Repository navigation
singleton: sweep the safe <=2-hit files (Tier 1e, #3488) - #3756
Merged
Merged
Conversation
Part of #3481. Addresses the safe portion of #3488. Moves five namespace-scope variables behind Singleton<T> so --gc-sections can drop the storage together with its accessor when a sketch never reaches the code: - fl/test/fltest.cpp.hpp sCurrentTestSkipped + sSkipReason -> SkipState - fl/sensors/pir.cpp.hpp g_counter -> PirNameCounter - platforms/wasm/audio_input_wasm.cpp.hpp g_wasmAudioInput -> holder - platforms/shared/coroutine_context.cpp.hpp sCoroutinePlatformInstance folded into the CoroutineGlobals singleton that already existed in that file, rather than adding a second one SingletonElisionChecker: 39 -> 34. Two behaviour notes: - pir.cpp.hpp increments the counter at two sites, and the second increment is reachable only when the first returned non-zero. Both now hit the same singleton field, so the (slightly odd) existing numbering is preserved exactly rather than quietly normalised. - audio_input_wasm.cpp.hpp had its extern "C" JS callback reaching directly at fl::g_wasmAudioInput even though fl::wasm_get_audio_input() already existed. The callback now goes through that accessor. Deliberately NOT migrated, with reasons -- these are the rest of the <=2-hit set, and each is a worse candidate than it looks: - platform_time_lpc.cpp.hpp g_millis (volatile, written by the SysTick ISR) and g_systick_started. Singleton<T>::instance() lazily constructs behind an `if (!ptr)` check, so routing an ISR-updated counter through it adds a branch and a construction race. Belongs to the ISR tier (#3491). - avr/attiny/clockless_blocking.cpp.hpp gTimeErrorAccum256ths sits in an ATtiny bit-banging path where the extra indirection risks the timing the file exists to hold. - gpio_isr_rx/mcpwm_timer.cpp.hpp MCPWM_TIMER_TAG is a const char* log tag, which is constant-splitting work (#3483), not Singleton work. - FastLED.cpp.hpp pSmartMatrix is public API surface, explicitly out of scope for this issue. - asio/http/server.cpp.hpp s_esp_request_queue / s_esp_httpd are FreeRTOS handles touched from the httpd task; same ISR/task-safety question as the LPC pair. Validated: 357/357 on a clean build (the fltest change is the test framework itself, so the suite exercises the reset and read paths on every one of the 357 cases); wasm compile clean, with an #error negative control confirming audio_input_wasm.cpp.hpp is actually in that build rather than assuming a green compile covered it; lint green. Not covered: skipTest()'s write path. The FL_SKIP test that would exercise it is #if 0 upstream, so the two assignments inside skipTest() are compiled but never executed by CI. Left disabled rather than enabled here, since the comment says enabling it perturbs suite results. Co-Authored-By: Claude <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughThe pull request replaces several file-scope globals with ChangesSingleton-backed state migration
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related issues
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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.
Part of #3481. Addresses the safe portion of #3488 — deliberately not all of it, see below.
Moves five namespace-scope variables behind
Singleton<T>so--gc-sectionscan drop the storage together with its accessor when a sketch never reaches the code.fl/test/fltest.cpp.hppsCurrentTestSkipped+sSkipReason→SkipStatefl/sensors/pir.cpp.hppg_counter→PirNameCounterplatforms/wasm/audio_input_wasm.cpp.hppg_wasmAudioInput→ holderplatforms/shared/coroutine_context.cpp.hppsCoroutinePlatformInstancefolded into theCoroutineGlobalssingleton already in that file, rather than adding a second oneSingletonElisionChecker: 39 → 34.
Two behaviour notes
pir.cpp.hppincrements the counter at two sites, the second reachable only when the first returned non-zero. Both now hit the same singleton field, so the existing (slightly odd) numbering is preserved exactly rather than quietly normalised.audio_input_wasm.cpp.hpphad itsextern "C"JS callback reaching directly atfl::g_wasmAudioInputeven thoughfl::wasm_get_audio_input()already existed. The callback now goes through that accessor.Deliberately NOT migrated
These are the rest of the ≤2-hit set. Each is a worse candidate than it looks, and the reason matters:
Singleton<T>::instance()lazily constructs behind anif (!ptr)check, so it is not free and not ISR-safe.platform_time_lpc.cpp.hpp—g_millisisvolatileand written by the SysTick ISR;g_systick_startedlikewise. Routing an ISR-updated counter through a lazily-constructing accessor adds a branch and a construction race. Belongs to the ISR tier (singleton: migrate remaining ISR-touching drivers — LPUART, RMT5 peripheral, LCD_CAM, MCPWM (Tier 2c) #3491).avr/attiny/clockless_blocking.cpp.hpp—gTimeErrorAccum256thssits in an ATtiny bit-banging path where the extra indirection risks the very timing the file exists to hold.gpio_isr_rx/mcpwm_timer.cpp.hpp—MCPWM_TIMER_TAGis aconst char*log tag. That's constant-splitting work (lint: split integer-constant globals into PreferConstexprChecker #3483), notSingletonwork.FastLED.cpp.hpp—pSmartMatrixis public API surface, explicitly out of scope per the issue.asio/http/server.cpp.hpp—s_esp_request_queue/s_esp_httpdare FreeRTOS handles touched from the httpd task; same safety question as the LPC pair.I'd rather leave #3488 partially open with these documented than migrate them and introduce an ISR race to close a lint count.
Validation
fltest.cpp.hppchange is to the test framework itself, so the suite exercises the reset and read paths on all 357 cases.#errornegative control confirmingaudio_input_wasm.cpp.hppis actually in that build (2 hits) — a green compile of a file that isn't compiled proves nothing.bash lintgreen.Not covered:
skipTest()'s write path. TheFL_SKIPtest that would exercise it is#if 0upstream, so those two assignments are compiled but never executed by CI. I left it disabled rather than flipping it on, since the surrounding comment says enabling it perturbs suite results.🤖 Generated with Claude Code
Summary by CodeRabbit