Repository navigation
fix(esp32): make MCPWM_TIMER_TAG a compile-time constant (#3483) - #3758
Conversation
`static const char* MCPWM_TIMER_TAG` is a mutable pointer, so it occupies storage of its own in addition to the string literal it points at. As `static constexpr const char*` it emits nothing unless its address is taken. The tag is only ever read, as the first argument to ESP_LOGE/ESP_LOGI/ ESP_LOGW -- there is no assignment to it anywhere in the file, so nothing depended on the pointer being mutable. This was the last remaining item of #3483. The ~30 integer constants that issue was filed against (PRIORITY_* in channel_manager_esp32.cpp.hpp, kBassStart/kBassEnd in equalizer.cpp.hpp) no longer appear in the checker output at all -- see the issue comment for the full accounting, plus one open design question about constexpr scalars that blocks #3492. Validated: 357/357 host tests, lint green, and the checker no longer reports the tag. Co-Authored-By: Claude <[email protected]>
📝 WalkthroughWalkthroughThe MCPWM timer tag changes from a static const pointer to a static constexpr pointer, with comments updated to describe its compile-time constant behavior. ChangesMCPWM timer constant
Estimated code review effort: 1 (Trivial) | ~2 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Local Being precise about what that does and doesn't prove, since a green build of a file that isn't in the build proves nothing:
So: the guards say it compiles, and the build is green. CI's ESP32 job is the authoritative check for that leg, and I'm treating it as such rather than claiming more than I measured. The functional risk remains what the PR body says — a reassignment of the tag somewhere — and there is none; all 10 uses are read-only |
Closes out the last remaining item of #3483.
The change
static const char* MCPWM_TIMER_TAGis a mutable pointer — it occupies storage of its own in addition to the string literal it points at. Asstatic constexpr const char*it emits nothing unless its address is taken.Verified safe: the tag is only ever read, as the first argument to
ESP_LOGE/ESP_LOGI/ESP_LOGW. There is no assignment to it anywhere in the file, so nothing depended on the pointer being mutable.Most of #3483 was already done
The issue was filed against ~30 integer constants. None of its cited examples still appear in
fastled-lint --checker singleton_elisionon master:channel_manager_esp32.cpp.hpp(PRIORITY_FORCEetc.)equalizer.cpp.hpp(kBassStart,kBassEnd)The original count came from
ci/scan_singleton_elision.py, which still reports 101 where the Rust checker reports 34. That gap is mostly #3754's real literal tokenizer removing false positives — so 34 is the truer number, and the constant-splitting work has largely already happened. Full accounting is in the issue comment.One thing I deliberately did NOT do
objectfled_spi_mode.cpp.hpp:100is still flagged:It is already
static constexpr— already what a "split constants out" fix would produce. It's flagged only because the triviality test accepts a literal RHS but not one computed from other constants.This blocks #3492 (promote to hard-fail at zero): the finding can't be driven to zero, because "wrap in
fl::Singleton<T>" is not meaningful advice for a compile-time scalar.I prototyped skipping
constexprscalars while keepingconstexprtables flagged (an array is far more likely to be ODR-used through a pointer, and then really does occupy flash) — then reverted it.singleton_elision_still_flags_non_literal_constexprinlint_core/tests.rsdeliberately pins the current behaviour for exactly those RHS forms, added under #3486. That's a documented decision, so I raised it on the issue rather than flipping it unilaterally.Validation
bash lintgreenMCPWM_TIMER_TAGexercise it. A local
esp32devcompile was still running when this was opened, soI am relying on CI's ESP32 job for that leg rather than claiming a green build I
have not seen. The change is a
const char*->constexpr const char*on a symbolthat is only ever read, so the risk surface is a reassignment somewhere -- and I
grepped: there is none.
🤖 Generated with Claude Code