Repository navigation
Open
Labels
area: ciGitHub Actions, fbuild, toolchainsdeferredTriage pass could not resolve this; skipped by ci/oldest_issue.pypriority: lowStyle, minor optimization — optionaltype: featureNew capability or enhancement
Description
Part of #3481 (Tier 3, deferred).
Task
The original directive for the Singleton lint asked for it to be built on the "clang query protocol" — libclang's AST cursor API, not regex. The current SingletonElisionChecker in ci/lint_cpp_rs/src/checkers/singleton_elision.rs uses regex + brace-depth tracking (same style as the other FileContentCheckers in the crate). This is pragmatic for one rule but doesn't scale.
Why AST-based
- Regex-based checkers cannot distinguish a namespace-scope
int gFoofrom a localint gFoowhen both fit on similar lines with unusual context. - Templates, macros, and multi-line declarations regularly fool the brace-depth heuristic.
- Clang's
hasGlobalStorage()matcher is the correct predicate for "this variable is at namespace scope and emits storage" — no ambiguity. - Rebuilding this once for the whole crate enables cheap addition of future structural rules (dependency-direction, layer-violation, cross-TU consistency).
Approach
- Add
clang-sys/clangcrate dep toci/lint_cpp_rs/Cargo.toml, gated behind alibclangfeature so systems without libclang installed can still run the regex checkers. - Introduce a new checker trait
AstCheckeralongsideFileContentChecker. - Parse each TU once (via a shared
TranslationUnitcache) and walk cursors, feeding each cursor to every registeredAstChecker. - Reimplement
SingletonElisionCheckeras anAstCheckerusingCursor::kind() == CXCursor_VarDecl && cursor.storage_class() == CX_SC_Static && cursor.linkage() != CX_Linkage_NoLinkage. - Keep the regex version as a fallback for environments without libclang.
Acceptance criteria
bash lintproduces identicalSingletonElisionCheckeroutput whether run with the regex or AST backend (mod false-positive fixes exposed by the more accurate AST predicate).- At least one additional AST checker migrated from the Python
ci/scripts to demonstrate the pattern (candidates:SingletonInHeadersChecker, or a new dependency-direction rule). - Documentation added to
agents/docs/linter-architecture.md.
Scope note
This is a substantial effort (2–3 weeks). Deliberately deferred until after Tier 1 and Tier 2 have proven the Singleton-elision rule is worth having. Do NOT block Tier 1 or Tier 2 on this.
Metadata
Metadata
Assignees
Labels
area: ciGitHub Actions, fbuild, toolchainsdeferredTriage pass could not resolve this; skipped by ci/oldest_issue.pypriority: lowStyle, minor optimization — optionaltype: featureNew capability or enhancement
Type
Projects
- StatusShow more project fieldsTriage
Activity
zackees commentedon Aug 20, 2026
Queue classification corrected: this issue is explicitly marked “Tier 3, deferred” in both its title and body, but it lacked the
deferredlabel and was therefore being counted as actionable.The deferral remains valid. This is a 2–3 week cross-platform libclang subsystem (feature-gated parser, shared TU cache, new checker trait, regex fallback, checker migration, parity validation, and documentation). In addition, #3492 established that the current Singleton rule first needs a corrected semantic target—dynamic initialization / retained
.init_arraycontributors—before AST parity is meaningful.Restart criteria:
deferredonly when an owner and CI dependency strategy are assigned.No implementation work will be performed while this label is present, per the burn-down policy.