You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
singleton: migrate fl/stl/{ios,istream,ostream} state (Tier 1b) #3485
Wrap the stream-state statics in src/fl/stl/ios.cpp.hpp, src/fl/stl/istream.cpp.hpp, and src/fl/stl/ostream.cpp.hpp in fl::Singleton<T> so unused stream storage is elided.
Approach
Per file, identify the file-scope mutable state (typically default stream buffer, format flags, current width/precision).
Wrap in a per-file state struct → fl::Singleton<Struct>::instance().field.
If multiple state pieces logically belong together across the three files, consider a shared StreamState in fl/stl/streams_state.h.
bash test --cpp — the STL tests exercise these directly.
bash bloat before/after diff.
Acceptance criteria
All three files clean of SingletonElisionChecker warnings.
STL tests pass.
Storage confirmed elidable when streams are unused.
Audited against the finding in #3754 / #3486: fl::Singleton elision pays off only for objects with dynamic initialization (those register .init_array entries that pull in a ctor and resist --gc-sections). It does nothing for constant-initialized PODs — builds already pass -ffunction-sections -fdata-sections (ci/boards.py:795), so those are already dropped when unreferenced. For PODs the wrap is a net loss: storage grows by a T*, every access gains a null-check, and constant-initialization (race-free) is replaced by Singleton<T>::instance()'s hand-rolled if (!ptr), which bypasses the C++11 magic-static guard.
All 6 hits are already annotated, and this file already demonstrates the pattern the whole tier should be measured against.
The six carry FL_LINT_ALLOW_GLOBAL with written justifications (ios.cpp.hpp:11,13,15; ostream.cpp.hpp:8,11; istream.cpp.hpp:127), so the checker reports 0 hits here today — the acceptance criterion is already met. hex_t/dec_t/oct_t/endl_t are empty structs; ostream cout; uses = default with int mBase = 10;, so it is constant-initialized.
More useful: istream.cpp.hpp:133 already does the right thing —
That is a C++11 magic static: lazy construction with a compiler-generated thread-safe guard, which is strictly better than fl::Singleton's hand-rolled if (!ptr). Where lazy init genuinely is wanted, this is the pattern to copy.
Closing as not planned after re-validating the July audit against current master.
The proposed fl::Singleton<T> migration would not satisfy the issue's stated optimization goal:
hex, dec, oct, and endl are public empty-struct manipulator objects with constant initialization.
cout is public named API state with a defaulted/constant-initialized small object; changing it to cout() would be source-breaking.
cin is likewise a small public stub, while its actual buffered istream_real storage is already lazy through a C++11 function-local static in cin_real().
The tree builds with per-data sections and linker garbage collection, so unreferenced constant-initialized POD data is already elidable. Wrapping it would add pointer storage and per-access checks without removing a dynamic initializer.
Activity
zackees commentedon Jul 28, 2026
Audited against the finding in #3754 / #3486:
fl::Singletonelision pays off only for objects with dynamic initialization (those register.init_arrayentries that pull in a ctor and resist--gc-sections). It does nothing for constant-initialized PODs — builds already pass-ffunction-sections -fdata-sections(ci/boards.py:795), so those are already dropped when unreferenced. For PODs the wrap is a net loss: storage grows by aT*, every access gains a null-check, and constant-initialization (race-free) is replaced bySingleton<T>::instance()'s hand-rolledif (!ptr), which bypasses the C++11 magic-static guard.All 6 hits are already annotated, and this file already demonstrates the pattern the whole tier should be measured against.
The six carry
FL_LINT_ALLOW_GLOBALwith written justifications (ios.cpp.hpp:11,13,15;ostream.cpp.hpp:8,11;istream.cpp.hpp:127), so the checker reports 0 hits here today — the acceptance criterion is already met.hex_t/dec_t/oct_t/endl_tare empty structs;ostream cout;uses= defaultwithint mBase = 10;, so it is constant-initialized.More useful:
istream.cpp.hpp:133already does the right thing —That is a C++11 magic static: lazy construction with a compiler-generated thread-safe guard, which is strictly better than
fl::Singleton's hand-rolledif (!ptr). Where lazy init genuinely is wanted, this is the pattern to copy.Recommend closing as not-planned. See #3492.
zackees commentedon Aug 20, 2026
Closing as not planned after re-validating the July audit against current master.
The proposed
fl::Singleton<T>migration would not satisfy the issue's stated optimization goal:hex,dec,oct, andendlare public empty-struct manipulator objects with constant initialization.coutis public named API state with a defaulted/constant-initialized small object; changing it tocout()would be source-breaking.cinis likewise a small public stub, while its actual bufferedistream_realstorage is already lazy through a C++11 function-local static incin_real().FL_LINT_ALLOW_GLOBALrationale, soSingletonElisionCheckerhas no outstanding finding in these files. Parent meta Meta: migrate namespace-scope globals to fl::Singleton<T> for --gc-sections elision #3481 is also closed.No code change is warranted, and no PR should be manufactured for a net-negative migration.