Repository navigation
fix(avr/math): #undef Arduino F() macro before fl::math polynomial templates (unbreak master Uno build) - #3086
Conversation
…emplates Master Uno (AVR) build has been red since c0da8bd landed the Low-memory polynomial fallbacks. Root cause: Arduino's WString.h (transitively included via the Arduino core on AVR) defines `F()` as a PROGMEM-string macro. The preprocessor rewrites every `F(value)` constructor cast in fl::math's polynomial helpers (e.g. `F(1.0 / 6.0)`, `F(0.5)`) into `WString::F(1.0 / 6.0)`, which fails with "initializer fails to determine size of '__c'". Undefining the macro at the top of math.cpp.hpp is local to this translation unit. fl::math itself never uses the macro; only end-user sketches do (where the macro stays defined). No behavior change on any platform. Pre-existing master breakage; surfaced while CI-checking PRs #3084 / #3085 for meta #3079.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughIn ChangesArduino F() Macro Collision Fix
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
…er (closes #3235 Tier 1B) (#3238) Replaces the previous 5-alternative `fl::variant` storage (heap-fallback + free-fn + inlined-lambda + non-const member + const member) with a single small-buffer-optimized storage plus two function pointers: - `Invoker`: per-Func; knows how to call the stored callable with (Args...). - `Manager`: per-Func (or shared `trivial_manager<sizeof(Func)>` for trivially-copyable callables); multiplexes copy / move / destroy through an Op enum. The variant's per-(T, op) thunk explosion -- 5 alternatives × 4 ops × N signatures = ~25 small functions per Sig at ~80-120 B each -- collapses to one invoker + one manager pointer per Func instance. Trivially-copyable captures (the common case) share a per-size `memcpy` manager so the linker collapses many F's into one body. ## Member-function support preserved The `function(R(C::*)(Args...), C*)` and const variant constructors remain in the public API. They route through thin `NonConstMemberWrapper<C>` and `ConstMemberWrapper<C>` structs stored in the SBO -- the legacy `MemberCallableBase` / `NonConstMemberCallable` / `ConstMemberCallable` class hierarchy and its virtual dispatch are gone. ## Heap fallback retained Lambdas larger than `FASTLED_INLINE_LAMBDA_SIZE` (default 64 B) still compile -- they get wrapped in a `HeapHolder<Func>` struct that stores `fl::shared_ptr<Func>` in the SBO. This preserves the legacy "big lambda lives on the heap" semantics without re-introducing the variant. Tradeoff investigation tracked separately at #3237 (HeapHolder's shared_ptr vs unique_ptr-deep-copy vs single-threaded-refcount options). ## Verification LPC845-BRK / AutoResearch (Low-memory): flash 49,396 B -> 48,260 B (-1,136 B) RAM 9,984 B -> 9,984 B (unchanged) Teensy 4.0 / AutoResearch (Large-memory): flash 357,376 B -> 348,160 B (-9,216 B saved, -2.6%) RAM 112,576 B -> 110,528 B (-2,048 B saved) `fl::function`-related symbol mass on LPC845 dropped from 3,164 B (post- #3084) to 2,302 B (-862 B specifically from the variant collapse, the rest is downstream DCE). The Low-memory `FL_FUNCTION_FULL_VARIANT` macro is no longer needed -- both tiers share the same Option B implementation. The Low-memory "no-op heap-fallback" branch from #3077/#3084 is replaced by the real `HeapHolder` path; behavior is now uniform across all targets. ## Rename: F -> Func template parameter Renamed the template parameter throughout to `Func` because Arduino's `Arduino.h` (LPC8xx core, AVR core) defines `F()` as a PROGMEM-string preprocessor macro that collides with `F` used as a template parameter name. Same root cause as #3086's m0clockless_c.h fix. Refs #3235 Tier 1B, #3237
Summary
Master's Uno (AVR) build has been red since
c0da8bd35d("perf(fl/math): gate libm behind SKETCH_HAS_LARGE_MEMORY; polynomial impls on Low-memory"). 5 consecutive master CI failures, none related to feature work. This PR unbreaks it.Root cause
Arduino's `WString.h` (transitively included via the Arduino core on AVR and other Arduino-framework targets) defines:
```cpp
#define F(string_literal) (reinterpret_cast<const __FlashStringHelper *>(PSTR(string_literal)))
```
That collides with the `template ` parameter used by 9 polynomial / Newton-iteration helpers in `src/fl/math/math.cpp.hpp` (sqrt_newton_, sin_poly_quarterturn_, cos_poly_quarterturn_, sin_reduce_, cos_reduce_, log_natural_, atan_poly_unit_, atan_full_, atan2_full_, ldexp_loop_). The preprocessor rewrites every `F(value)` constructor cast in those templates into `WString::F(value)`, which fails with:
```
WString.h:38:74: error: initializer fails to determine size of '__c'
note: in expansion of macro 'F'
```
Fix
`#undef F` at the top of `math.cpp.hpp` after the includes that pull in WString.h. Local to this translation unit; `fl::math` itself never uses the macro; only end-user sketches do (where the macro stays defined).
No behavior change on any platform. Just unbreaks the AVR translation unit.
Discovery context
Surfaced while CI-checking PRs #3084 and #3085 (against meta #3079 — LPC845 64 KB flash bloat hunt). Those PRs were green on every other platform but blocked by this pre-existing master breakage on AVR.
Test plan
🤖 Generated with Claude Code
Summary by CodeRabbit