Repository navigation
Description
Context
Keep the existing stub AST lint and add real ESP analysis profiles, with shared parsing, correct incremental caching, and explicit coverage reporting. The goal is to check platform implementations efficiently rather than treating a successful host parse as coverage of every platform branch.
FastLED #4826 exposed the gap: eight Arduino SD/SdFat overrides lacked the FL_NO_EXCEPT contract required by their base class. The focused fix is merged in #4828. The broader coverage gap remains:
ci/tools/check_noexcept.py::_compiler_args()selectsSTUB_PLATFORM,FASTLED_STUB_IMPL, andFASTLED_TESTING. Conditional ESP implementations disappear before AST matching.- An ordinary fbuild compile can also exclude the affected code. Probing cached ESP32 configurations showed
SD.habsent, lowercasefs.habsent, and uppercase SDKFS.hpresent. Adding SD alone still leaves the lowercase-header guard false on Linux. With the backend enabled, fbuild rejects the original code with the reported errors. - Including a file is insufficient evidence that its conditional declarations were parsed. Optional backends need explicit presence assertions.
Feasibility experiments
Local clang-query 21.1.8 experiments at 6bd941a6523ac6ef09eb8c94f068203ff836d508, using the existing src/fl/build/platforms+.cpp router and real SDK/toolchain headers:
| Profile | Distinct platform declaration locations | Files containing those locations | Additional locations beyond stub |
|---|---|---|---|
| Current stub | 3,336 | 218 | — |
| ESP32 / Arduino 2.0.3 | 2,330 | 196 | 692 |
| ESP32 / Arduino 3.3.11 | 2,851 | 227 | 1,121 |
The query selected non-implicit function declarations under src/platforms/, normalized paths, and deduplicated source locations. These are configuration-specific declaration inventories, not runtime coverage percentages or a complete inventory of all separately compiled ESP units. Both ESP parses passed the existing compiler-error rejection check; vendor-header warnings remained. Separate real-SDK SD probes exposed 16 method/constructor/destructor declarations where the stub profile exposed no SDFileHandle.
Required adaptation included removing incompatible GCC options, providing target C/C++ include directories, normalizing escaped definitions, and preventing host headers from entering the target parse. A raw Tree-sitter experiment found all eight offending methods across both conditional branches without an SDK, but other macros produced parse errors; it is suitable for coverage discovery, not a substitute for semantic validation.
Proposal
1. Explicit stub and ESP profiles
- Preserve the current stub pass and its checks.
- Add pinned ESP32 IDF 4 and IDF 5 profiles, plus a representative ESP RISC-V profile selected for additional source coverage.
- Record compiler identity, SDK identity, target, include paths, macros, generated configuration, and optional features for each profile.
- Include explicit SD and SdFat configurations. Add other feature configurations where the inventory proves a gap, such as alternate driver generations.
- Provision SDKs separately and reuse them. Warm lint must not download toolchains or build firmware. Missing prerequisites must produce an actionable failure, not silently skip required ESP coverage.
2. Reuse real compilation settings and source units
- Derive ESP environments from fbuild's actual compilation databases, with a tested adapter for Clang-compatible arguments.
- Preserve target semantics and SDK headers; reject accidental host standard-library leakage.
- Enumerate actual owned compilation units, including split ESP driver routers. The single platform router used in the experiment is not the complete analysis scope.
- Add small generated translation units for optional implementations absent from ordinary build inputs. Use real SDK declarations and require expected backend types to exist.
- Run supported configurations separately rather than enabling incompatible chip macros in one giant translation unit.
3. One parse per unit/configuration
- Extend
ci/tools/check_ast_combined.pyso noexcept, array-parameter checks, and coverage collection share each AST parse. - Deduplicate equivalent analysis jobs and findings while retaining profile attribution.
- Bound worker concurrency and memory use across the entire matrix.
- Keep compiler diagnostics fatal even when clang-query exits zero or emits partial matches; retain the existing fail-closed behavior.
4. Coverage as an observable contract
- Record parsed declaration source locations per profile and the union across profiles.
- Declare expected implementations for each profile, including SD and SdFat; fail when they disappear behind feature/header guards.
- Report successful semantic coverage, missing expectations, parse failures, and known uncovered regions separately.
- Do not equate file inclusion, zero matches, or a successful process exit with coverage.
- Consider raw-source inventory and Clang preprocessor callbacks for skipped ranges and
__has_includedecisions as a later enhancement, to guide additional profiles.
5. Correct incremental caching
- Cache completed analysis using source/transitive headers, compiler and matcher versions, full profile arguments, SDK identity/content, and generated configuration inputs.
- Account for negative include lookups and changed header availability: adding a previously absent optional header must invalidate affected analysis. Hashing only previously included files is insufficient.
- Local edits rerun affected units; CI evaluates the complete required profile matrix while reusing valid results.
- Never reuse an incomplete or failed parse as a successful check. Cached violations must remain violations.
- Coordinate with chore(lint): migrate ci/lint_cpp orchestrator (drop bespoke ast_cache, evaluate Rust port) after zccache#838 lands #3338 rather than introducing a competing cache/orchestrator rewrite.
6. Measured rollout
Deliver in three reviewable stages:
- Profile support and real ESP parsing, with reproducible coverage inventory.
- Presence assertions, focused regressions, and fixes for genuine existing violations.
- Correct caching, bounded scheduling, measured performance, and required stub-plus-ESP enforcement in existing lint/CI entry points.
Measure cold runs, unchanged warm runs, single-source edits, and common-header edits on the same revision/machine. Record elapsed time, peak memory, parse count, cache hit rate, and unique declarations covered. Establish a concrete budget from those measurements before enabling the required matrix. Remove a redundant configuration only with evidence that required coverage is retained.
Acceptance criteria
- Both stub and ESP semantic passes run through the normal C++ lint entry point and existing CI integration; missing required ESP tooling cannot silently pass.
- IDF 4, IDF 5, a documented representative RISC-V target, SD, and SdFat configurations are covered with real SDK settings and reproducible provisioning.
- Source-unit enumeration covers separate ESP implementation units, not only
platforms+.cpp; the report identifies the exact units and profile versions checked. - RED -> GREEN evidence: focused tests first demonstrate the existing blind spot, then the implementation detects the original eight SD annotation omissions and a violation in an ESP-only implementation.
- Tests prove that an absent expected backend, an unavailable required SDK, and a compiler error accompanied by exit status zero all fail the check.
- Tests prove invalidation after source/header, compiler/matcher/profile, SDK/configuration, and previously absent-header availability changes, including warmed-cache cases.
- Each analysis unit/profile parses once for the combined checks; scheduling is globally bounded and duplicate diagnostics preserve useful profile attribution.
- A machine-readable coverage report and concise human summary distinguish semantic coverage from missing/unparsed/excluded code. No runtime coverage percentage is inferred from declaration counts.
- Cold/warm/edit performance and peak memory are measured and published with an explicit budget; an unchanged warm run launches no clang-query parses and performs no downloads or firmware builds.
- Genuine existing ESP findings are fixed before required enforcement; no generated baseline silently grandfathers missing annotations.
- Existing stub behavior and regression tests remain valid; repository lint, relevant tests, and code review pass.
- Documentation explains setup, profile selection, cache invalidation, diagnostics, coverage limits, and how to add a supported platform/feature profile.
Decisions
- Extend the existing clang-query orchestration first: real ESP parsing has been demonstrated, so a new AST engine is not a prerequisite.
- Preserve stub coverage: ESP profiles expose additional declarations but do not subsume host/shared configurations.
- Choose the RISC-V target and any extra feature profiles using measured additional coverage and SDK compatibility, not an exhaustive board matrix.
- Reuse existing workflows; do not add new GitHub Actions workflow files for this work.
- Keep Tree-sitter/Cppcheck inventories and a GCC-plugin checker as optional follow-ups. They must not replace the required semantic gate.
- Audit SDK header-name/feature guards exposed by this work; ensure any corrections have focused platform regressions and do not quietly remove supported backends.
- Distinguish this from lint: full libclang-based Rust AST subsystem for structural lints (deferred) #3493: migrating structural rules into a Rust/libclang subsystem is separate from expanding supported preprocessing environments.
Related issues
- 3.10.7 does not compile my simple sketch in Platformio #4826 and merged fix: restore ESP32 SD file noexcept compatibility #4828: motivating SD exception-specification regression and focused fix.
- ci: enforce FL_NOEXCEPT on every owned function in src #2984: existing intent to enforce annotations throughout owned sources; conditional platform coverage remains incomplete.
- chore(lint): migrate ci/lint_cpp orchestrator (drop bespoke ast_cache, evaluate Rust port) after zccache#838 lands #3338: AST cache/orchestration performance work to coordinate with.
- lint: full libclang-based Rust AST subsystem for structural lints (deferred) #3493: separate deferred Rust/libclang structural-lint architecture.
References
- Clang compilation databases
- Espressif Clang analysis support
- Clang preprocessor callbacks, including skipped ranges and header-availability probes.
Implementation and final validation
Implemented in #4831 at 651868a4670142911cdb174ff479753dfd5e81c4: all 121 checks across 98 workflows passed with ci-full. This issue remains open until the implementation PR merges. The published dependency FastLED/fbuild#1678 is merged and FastLED/fbuild#1677 is closed after downstream acceptance.
- Normal lint enforces 138 stub/ESP jobs; final Linux warm run used 138 verified cache hits with no parses or failures in 10.76s.
- Final Intel Mac validation: 138 jobs, 33 hits, 21,894 declarations, zero failures, 571.92s analysis, 1,546 MiB sampled peak RSS. Native Windows, Linux and both Mac unit/example suites passed.
- Final local Python sweep: 1,967 tests and 3,263 subtests passed (48 skipped, two xfailed). Native debug: 320 units and 96 examples passed.
- Real published-wheel builds and unchanged Pico, Teensy and ESP32-S3 size budgets passed. All final board workflows passed.
- Metro M4 and tinystm initially failed npm downloads with ETIMEDOUT/ECONNRESET; unchanged-head reruns passed. No checks were disabled.
- The QEMU smoke now uses the existing GPIO software driver supported by the emulator and rejects ChannelManager timeouts; it does not claim RMT or electrical waveform validation.
Coverage remains a semantic declaration inventory, not runtime coverage. Performance, cache audits, profile identities, setup and limits are documented in the PR and docs/AST_LINT_PROFILES.md.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsTriage
Activity