You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
lint: split integer-constant globals into PreferConstexprChecker #3483
The scan (ci/scan_singleton_elision.py) reports ~30 hits that are NOT true Singleton candidates — they are integer / const-int compile-time constants that should be constexpr (compiler will inline, no storage emitted). Bucketing them under the Singleton warning conflates two very different fixes.
Examples
// src/platforms/esp/32/drivers/channel_manager_esp32.cpp.hppintPRIORITY_FORCE = 4; // should be `constexpr int`intPRIORITY_PARLIO = 3;
intPRIORITY_LCD_RGB = 2;
// ... 14 total in this file// src/fl/audio/detector/equalizer.cpp.hppconstintkBassStart = 20; // should be `constexpr int`constintkBassEnd = 250;
// ... 6 total in this file// src/platforms/arm/rp/rpcommon/spi_hw_manager_rp.cpp.hppintPRIORITY_SPI_HW_8 = 3;
Concrete steps
Create ci/lint_cpp_rs/src/checkers/prefer_constexpr.rs as a sibling to singleton_elision.rs.
Match namespace-scope int / const int / unsigned etc. definitions with a trivial integer literal RHS (int literal, hex, binary, single-token bit-shift like (1u << 5)).
Emit warning: "namespace-scope NAME is a compile-time integer constant; use constexpr so the compiler inlines it and no storage is emitted".
Move the trivial-literal-with-non-constexpr detection OUT of SingletonElisionChecker so the two rules don't overlap.
Register in processor_registry_cli.rs (warn-only).
The original count came from ci/scan_singleton_elision.py, which still reports 101. 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.
What was actually left: one item.MCPWM_TIMER_TAG in gpio_isr_rx/mcpwm_timer.cpp.hpp was static const char* — a mutable pointer occupying storage on top of the string literal. Fixed to static constexpr const char* in the linked PR.
One open design question, worth a maintainer decision
The remaining set contains a case this issue's framing doesn't cover, and it blocks #3492.
It is already static constexpr — already the thing a "split constants out" fix would produce. It is flagged only because the triviality test accepts a literal RHS but not one computed from other constants.
That matters for #3492 (promote to hard-fail when the count reaches zero): this finding cannot be driven to zero. The warning says "wrap in fl::Singleton<T>", which is not meaningful advice for a compile-time scalar — it emits no storage unless ODR-used, and if it is ODR-used the remedy is to stop taking its address, not to wrap it. The only way to clear it today is an FL_LINT_ALLOW_GLOBAL annotation on something that is already correct.
I prototyped skipping constexprscalars (keeping constexprtables flagged, since an array is far more likely to be ODR-used through a pointer and then really does occupy flash) — and reverted it, because singleton_elision_still_flags_non_literal_constexpr in lint_core/tests.rs deliberately pins the current behaviour for exactly these RHS forms (kMin * 2.0f, kOther + 1), added under #3486. That is a documented decision and not mine to flip unilaterally.
So, one of:
Skip constexpr scalars, keep constexpr tables — updates that test; makes the count reachable-to-zero.
Activity
singleton: sweep the safe <=2-hit files (Tier 1e)
singleton: sweep the safe <=2-hit files (Tier 1e) (#3756)
zackees commentedon Jul 29, 2026
This issue is now almost entirely resolved — the ~30 integer constants it was filed against are gone from the checker output.
Neither cited example still appears. Current
fastled-lint --checker singleton_elisionon master (34 findings) contains no hits in either file:channel_manager_esp32.cpp.hpp(cited: 14 hits,PRIORITY_FORCE/PRIORITY_PARLIO/PRIORITY_LCD_RGB) — 0equalizer.cpp.hpp(cited: 6 hits,kBassStart/kBassEnd) — 0The original count came from
ci/scan_singleton_elision.py, which still reports 101. 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.What was actually left: one item.
MCPWM_TIMER_TAGingpio_isr_rx/mcpwm_timer.cpp.hppwasstatic const char*— a mutable pointer occupying storage on top of the string literal. Fixed tostatic constexpr const char*in the linked PR.One open design question, worth a maintainer decision
The remaining set contains a case this issue's framing doesn't cover, and it blocks #3492.
objectfled_spi_mode.cpp.hpp:100is flagged:It is already
static constexpr— already the thing a "split constants out" fix would produce. It is flagged only because the triviality test accepts a literal RHS but not one computed from other constants.That matters for #3492 (promote to hard-fail when the count reaches zero): this finding cannot be driven to zero. The warning says "wrap in
fl::Singleton<T>", which is not meaningful advice for a compile-time scalar — it emits no storage unless ODR-used, and if it is ODR-used the remedy is to stop taking its address, not to wrap it. The only way to clear it today is anFL_LINT_ALLOW_GLOBALannotation on something that is already correct.I prototyped skipping
constexprscalars (keepingconstexprtables flagged, since an array is far more likely to be ODR-used through a pointer and then really does occupy flash) — and reverted it, becausesingleton_elision_still_flags_non_literal_constexprinlint_core/tests.rsdeliberately pins the current behaviour for exactly these RHS forms (kMin * 2.0f,kOther + 1), added under #3486. That is a documented decision and not mine to flip unilaterally.So, one of:
Option 1 is what I'd suggest, but it changes a tested contract, so flagging rather than doing.
fix(esp32): make MCPWM_TIMER_TAG a compile-time constant (#3483) (#3758)
feat(lint): split integer constants out of SingletonElisionChecker in…