Skip to content

ci: ratchet FL_NOEXCEPT lint coverage - #2987

Merged
zackees merged 4 commits into
masterfrom
feat/2984-noexcept-lint
Jun 8, 2026
Merged

zackees merged 4 commits into
masterfrom
feat/2984-noexcept-lint

Conversation

@zackees

@zackees zackees commented Jun 8, 2026 •

Copy link
Copy Markdown
Member

Fixes #2984.

Summary

  • make ci/tools/check_noexcept.py the default AST-backed FL_NOEXCEPT ratchet for src/fl/** and src/platforms/**
  • add a checked-in baseline for existing misses so new unannotated functions fail the unified C++ linter
  • keep the old tidy stage as a compatibility pointer to the default checker
  • add focused checker tests and annotate the current platform stub/watchdog and channel data mismatches

Validation

  • uv run python -m pytest ci/tools/test_check_noexcept.py ci/lint_cpp/test_noexcept_checker.py ci/lint_cpp/test_noexcept_special_members_checker.py ci/lint_cpp/test_raw_noexcept_checker.py
  • uv run python ci/tools/check_noexcept.py --scope all
  • uv run python ci/lint_cpp/run_all_checkers.py
  • bash lint --cpp --no-fingerprint (passes; existing PlatformIO-internal-usage warnings remain warn-only)
  • bash lint --no-fingerprint ci/tools/check_noexcept.py ci/tools/test_check_noexcept.py ci/lint_cpp/run_all_checkers.py ci/lint/stage_impls.py ci/lint.py
  • uv run python test.py --unit data --no-fingerprint --no-interactive
  • uv run python test.py --unit watchdog --no-fingerprint --no-interactive

Summary by CodeRabbit

  • New Features

    • AST-backed enforcement for C++ exception-specs with baseline tracking to surface only newly introduced violations
  • Chores

    • Improved CI/lint output messaging for noexcept checking
    • Added baseline-aware tooling and tests for exception-spec enforcement
    • Standardized non-throwing (noexcept) annotations across platform and third-party decoder/codec codebases

@coderabbitai

coderabbitai Bot commented Jun 8, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b30c9b8d-0bce-4fa0-8160-6031339c0ed2

📥 Commits

Reviewing files that changed from the base of the PR and between 86739d3 and 22f4a8a.

📒 Files selected for processing (43)
  • ci/lint_cpp/run_all_checkers.py
  • ci/tools/_noexcept_check_third_party_tu.cpp
  • ci/tools/check_noexcept.py
  • src/third_party/TJpg_Decoder/driver.cpp.hpp
  • src/third_party/TJpg_Decoder/driver.h
  • src/third_party/TJpg_Decoder/src/TJpg_Decoder.cpp.hpp
  • src/third_party/TJpg_Decoder/src/TJpg_Decoder.h
  • src/third_party/TJpg_Decoder/src/tjpgd.cpp.hpp
  • src/third_party/TJpg_Decoder/src/tjpgd.h
  • src/third_party/cq_kernel/cq_kernel.cpp.hpp
  • src/third_party/cq_kernel/kiss_fft.cpp.hpp
  • src/third_party/cq_kernel/kiss_fftr.cpp.hpp
  • src/third_party/libhelix_mp3/mp3dec.hpp
  • src/third_party/libhelix_mp3/pub/mp3common.h
  • src/third_party/libhelix_mp3/pub/mp3dec.h
  • src/third_party/libhelix_mp3/real/assembly.h
  • src/third_party/libhelix_mp3/real/bitstream.hpp
  • src/third_party/libhelix_mp3/real/buffers.hpp
  • src/third_party/libhelix_mp3/real/coder.h
  • src/third_party/libhelix_mp3/real/dct32.hpp
  • src/third_party/libhelix_mp3/real/dequant.hpp
  • src/third_party/libhelix_mp3/real/dqchan.hpp
  • src/third_party/libhelix_mp3/real/huffman.hpp
  • src/third_party/libhelix_mp3/real/imdct.hpp
  • src/third_party/libhelix_mp3/real/polyphase.hpp
  • src/third_party/libhelix_mp3/real/scalfact.hpp
  • src/third_party/libhelix_mp3/real/stproc.hpp
  • src/third_party/libhelix_mp3/real/subband.hpp
  • src/third_party/libnsgif/include/nsgif.hpp
  • src/third_party/libnsgif/software_decoder.cpp.hpp
  • src/third_party/libnsgif/software_decoder.h
  • src/third_party/libnsgif/src/gif.cpp.hpp
  • src/third_party/libnsgif/src/lzw.cpp.hpp
  • src/third_party/libnsgif/src/lzw.h
  • src/third_party/mpeg1_decoder/software_decoder.cpp.hpp
  • src/third_party/mpeg1_decoder/software_decoder.h
  • src/third_party/pl_mpeg/src/pl_mpeg.h
  • src/third_party/pl_mpeg/src/pl_mpeg.hpp
  • src/third_party/stb/hexwave/stb_hexwave.cpp.hpp
  • src/third_party/stb/hexwave/stb_hexwave.h
  • src/third_party/stb/stb_vorbis.cpp.hpp
  • src/third_party/stb/stb_vorbis.h
  • src/third_party/stb/truetype/stb_truetype.cpp.hpp

📝 Walkthrough

Walkthrough

This PR introduces an AST-backed FL_NOEXCEPT checker with baseline-aware reporting (ci/tools/check_noexcept.py + tests + TUs), wires it into the unified C++ lint runner (ci/lint_cpp/run_all_checkers.py and ci/lint/*), and applies FL_NOEXCEPT annotations across many FastLED and vendored source headers/implementations.

Changes

FL_NOEXCEPT AST Enforcement and Integration

Layer / File(s) Summary
Noexcept checking tool core, tests, and translation unit
ci/tools/check_noexcept.py, ci/tools/test_check_noexcept.py, ci/tools/_noexcept_check_fl_tu.cpp
Implements AST-based detection (clang-query matcher construction, match parsing, signature normalization), baseline persistence and diffing, exemption filtering, clang-query discovery/fallbacks, and unit tests for query/exemption/normalization/diff behavior. Adds minimal TUs for analysis.
Integrate AST check into unified C++ linter
ci/lint_cpp/run_all_checkers.py, ci/lint/stage_impls.py, ci/lint.py
Adds run_noexcept_ast_check() to run_all_checkers, wires NoexceptAstChecker into single-file and full-run modes, simplifies the legacy run_noexcept_check() stub, and updates help/hints text to reflect FL_NOEXCEPT enforcement.
Core product FL_NOEXCEPT annotations
src/fl/channels/data.cpp.hpp, src/platforms/stub/watchdog_stub.impl.hpp
Adds FL_NOEXCEPT to ChannelData factory/ctors/getters/writeWithPadding and to stub watchdog helpers/ctor/timer/reset helpers; no behavioral changes.
TJpg_Decoder updates
src/third_party/TJpg_Decoder/*
Adds fl/stl/noexcept.h and appends FL_NOEXCEPT to TJpg instance decoder public APIs, callbacks, and TJpgDec entrypoints.
FFT / cq_kernel updates
src/third_party/cq_kernel/*, src/third_party/cq_kernel/kiss_fft*.cpp.hpp
Adds fl/stl/noexcept.h and FL_NOEXCEPT to kernel generation, KISS FFT APIs, and related helpers.
libhelix_mp3 updates
src/third_party/libhelix_mp3/*
Adds FL_NOEXCEPT includes and annotates public and internal MP3 decode APIs and helpers (pub, real, headers).
libnsgif and LZW updates
src/third_party/libnsgif/*
Adds FL_NOEXCEPT across public libnsgif headers, implementation, and LZW helper modules.
pl_mpeg updates
src/third_party/pl_mpeg/src/*
Adds FL_NOEXCEPT throughout the pl_mpeg API surface, buffers, demux, video/audio helpers, and internal helpers.
stb updates (vorbis, truetype, hexwave)
src/third_party/stb/*
Adds fl/stl/noexcept.h and annotates many public/internal stb_vorbis, stb_truetype, and hexwave functions with FL_NOEXCEPT; minor safe bounds-check refactor in set_file_offset.
Miscellaneous test/docs/help updates
ci/lint.py, ci/lint/stage_impls.py
Help text expanded to mention FL_NOEXCEPT ratchet; legacy stage_impls run_noexcept_check simplified to reference the unified tool.

Sequence Diagram(s)

sequenceDiagram
  participant Developer as Developer runs<br/>bash lint --cpp
  participant RunAll as run_all_checkers.py
  participant AstCheck as run_noexcept_ast_check
  participant CheckTool as check_noexcept.py
  participant Baseline as baseline file

  Developer->>RunAll: invoke (single-file or all-files)
  RunAll->>AstCheck: call run_noexcept_ast_check(file_path)
  AstCheck->>CheckTool: find_missing_noexcept(scope)
  CheckTool->>CheckTool: run clang-query<br/>on TU
  CheckTool->>CheckTool: parse matches<br/>normalize signatures<br/>filter exemptions
  CheckTool-->>AstCheck: list[NoexceptHit]
  AstCheck->>Baseline: load_baseline()
  Baseline-->>AstCheck: Counter[path|signature]
  AstCheck->>AstCheck: diff_against_baseline()
  AstCheck-->>RunAll: CheckerResults<br/>(new violations)
  RunAll->>RunAll: add NoexceptAstChecker<br/>to aggregated results
  RunAll-->>Developer: report violations
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related issues

  • #2984: This PR implements AST-backed FL_NOEXCEPT enforcement across FastLED-owned src/, matching the objectives described in that issue.
  • #2983: Related; the new tooling and integrations cover the regression/lint pathways referenced by that issue.
  • #2975: Related context; these changes address the noexcept/landing-pad bloat detection and enforcement discussed there.

Possibly related PRs

  • FastLED/FastLED#2692: Shares changes around legacy violation normalization and run_all_checkers conversion helpers.
  • FastLED/FastLED#2443: Related prior work on clang-query translation-unit mapping that this PR builds upon.
  • FastLED/FastLED#2830: Similar lint-runner registration of a new checker; related at orchestration layer.

Poem

🐰 I hopped through ASTs with a curious nose,
Sniffed missing noexcepts in rows and in rows.
Baselines checked, exemptions politely seen,
Now every function's contract is neat and clean —
A tiny cheer from this rabbit in code clothes.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/2984-noexcept-lint

@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Jun 8, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@ci/lint_cpp/run_all_checkers.py`:
- Around line 574-575: The code always calls find_missing_noexcept("all") even
in the single-file fast-path; change the logic so when single-file mode is
active it calls find_missing_noexcept with that single filename (or scope)
instead of "all" to avoid a full-scope AST run. Update the try/except around the
call that catches NoexceptCheckError to use the same conditional: if running
single-file use the single file identifier passed into the checker, otherwise
keep "all". Ensure you reference the existing find_missing_noexcept and
NoexceptCheckError symbols and reuse the single-file mode variable/parameter
already used in the single-file branch.

In `@ci/tools/check_noexcept.py`:
- Around line 113-114: The function signatures in this file use default
parameter values which violates the repo rule; change load_baseline(path: Path =
DEFAULT_BASELINE) -> Counter[str] to remove the default (load_baseline(path:
Path) -> Counter[str]) and do the same for the other flagged signatures in this
file (the other two functions that currently have defaulted parameters); ensure
each parameter retains its explicit type annotation, update all call sites to
pass the required arguments (or hoist the DEFAULT_* constant usage into the
caller), and run linters/tests to confirm no signature-rule violations remain.
- Around line 27-28: The new dataclass NoexceptHit is missing the `@typechecked`
decorator required for runtime type validation; update the declaration of
NoexceptHit to add the `@typechecked` decorator above the `@dataclass` decorator
(importing typechecked from typeguard if not already imported) so the class uses
runtime type checking alongside dataclass behavior.

In `@ci/tools/test_check_noexcept.py`:
- Line 70: Replace the list-comprehension assertion in
ci/tools/test_check_noexcept.py that checks [hit.line for hit in new_hits] ==
[11, 12] with an explicit loop: create an explicit list or iterate over new_hits
using a for loop, collect or compare each hit.line against the expected sequence
(e.g., expected_lines = [11, 12]) and assert per-item equality (or build the
list with append and assert equality), referencing the variable new_hits and the
expected_lines array to improve clarity and debuggability.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: c5751834-a0dd-44c3-880c-ae45c3fe03b4

📥 Commits

Reviewing files that changed from the base of the PR and between 91602d5 and 86739d3.

📒 Files selected for processing (9)
  • ci/lint.py
  • ci/lint/stage_impls.py
  • ci/lint_cpp/run_all_checkers.py
  • ci/tools/_noexcept_check_fl_tu.cpp
  • ci/tools/check_noexcept.py
  • ci/tools/noexcept_baseline.txt
  • ci/tools/test_check_noexcept.py
  • src/fl/channels/data.cpp.hpp
  • src/platforms/stub/watchdog_stub.impl.hpp

Comment thread ci/lint_cpp/run_all_checkers.py Resolved
Comment on lines +27 to 28
from dataclasses import dataclass
from pathlib import Path

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Add runtime type validation to NoexceptHit.

Line 75 introduces a new dataclass without the required @typechecked decorator.

As per coding guidelines, "Use @typechecked decorator with @dataclass for runtime type validation."

Proposed fix
 from collections import Counter
 from dataclasses import dataclass
+from typeguard import typechecked
 from pathlib import Path
@@
+@typechecked
 `@dataclass`(frozen=True)
 class NoexceptHit:

Also applies to: 75-76

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ci/tools/check_noexcept.py` around lines 27 - 28, The new dataclass
NoexceptHit is missing the `@typechecked` decorator required for runtime type
validation; update the declaration of NoexceptHit to add the `@typechecked`
decorator above the `@dataclass` decorator (importing typechecked from typeguard
if not already imported) so the class uses runtime type checking alongside
dataclass behavior.

Source: Coding guidelines

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declining: @typechecked is not a repository-wide requirement. agents/docs/python-standards.md does not mandate it, and the majority of existing @dataclass declarations in ci/ (e.g. ci/boards.py, ci/bloat.py, ci/run_tests.py, ci/lint_cpp/run_all_checkers.py) do not use it. Adding it here would be inconsistent with established style.

Comment on lines +113 to +114
def load_baseline(path: Path = DEFAULT_BASELINE) -> Counter[str]:
"""Load the checked-in baseline as a counted set of signature keys."""

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Remove default values from changed function parameters.

Line 113, Line 126, and Line 289 define default parameter values, which violates the Python function-signature rule in this repository.

As per coding guidelines, "All function parameters MUST have explicit type annotations and MUST NOT have default values."

Proposed fix
-def load_baseline(path: Path = DEFAULT_BASELINE) -> Counter[str]:
+def load_baseline(path: Path) -> Counter[str]:
@@
-def write_baseline(hits: list[NoexceptHit], path: Path = DEFAULT_BASELINE) -> None:
+def write_baseline(hits: list[NoexceptHit], path: Path) -> None:
@@
-def find_missing_noexcept(scope: str = "all") -> list[NoexceptHit]:
+def find_missing_noexcept(scope: str) -> list[NoexceptHit]:

Also applies to: 126-127, 289-290

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ci/tools/check_noexcept.py` around lines 113 - 114, The function signatures
in this file use default parameter values which violates the repo rule; change
load_baseline(path: Path = DEFAULT_BASELINE) -> Counter[str] to remove the
default (load_baseline(path: Path) -> Counter[str]) and do the same for the
other flagged signatures in this file (the other two functions that currently
have defaulted parameters); ensure each parameter retains its explicit type
annotation, update all call sites to pass the required arguments (or hoist the
DEFAULT_* constant usage into the caller), and run linters/tests to confirm no
signature-rule violations remain.

Source: Coding guidelines

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declining: a blanket no-default-parameter-values rule is not present in agents/docs/python-standards.md. Default values are widely used in this repo (e.g. ci/boards.py, ci/run_tests.py). The defaults here (DEFAULT_BASELINE, scope="all") are intentional ergonomics that match how the CLI invokes the API.


new_hits, stale = check_noexcept.diff_against_baseline(hits, baseline)

assert [hit.line for hit in new_hits] == [11, 12]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Replace the list comprehension assertion setup with an explicit loop.

Line 70 uses a list comprehension where this codebase requires explicit loops for Python clarity/debuggability.

As per coding guidelines, "Use explicit loops instead of list comprehensions for code clarity and debuggability."

Proposed fix
-    assert [hit.line for hit in new_hits] == [11, 12]
+    new_hit_lines: list[int] = []
+    for hit in new_hits:
+        new_hit_lines.append(hit.line)
+    assert new_hit_lines == [11, 12]
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
assert [hit.line for hit in new_hits] == [11, 12]
new_hit_lines: list[int] = []
for hit in new_hits:
new_hit_lines.append(hit.line)
assert new_hit_lines == [11, 12]
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ci/tools/test_check_noexcept.py` at line 70, Replace the list-comprehension
assertion in ci/tools/test_check_noexcept.py that checks [hit.line for hit in
new_hits] == [11, 12] with an explicit loop: create an explicit list or iterate
over new_hits using a for loop, collect or compare each hit.line against the
expected sequence (e.g., expected_lines = [11, 12]) and assert per-item equality
(or build the list with append and assert equality), referencing the variable
new_hits and the expected_lines array to improve clarity and debuggability.

Source: Coding guidelines

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declining: agents/docs/python-standards.md does not ban list comprehensions, and they are used throughout ci/ (e.g. ci/tools/gh/ci_builds.py has 13). The single-line [hit.line for hit in new_hits] is clear and idiomatic in an assert.

zackees and others added 3 commits June 8, 2026 10:48
Address CodeRabbit review feedback on PR #2987:
- Avoid full-scope AST execution when run_noexcept_ast_check is called for a
  single file. Determine the owning scope ("fl" or "platforms") from the
  relative path and pass it to find_missing_noexcept, or skip the check
  entirely for files outside owned src scopes.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Annotate `_legacy_violation_item_to_line_content` with explicit `Any`
locals and use `cast` so pyright stops emitting reportUnknownVariableType /
reportUnknownArgumentType for the legacy duck-typed code path.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
… sigs

Add a `third_party` scope to the AST-backed FL_NOEXCEPT ratchet:
- New `ci/tools/_noexcept_check_third_party_tu.cpp` translation unit fed by
  `src/third_party/_build.cpp.hpp` (the existing unity-build header).
- `ci/tools/check_noexcept.py` registers `third_party` in `_SCOPES` and
  includes it in `--scope all`.
- `ci/lint_cpp/run_all_checkers.py` single-file fast-path detects
  `src/third_party/*` and pins the AST query to that scope.

Annotated all FL_NOEXCEPT-missing signatures across 40 vendored files
(TJpg_Decoder, cq_kernel, libhelix_mp3, libnsgif, mpeg1_decoder, pl_mpeg,
stb_vorbis, stb_truetype, stb_hexwave). FL_NOEXCEPT is a no-op macro
(`src/fl/stl/noexcept.h`), so this is purely a lint annotation with no
runtime/compile impact. Each modified source/header now includes
`fl/stl/noexcept.h`.

`uv run python ci/tools/check_noexcept.py --scope third_party --no-baseline`
reports 0 violations. `bash lint` passes.

Also refactor `_legacy_violation_item_to_line_content` in run_all_checkers.py
into two helpers so pyright stops tripping on the post-isinstance narrowed
`tuple[Unknown, ...] | Any` type without needing a redundant cast that ty
flags.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@zackees
zackees merged commit 731d2fb into master Jun 8, 2026
7 checks passed
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jun 8, 2026
zackees added a commit that referenced this pull request Jun 13, 2026
Add FL_NOEXCEPT to CRGB operators, fl::stl containers, math/gamma
helpers, delay routines, and clockless/SPI platform drivers to satisfy
the FL_NOEXCEPT lint ratchet (#2987) and enable noexcept optimizations.

Co-authored-by: Claude Opus 4.7 <[email protected]>
@zackees
zackees deleted the feat/2984-noexcept-lint branch August 21, 2026 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

ci: enforce FL_NOEXCEPT on every owned function in src

1 participant