Skip to content

Hardening no-STL Builds in C++ - #335

Open
ashvardanian wants to merge 2 commits into
mainfrom
reduce-includes
Open

Hardening no-STL Builds in C++#335
ashvardanian wants to merge 2 commits into
mainfrom
reduce-includes

Conversation

@ashvardanian

Copy link
Copy Markdown
Owner

No description provided.

`<memory>`, `<thread>`, and `<numeric>` leave `include/` entirely. `min_of_two`,
`max_of_two`, `rebound_allocator`, and `iterator_value` join `trivial_swap` in
`types.hpp`, and the ~93 call sites that reached for `std::min`,
`std::allocator_traits`, and `std::iterator_traits` without including a header for
them now name what they use - they resolved only because `<memory>` routes through
`bits/stl_algobase.h` on libstdc++.

`safe_vector` reads its allocator's members directly; the
`propagate_on_container_copy_assignment` branch was dead in every instantiation and
is gone. `std::gcd` becomes a Euclid loop, dropping a needless C++17 floor from the
fingerprints. The OpenMP executor sizes its slices from the team that actually shows
up rather than `hardware_concurrency()`, which ignored `OMP_NUM_THREADS` and left
`start` unclamped - with 7 threads on a 16-core box, `n=1` handed callers 14
inverted ranges.

`sz_status_t` gains `sz_out_of_range_k` and `sz_length_error_k`, appended below the
existing codes so nothing shifts. All 38 `throw` statements collapse into one
`raise(status, site)` taking `__func__`, leaving the exception dependency in a single
body and retiring 35 hand-written literals that could drift from the functions they
named. The same exception types still fire, `what()` still carries the site, and the
hot path still compiles to `cmp`/`jb` with the throw relocated out of line.

`SZ_AVOID_STL=1`, which no build system set and which had rotted to 137 errors,
compiles again. The freestanding headers move out of its gate while `<iterator>` and
`<memory>` stay behind it, and owning containers default to `dummy_alloc` so a caller
who brings no allocator gets a clean refusal. Only the failure path is conditional -
gating the throwing methods would have cascaded into `compare`, `rfind`, and every
future caller. `test/avoid_stl.cpp` pins the contract with header-guard probes and
runs from the four Ubuntu jobs; the existing suite cannot cover the mode, being 84
errors deep in the interop it removes.

Engine translation units drop ~25% of their preprocessed lines and about 6% of their
compile time; under `SZ_AVOID_STL=1` `stringzilla/types.hpp` falls from 58K
preprocessed lines to 13K.
The recorded DOI was v4.6.3's version record while the metadata declared 5.1.2.
The concept DOI always resolves to the newest release, so it survives the version
bumps that no automation applies to the DOI field.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant