Repository navigation
Description
Context
#3027 (phase 1 of #3022) lands the structural gate that drops float / fl::vector<float> from fl::json_value::variant_t on FL_JSON_HAS_FLOAT=0. That eliminates the soft-FP cascade from JsonTokenizer::parse, JsonBuilder::on_token, parseFloat, and all variant::visit_fn<float, ...> instantiations — verified on lpc845brk AutoResearchLpc.ino: zero __aeabi_d* / __aeabi_f* symbols, flash 64.20 KB → 50.44 KB (~13.6 KB saved).
But during PR review the principle was tightened: the FastLED library must never pull in floating-point ops on Low-memory targets, regardless of which sketch is linked. The current PR violates that in two ways:
-
json(float)/json(double)/operator=(float)/set(key, float)truncate-to-i64 fallback insrc/fl/stl/json.hinvokesstatic_cast<i64>(f)→ pulls__aeabi_f2iz/__aeabi_d2iz(~64 B each) into the link at every call site, even when the user only ever wanted integer storage. The library is doing the float conversion itself; the user did not opt in. -
FastLED-internal UI controls call
json::set(key, float)from library code — that is, the soft-FP pull is anchored inside the library, not inside the user's sketch. The library hits the FP path even when the user's sketch is pure integer JSON-RPC, as long as the link pulls one of the offending TUs in.
The mandate per the design discussion: "If the user uses float that's their problem, FastLED lib should not pull in floating ops when memory is low. If the sketch does then that's beyond our control."
Concrete gap
A. FastLED-internal callers that pass float into fl::json
| File | Line(s) | Pattern |
|---|---|---|
src/platforms/shared/ui/json/slider.h |
20–21, 27–31, 40 | JsonSliderImpl API takes float for value/min/max/step. |
src/platforms/shared/ui/json/slider.cpp.hpp |
18–21, 41–46, 52, 62–65 | Stores float mMin/mMax/mValue/mStep; calls json.set("value", mValue) etc. and consumes `json |
src/platforms/shared/ui/json/number_field.h |
20, 26–27, 35, 37–40 | Same pattern as slider: float in API + storage. |
src/platforms/shared/ui/json/number_field.cpp.hpp |
30–32 | json.set("value"/"min"/"max", float). |
src/platforms/shared/ui/json/json_console.cpp.hpp |
190–199, 216, 263 | strtod + float storage + doc.set(idStr, value) with a float. |
src/fl/math/screenmap.cpp.hpp |
209, 290–304 | as_float() for diameter; fl::json(static_cast<double>(coord)) per element. Already gated in #3027 behind !FL_JSON_HAS_FLOAT — works as a model for the other consumers. |
B. Missing manual fixed-point ↔ json API
fl::fixed_point<IntBits, FracBits, Sign> already exists at src/fl/math/fixed_point/ (32-bit Q-format types: s0x32, s16x16, u24x8, etc.) but has no fl::json integration. Today there is no way to round-trip a fractional JSON number on a Low-memory target other than through as_float() (which dispatches the variant's i64 arm via static_cast<float>(value) and pulls __aeabi_l2f at the call site).
To honor the mandate, fl::json needs these manual extractor / setter overloads:
// In fl::json_value (extractors — pure-integer, no FP):
template<int IntBits, int FracBits, typename Sign>
fl::optional<fl::fixed_point<IntBits, FracBits, Sign>> as_fixed_point() const FL_NOEXCEPT;
// Q-format pair-style accessors per the #3022 design body:
fl::pair<fl::i32, fl::u32> to_q30_31() const FL_NOEXCEPT;
fl::pair<fl::i32, fl::u32> to_q15_46() const FL_NOEXCEPT;
fl::pair<fl::u32, fl::u32> to_uq32_29() const FL_NOEXCEPT;
// In fl::json (setter overloads that store as packed i64, no FP):
template<int IntBits, int FracBits, typename Sign>
json& operator=(fl::fixed_point<IntBits, FracBits, Sign> v) FL_NOEXCEPT;
template<int IntBits, int FracBits, typename Sign>
void set(const fl::string& key, fl::fixed_point<IntBits, FracBits, Sign> v) FL_NOEXCEPT;These should land alongside the fl::json_number packed-tagged-union design from the parent issue (#3022), since the storage layout is the same (61-bit payload + 3-bit tag in one i64 variant slot).
C. Phase-1 design defect: json(float) / json(double) truncation fallback in #3027
The fallback added in #3027 src/fl/stl/json.h:
#else // FL_JSON_HAS_FLOAT == 0
json(float f) FL_NOEXCEPT : mValue(fl::make_shared<json_value>(static_cast<i64>(f))) {}
json(double d) FL_NOEXCEPT : mValue(fl::make_shared<json_value>(static_cast<i64>(d))) {}
#endifdoes the conversion inside the library. The user did not ask for truncation; the library decided. __aeabi_f2iz / __aeabi_d2iz get pulled in at every call site. Per the mandate this should be a hard compile error directing the caller to the manual fixed-point setter — or, equivalently, the overload should not exist.
Same applies to:
json& operator=(float)/json& operator=(double)injson.hvoid set(const fl::string& key, float)/void set(..., double)injson.h
Proposal — "phase 1.5" PR (closes this issue)
-
Remove the truncation fallback in
json.h. Gatejson(float/double),operator=(float/double),set(key, float/double)behind#if FL_JSON_HAS_FLOATonly. No#elsebranch. Caller code that tries to pass a float on a Low-memory build hits a compile error that directs them tofl::fixed_point<>+ the newset(key, fixed_point)overload (B above). The error message should name the migration path. -
Gate FastLED-internal UI-control
.cpp.hppfiles behind#if FL_JSON_HAS_FLOAT.slider.cpp.hpp,number_field.cpp.hpp, the float branch ofjson_console.cpp.hpp. OnFL_JSON_HAS_FLOAT=0the entire UI-slider TU drops out of the library archive — sketches that link nothing else fromplatforms/shared/ui/json/see zero impact, sketches that try to use a slider fail at link withundefined reference, mirroring the existingFASTLED_NO_JSONergonomics. ScreenMap already follows this pattern in feat(json): gate float out of variant on FL_JSON_HAS_FLOAT=0 (#3022 phase 1) #3027.Future / phase 2: add fixed-point variants —
JsonSliderImplFixed<Q16x16>etc. — so onFL_JSON_HAS_FLOAT=0users still have a working slider, just one whose value type isfl::s16x16instead offloat. Tracked separately under fl::json: custom 64-bit packed tagged-number type (replaces variant<i64, float, double> in #3002) #3022 once the json_number Q-format extractors land. -
Land the json↔fixed_point extractor / setter API (B above) as a sibling PR or bundled into the phase-2
fl::json_numberPR for fl::json: custom 64-bit packed tagged-number type (replaces variant<i64, float, double> in #3002) #3022. The extractor / setter design is independent of the packed-tag union; it can land first and the packed-tag union promotes to use it later.
Verification (for the closing PR)
bash compile lpc845brk --examples AutoResearchLpcsucceeds withFL_JSON_HAS_FLOAT=0(same as today).arm-none-eabi-nm -C firmware.elf | grep -E '(aeabi_d|aeabi_f|f2iz|d2iz|__l2f|__floatdisf)'stays empty (currently passes theaeabi_d/aeabi_fcheck but__aeabi_f2iz/__aeabi_d2izare reachable from the truncation fallback when any caller links).- A pure-integer LPC sketch that does not use UI controls or ScreenMap continues to compile (this is the
AutoResearchLpc.inobaseline). - A pure-integer LPC sketch that does try to write
json["x"] = 3.14ffails at compile time with a clear error message pointing tofl::s16x16+ the manual setter.
Related
- fl::json: custom 64-bit packed tagged-number type (replaces variant<i64, float, double> in #3002) #3022 (parent —
fl::json_numberpacked type) - feat(json): gate float out of variant on FL_JSON_HAS_FLOAT=0 (#3022 phase 1) #3027 (in-flight phase 1 — structural variant gate; introduces the truncation fallback this issue is asking to remove)
- refactor(system): introduce FL_PLATFORM_HAS_*_MEMORY canonical names (closes #3000) #3019 / Rename SKETCH_HAS_*_MEMORY macros to FL_PLATFORM_HAS_*_MEMORY #3000 (
FL_PLATFORM_HAS_*_MEMORYcanonical names; theFL_JSON_HAS_FLOATdefault tracks these) src/fl/math/fixed_point/(existing 32-bit Q-format types — destination for the manual extractor / setter API)
🤖 Filed via Claude Code as the gap-tracking issue spun out of #3027 review.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
feat(json): remove float truncation fallback + add fixed_point setter (…
zackees commentedon Jun 14, 2026
Phase 1.5 work landed as commit cfe8b9156d on PR #3027's branch (
feat/3022-json-no-float), per the issue's "fold into the in-flight PR" guidance. The commit:src/fl/stl/json.h— drops the#elsetruncation fallback forjson(float/double),operator=(float/double), andset(key, float/double). OnFL_JSON_HAS_FLOAT=0these are now SFINAE-templatedFL_STATIC_ASSERToverloads that name the migration path (fl::fixed_point<>, e.g.fl::s16x16fromsrc/fl/math/fixed_point/). The library no longer takes ownership of float→i64 conversion.src/fl/stl/json.h— adds thefl::json↔fl::fixed_pointsetter / extractor API (item B from the issue body), but minimally: templatedjson(FP),operator=(FP),set(key, FP), andas_fixed_point<FP>()keyed on a SFINAE trait that probesINT_BITS/FRAC_BITS/raw()/from_raw(). Storage is the existingi64variant slot (since "our number format is itself a super fixed point" — the Q-format is encoded in the C++ type at the call site, not as a JSON tag). The Q-format pair accessors and fulljson_numberpacked-tag union remain deferred to fl::json: custom 64-bit packed tagged-number type (replaces variant<i64, float, double> in #3002) #3022 phase 2.src/platforms/shared/ui/json/slider.cpp.hpp,.../number_field.cpp.hpp— wrap whole-TU bodies in#if FL_JSON_HAS_FLOAT. Sketches that don't instantiate these widgets see no impact; sketches that try fail at link withundefined reference, matching theFASTLED_NO_JSON/ScreenMapergonomics.src/platforms/shared/ui/json/json_console.cpp.hpp— tightens the existingSKETCH_HAS_LARGE_MEMORYgate to also requireFL_JSON_HAS_FLOAT, so a user opt-out via-DFL_JSON_HAS_FLOAT=0on a Large-memory part drops the TU too.CI on PR #3027 will exercise the LPC845 verification matrix from the issue body. The fixed-point widget variants (
JsonSliderImplFixed<Q16x16>) remain phase-2 work.🤖 via Claude Code.
feat(json): introduce fl::json_number packed-tag Q-format number (#3022/
feat(json): integer-only IEEE 754 codec replaces soft-FP cascade (refs …
zackees commentedon Jun 18, 2026
Fixed by merged PR #3211: #3211
What changed:
fl::json(float),fl::json(double), and fixed-point JSON entry points.doubleand fixed-point values now convert into JSON float storage through integer IEEE-754 bit construction instead of relying on target floating-point conversion helpers.ScreenMap::toJsonavoids unnecessaryfloat -> doublepromotion.Upgrade guidance: no source changes are expected for users. Update to a FastLED version containing PR #3211; existing JSON float/double/fixed-point callers should continue to compile, including low-memory LPC builds.