Repository navigation
test(spi): pin SPI chipset instantiation across the data-rate range - #3826
Merged
Merged
Conversation
Addresses #974 and #976, both "template instantiation depth exceeds maximum" when a software-SPI chipset is given an explicit data rate. Both are fixed. delaycycles<N> used to recurse linearly (N -> N-1), which is what produced the reported chain from CYCLES=2147483640 downwards. It now splits binary with <0>/<1>/<2> base cases present in every translation unit, so depth is logarithmic. Verified on a software-SPI platform rather than assumed: temporarily giving examples/Apa102 the DATA_RATE_KHZ(1) from the reports and running `bash compile uno --examples Apa102` succeeds. Reverted after. The reason these lasted six years is a coverage hole, not a hard bug. No example anywhere passes a data rate at all, and the only tests that did used a single fast rate. So the 83-example compile matrix never once instantiated the path that broke. This closes the natively-closable part of that hole: SK9822 and APA102 across DATA_RATE_KHZ(1) -- the exact rate from #976 -- through DATA_RATE_MHZ(24). Deliberately scoped, and the test says so rather than implying more: FASTLED_STUB_IMPL sits in the *hardware* SPI branch of fastspi.h, so DATA_RATE_KHZ expands to a frequency here, not to the cycles-per-bit divider that fed delaycycles. These cases pin the template surface; they cannot reach the software-SPI path. That one needs a platform compile, and the natural home for such a test (examples/CompileTest/) is itself dead -- see #3816. bash test --cpp: 277/277 unit, 83/83 examples. bash lint: clean. Co-Authored-By: Claude <[email protected]>
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe pull request adds compile-time tests for ChangesSPI instantiation coverage
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addresses #974 and #976 — both
template instantiation depth exceeds maximumwhen a software-SPI chipset is given an explicit data rate, on Teensy and ESP32 respectively.Both are fixed
delaycycles<N>used to recurse linearly (N -> N-1), which is exactly the chain in #974's log:It now splits binary —
delaycycles<N/2>() + delaycycles<N - N/2>()— with<0>/<1>/<2>base cases present in every translation unit, so depth is logarithmic.src/platforms/shared/delay_cycles_generic.h:40-52carries a good comment on why those base cases must be per-TU.Verified on a software-SPI platform, not assumed. I temporarily gave
examples/Apa102theDATA_RATE_KHZ(1)from the reports and ranbash compile uno --examples Apa102— succeeds in 31s. Reverted after.Why they lasted six years
Not a hard bug — a coverage hole:
grep -rn "DATA_RATE_KHZ\|DATA_RATE_MHZ" examples/returns nothing.DATA_RATE_MHZ(12)).So the 83-example compile matrix, across every board, never once instantiated the path that broke.
What this adds
SK9822 and APA102 across
DATA_RATE_KHZ(1)— the exact rate from #976 — throughDATA_RATE_MHZ(24).Scoped deliberately, and the test says so
This is the part I want reviewed rather than skimmed.
FASTLED_STUB_IMPLis in the hardware-SPI branch offastspi.h:78:so natively
DATA_RATE_KHZexpands to a frequency, not to the cycles-per-bit divider that feddelaycycles. These cases pin the template surface — that every rate, including the pathological ones, instantiates — but they cannot reach the software-SPI path that actually broke.I caught that after writing a native test and nearly reporting it as proof. It isn't. The genuine guard needs a platform compile, and the natural home for one (
examples/CompileTest/) is itself dead — see #3816. The test comment states this so nobody later reads it as coverage it doesn't provide.Related finding, not fixed here
delaycyclesis loop-based on AVR (_delaycycles_avr<CYCLES/3, CYCLES%3>) but the generic path force-inlines N NOPs via the binary split. On a non-AVR software-SPI platform a slow rate therefore emits tens of thousands of inlined NOPs — it compiles, but the code-size cost is large and silent. That's Teensy 3.x, exactly #974's board. Worth its own look; I haven't measured it on hardware-class flash so I'm not asserting a number.bash test --cppbash lintbash compile uno --examples Apa102withDATA_RATE_KHZ(1)🤖 Generated with Claude Code
Summary by CodeRabbit