Repository navigation
fix!: Verify sizes against the allocator and harden the derive macro - #68
Merged
Merged
Conversation
…uild `portable-atomic` without compare-and-swap Found by comparing the reported sizes with a counting allocator: - an `IndexMap`/`OrderMap` created with a capacity of 4 to 6, or 8 to 13, reported a hash table with half its buckets, since the reconstruction only handled capacities a table reports itself - a `RoaringBitmap` reported eight times the size of its bitset containers and twice the capacity of its array containers, because the byte totals of its statistics do not describe the allocations; the size is now derived from the container and value counts The `portable-atomic` feature did not build for targets without atomic compare-and-swap, like `thumbv6m`, where the 64 and 128 bit atomics do not exist.
…rive errors - an integration test with a counting global allocator compares the reported heap sizes with the real allocations, exactly where the layout is known and as a lower bound otherwise - an integration test implements the traits like a downstream crate does, so a changed signature fails to compile - the derive macro is expanded in unit tests, which pin its error messages and the shape of the generated implementation
- run the test suite on LoongArch and on x86 without SSE2, whose hash tables use other group widths, and the integration tests on WASI and under Miri - build for a target without atomic compare-and-swap - measure the coverage of the whole workspace, now that the derive macro has unit tests, and leave the examples out - do not name a Rust version for the integrations in the READMEs, which went stale with the last dependency update
…part The standard library builds `hashbrown` with its `nightly` feature, which scans 16 control bytes at once with LSX, while the `hashbrown` behind `indexmap` and `ordermap` is built without it. Both were given the same group width, which was wrong for one of them on LoongArch. The unit test comparing the standard library with a `hashbrown` built by `cargo` cannot hold on such a target and is superseded by the comparison with the allocator. The test jobs now run every test binary, so one failure no longer hides the others.
- fold the full 128 bit product in the address hasher: rotating left the always zero low bits of an address into the bucket index of tables beyond 2^26 buckets, and into the tag bits used on 32 bit targets - keep the 64 and 128 bit `portable-atomic` types on targets without compare-and-swap when the new `portable-atomic-critical-section` feature or the `portable_atomic_unsafe_assume_single_core` cfg provides them - report the real capacity of roaring array containers, which is half of what the statistics state - measure a `ThinVec` of zero sized or over-aligned elements correctly - parse the field attributes by hand instead of with `attribute-derive`, so every error message is our own and independent of the features other crates enable for `syn`; accept an empty `ignore()` and a bare attribute - run the breaking change check in a workflow of its own, so editing a title no longer reruns the test suite, and keep tag runs apart from branch runs - correct comments and documentation about emptied hash tables, zero sized entries and variant level `ignore(...)`, and give the tests about removals a floor
Version 0.2.20 stopped allocating a header for them, so the size of such a vector depended on the resolved version.
Found by building and testing against the minimal versions of all direct dependencies: `chrono` only exports `TimeDelta` since 0.4.34, and `syn` needs newer `quote` and `proc-macro2` than the bare major version. The allocator test no longer needs a recent `bytes` either.
- accept the parenthesised attribute spellings `size(4)`, `size_fn(helper)` and `ignore(true)` again, which compiled before the field attributes were parsed by hand - reject a `size` with a suffix other than `usize`, which was dropped silently and turned `0XFF` into 0, and report every invalid `size` with the same message - compute the number of buckets without an intermediate overflow, and saturate where the table size is added up - build the single core cfg of `portable-atomic` in CI, and document which ways of enabling its wide atomics this crate can see - mention the new feature where the features are listed, and drop a stale dependency name from a comment
- give the local variables of the generated code the hygiene of a `macro_rules!` local, so a helper function named like one of them is no longer shadowed - hand the `size` literal on as written, so the compiler rejects one which does not fit the `usize` of the target instead of truncating it - tell an invalid value for `ignore` apart from a list of generics, and describe precisely what `size` accepts - implement `GetSize` for the wide `portable-atomic` types on AVR and MSP430, where they always exist - check the publication of both crates in one go, which also works on the commit bumping the version - saturate where the size of an index map is added up, like for the tables of the standard library - correct comments and documentation, and a test which no longer pinned what it claimed
Hygiene only keeps local bindings apart. An item of the same name, like a lower case constant or a static brought in by a glob import of generated bindings, turned the binding into a pattern or was rejected as shadowed. The locals carry their `__get_size_` prefix again, on top of the hygiene. The generated code also names `usize` by its full path, so a type of that name in scope no longer breaks the derive macro.
`::core::primitive::usize` does not resolve in a crate with a dependency named `core`. The generated code already relies on `::get_size2`, which now re-exports the type for it. Also from the fifth review: - sum up tuples and ranges by rebinding instead of assigning, which needs no lint expectation that newer clippy versions leave unfulfilled - do not count the two bytes of the serialized run count of a roaring run container - document the `__get_size_` prefix as reserved, and test that the hygiene of the generated locals holds for helpers and fields carrying it
Neither the hidden re-export of `usize` nor the corrected size of a run container was guarded by a test. The documentation now lists every kind of item the reserved prefix clashes with, and says how the generated code refers to the trait crate.
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.
Pre-release hardening for 0.12.0. Sizes are now checked against a counting allocator instead of against our own formulas, on eight platforms, and everything that surfaced was fixed. Six independent review passes went over the result.
Size fixes
IndexMap/OrderMapcreated with a capacity of 4 to 6 or 8 to 13 reported a hash table with half its buckets.hashbrownbehindindexmapandordermap8. Both are told apart now.RoaringBitmapreported eight times the size of its bitset containers and twice the capacity of its array containers, because the byte totals ofstatistics()do not describe the allocations. Bitset and array containers are exact now, run containers a lower bound.ThinVecof zero sized elements reported a header it does not allocate, and the header padding for over-aligned elements was missing. Requiresthin-vec0.2.20.Tracker
StandardTrackerhashes addresses with a folded 128 bit multiply. The previous finalizer lost its spread beyond 2^26 buckets and on 32 bit targets.Derive macro
attribute-deriveis no longer a dependency. Every error message is our own and pinned by a unit test.macro_rules!local and keep their__get_size_prefix, so neither a helper function, a field nor an item of the user can collide with them. The prefix is documented as reserved.::get_size2, includingusize, so a consumer may shadowusizeor depend on a crate calledcore.sizeliteral is handed on as written, so the compiler rejects one which does not fit theusizeof the target instead of truncating it.portable-atomicthumbv6m.portable-atomic-critical-sectionfor the 64 and 128 bit atomics on such targets; theportable_atomic_unsafe_assume_single_corecfg is honoured, and AVR and MSP430 are covered.Tests
tests/allocation_ground_truth.rs: a counting global allocator compares reported and real sizes, exactly where the layout is known and as a lower bound otherwise.tests/public_api.rs: implements both traits like a downstream crate, and derives next to items, helpers and fields named like the generated locals.CI
thumbv6mDependencies
chrono0.4.34 (first to exportTimeDelta),thin-vec0.2.20,syn3.0.4,quote1.0.40,proc-macro21.0.95Breaking changes
RoaringBitmap,RoaringTreemapandThinVecof zero sized elements report smaller sizes; smallIndexMap/OrderMapreport larger ones.sizeattribute with a suffix other thanusizeis rejected (0XFFused to be read as 0), and so is a value which does not fit theusizeof the target.sizeattribute, since it is passed through as written.__get_size_clashes with the generated code.get-size2of the same release; both crates have to be published together as 0.12.0.portable-atomictypes only implementGetSizethrough the new feature or the cfg.Known limits
BTreeMap/BTreeSetnodes,DashMapshards and the container list of aRoaringBitmapare not counted'staticBytesbuffer cannot be told apart