Skip to content

fix(esp32): make MCPWM_TIMER_TAG a compile-time constant (#3483) - #3758

Merged
zackees merged 1 commit into
masterfrom
fix/3483-constexpr-scalars
Jul 29, 2026
Merged

zackees merged 1 commit into
masterfrom
fix/3483-constexpr-scalars

Conversation

@zackees

@zackees zackees commented Jul 29, 2026 •

Copy link
Copy Markdown
Member

Closes out the last remaining item of #3483.

The change

static const char* MCPWM_TIMER_TAG is a mutable pointer — it occupies storage of its own in addition to the string literal it points at. As static constexpr const char* it emits nothing unless its address is taken.

Verified safe: the tag is only ever read, as the first argument to ESP_LOGE/ESP_LOGI/ESP_LOGW. There is no assignment to it anywhere in the file, so nothing depended on the pointer being mutable.

Most of #3483 was already done

The issue was filed against ~30 integer constants. None of its cited examples still appear in fastled-lint --checker singleton_elision on master:

Cited file Cited hits Actual now
channel_manager_esp32.cpp.hpp (PRIORITY_FORCE etc.) 14 0
equalizer.cpp.hpp (kBassStart, kBassEnd) 6 0

The original count came from ci/scan_singleton_elision.py, which still reports 101 where 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. Full accounting is in the issue comment.

One thing I deliberately did NOT do

objectfled_spi_mode.cpp.hpp:100 is still flagged:

static constexpr u32 kSpiMaxOutputWords = kSpiMaxInputBytes * kSpiWordsPerByte;

It is already static constexpr — already what a "split constants out" fix would produce. It's flagged only because the triviality test accepts a literal RHS but not one computed from other constants.

This blocks #3492 (promote to hard-fail at zero): the finding can't be driven to zero, because "wrap in fl::Singleton<T>" is not meaningful advice for a compile-time scalar.

I prototyped skipping constexpr scalars while keeping constexpr tables flagged (an array is far more likely to be ODR-used through a pointer, and then really does occupy flash) — then reverted it. singleton_elision_still_flags_non_literal_constexpr in lint_core/tests.rs deliberately pins the current behaviour for exactly those RHS forms, added under #3486. That's a documented decision, so I raised it on the issue rather than flipping it unilaterally.

Validation

  • 357/357 host tests, bash lint green
  • Checker no longer reports MCPWM_TIMER_TAG
  • Not yet locally confirmed: this is ESP-only code, so the 357 host tests do not
    exercise it. A local esp32dev compile was still running when this was opened, so
    I am relying on CI's ESP32 job for that leg rather than claiming a green build I
    have not seen. The change is a const char* -> constexpr const char* on a symbol
    that is only ever read, so the risk surface is a reassignment somewhere -- and I
    grepped: there is none.

🤖 Generated with Claude Code

`static const char* MCPWM_TIMER_TAG` is a mutable pointer, so it occupies
storage of its own in addition to the string literal it points at. As
`static constexpr const char*` it emits nothing unless its address is taken.

The tag is only ever read, as the first argument to ESP_LOGE/ESP_LOGI/
ESP_LOGW -- there is no assignment to it anywhere in the file, so nothing
depended on the pointer being mutable.

This was the last remaining item of #3483. The ~30 integer constants that
issue was filed against (PRIORITY_* in channel_manager_esp32.cpp.hpp,
kBassStart/kBassEnd in equalizer.cpp.hpp) no longer appear in the checker
output at all -- see the issue comment for the full accounting, plus one
open design question about constexpr scalars that blocks #3492.

Validated: 357/357 host tests, lint green, and the checker no longer
reports the tag.

Co-Authored-By: Claude <[email protected]>
@coderabbitai

coderabbitai Bot commented Jul 29, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The MCPWM timer tag changes from a static const pointer to a static constexpr pointer, with comments updated to describe its compile-time constant behavior.

Changes

MCPWM timer constant

Layer / File(s) Summary
Update MCPWM timer tag declaration
src/platforms/esp/32/drivers/gpio_isr_rx/mcpwm_timer.cpp.hpp
MCPWM_TIMER_TAG is declared as a static constexpr pointer, and surrounding comments are updated.

Estimated code review effort: 1 (Trivial) | ~2 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely describes the main change: making MCPWM_TIMER_TAG a compile-time constant.
✨ 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 fix/3483-constexpr-scalars

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@zackees

zackees commented Jul 29, 2026

Copy link
Copy Markdown
Member Author

Local esp32dev compile finished: All compilations completed successfully in 16m:57s, exit 0.

Being precise about what that does and doesn't prove, since a green build of a file that isn't in the build proves nothing:

  • I did not run an #error negative control on this TU (it would cost another ~17 min for a one-line change that CI already compiles).
  • What I did verify is that both guards wrapping the file resolve true for esp32dev:
    • FASTLED_RMT5 → 1 (auto-detected: ESP_IDF_VERSION >= 5.0.0 && FASTLED_ESP32_HAS_RMT)
    • SOC_MCPWM_SUPPORTED → 1 in the vendor soc_caps.h for classic ESP32
  • The compile log has 0 literal mentions of gpio_isr_rx, which is expected — the driver goes through the _build.cpp.hpp unity aggregator, so individual filenames don't appear as separate compile lines.

So: the guards say it compiles, and the build is green. CI's ESP32 job is the authoritative check for that leg, and I'm treating it as such rather than claiming more than I measured.

The functional risk remains what the PR body says — a reassignment of the tag somewhere — and there is none; all 10 uses are read-only ESP_LOGE/ESP_LOGI/ESP_LOGW first arguments.

@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Jul 29, 2026
@zackees
zackees merged commit 3cce972 into master Jul 29, 2026
12 checks passed
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jul 29, 2026
@zackees
zackees deleted the fix/3483-constexpr-scalars 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.

1 participant