Skip to content

lint: promote SingletonElisionChecker to hard-fail (Tier 3, ratchet) #3492

Closed as not planned

Description

@zackees

Part of #3481 (Tier 3, ratchet closure).

Task

Once Tier 1 (#3484 #3485 #3486 #3487 #3488) and Tier 2 (#3489 #3490 #3491) are all merged and the SingletonElisionChecker warn output is empty (modulo the allowlist for cached-pointer intentional statics), promote the checker from warn-only to hard-fail in CI.

Concrete steps

  1. Confirm bash lint reports zero SingletonElisionChecker warnings on master.
  2. Confirm the allowlist in ci/lint_cpp_rs/src/checkers/singleton_elision.rs covers only the intentional cached-pointer variables (typically s_XXX_state for each Tier 2 driver) — each with an inline comment justifying why it can't be inside a Singleton.
  3. Change the checker's severity in processor_registry_cli.rs from warn to error.
  4. Update agents/docs/cpp-standards.md to document the rule: "namespace-scope variables MUST be wrapped in fl::Singleton<T> unless annotated with [[gnu::used]] / FL_KEEP or on the allowlist".
  5. Update .coderabbit.yaml if there's a mirror rule that should also promote.

Acceptance criteria

  • bash lint fails a PR that introduces a new namespace-scope non-allowlisted variable.
  • Existing violations are all fixed (no allowlist bypass for laziness).
  • Documentation updated so authors know the rule.

When to close

Do not close this issue until all Tier 1 + Tier 2 sub-issues are ✅.

Activity

  1. added
    type: feature
    priority: low
    area: ci
    on Jul 1, 2026
  2. zackees commented on Jul 28, 2026

    @zackees
    MemberAuthor

    Recommend re-scoping this rather than promoting as written. Following the finding in #3754 / #3486, I audited all 39 violations the checker currently reports.

    39 of 39 are constant-initialized PODs. Zero are dynamic-init objects.

    Every flagged declaration is T* x = nullptr, bool x = false, int x = <literal>, const char* x = "lit", or a zero-init aggregate with constant NSDMIs — all static or anonymous-namespace, i.e. already dropped by the compiler when unreferenced, before --gc-sections even runs. Promoting to hard-fail today would force 39 migrations that each cost flash and RAM and lose race-free constant-initialization, and zero that gain anything.

    The signal is currently inverted

    Verified in src/fl/stl/asio/http/server.cpp.hpp:

    static httpd_handle_t s_esp_httpd = nullptr;                              // 947 -- FLAGGED
    static fl::vector<fl::unique_ptr<EspRouteContext>> s_esp_route_contexts;  // 948 -- NOT flagged

    Line 947 is a POD pointer that -fdata-sections already handles. Line 948 has a non-trivial constructor, so it does register an .init_array entry that pulls the ctor in and resists --gc-sections — the one genuine migration candidate in the whole flagged set — and the checker walks straight past it. Brace-initialized aggregates are skipped the same way (flexio_driver.cpp.hpp:144, lpuart_driver.cpp.hpp:183).

    Two concrete defects

    1. False positive on computed constexpr. objectfled_spi_mode.cpp.hpp:100: static constexpr u32 kSpiMaxOutputWords = kSpiMaxInputBytes * kSpiWordsPerByte; is flagged only because is_trivial_rhs matches bare literals, so the constexpr skip misses it. Any kFoo = kBar + 1 hits this.
    2. False negative on non-constant initializers, as above.

    Suggested re-scope

    Invert the detection: flag declarations whose initializer is not a constant expression (class types with non-trivial ctors, non-constexpr initializers), and explicitly exempt scalar/pointer/POD-aggregate constant-init and FL_PROGMEM. Then re-measure.

    • If the resulting warn set is empty → this closes as "ratchet not needed."
    • If it surfaces real .init_array contributors like s_esp_route_contexts → those become the actual Tier 1/2 work, and the sibling issues get re-filed against that list.

    Note the FL_PROGMEM guidance in the checker's own message ("put the value inside a class as a member") is actively harmful for flash tables: a Singleton<T> member lives in .bss populated by placement-new, so on AVR that trades free flash for scarce SRAM.

    I have not changed checker policy — that call is yours. Audit detail in the sibling issues.

  3. zackees commented on Aug 20, 2026

    @zackees
    MemberAuthor

    Closing as not planned because promoting the current checker would enforce the inverse of the intended optimization rule.

    The preserved audit found:

    • all 39 then-reported declarations were constant-initialized scalar/pointer/POD state already compatible with per-data-section linker GC;
    • the checker missed the non-trivial fl::vector<fl::unique_ptr<...>> object that actually registered dynamic initialization;
    • it also false-positive'd computed constexpr expressions;
    • moving the reported ISR-touched POD state behind Singleton<T> would add pointers/branches and replace race-free constant initialization with lazy manual initialization.

    The Tier 1/2 review is now terminal: the beneficial targeted migrations/constexpr fixes landed, while #3485, #3490, and #3491 were closed as net-negative migrations. Therefore the prerequisite “existing violations are all fixed” is intentionally not going to occur under the current rule semantics.

    SingletonElisionChecker should remain warn-only until it can distinguish dynamic initialization and retained .init_array contributors from constant-initialized POD/flash data. That redesign is a separate structural-lint project, not this ratchet flip. Making the existing rule hard-fail would institutionalize known false positives and unsafe fixes.

  4. moved this from Triage to Done in FastLED Trackeron Aug 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: cipriority: lowtype: feature

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions