Commit 42ece5a
committed
turbo-tasks: TinyVec API hardening + const-generic MAX
* Tighten visibility: `new`, `capacity`, `as_slice`, `as_mut_slice`,
`reserve` are now private. `len` and `is_empty` stay pub as a clippy-
preferred pair.
* Replace the hand-rolled `retain_mut` (~7 unsafe blocks with a panic
partial-shift guard) with delegation to `Vec::retain_mut` via a
Vec::from_raw_parts round-trip. retain_mut is cold relative to push
so the round-trip cost is irrelevant.
* Replace the hand-rolled owned `IntoIter` (custom struct + Iterator,
Drop, ExactSizeIterator impls) with delegation to `std::vec::IntoIter`
via the same Vec round-trip. Drops ~50 lines of unsafe.
* Drop `Extend` and `FromIterator` trait impls entirely — no external
callers. Replace with inherent `extend_exact` which requires an
`ExactSizeIterator` and reserves exactly once.
* Drop inherent `iter`, `iter_mut`, `last_mut`, `Index`, `IndexMut`
impls — all reachable through `Deref<Target = [T]>` to the slice's
methods. `for x in &tv` / `for x in &mut tv` still need `IntoIterator`
impls for refs because the `for`-loop desugar doesn't apply `Deref`
coercion across the reference boundary.
* Add a `const MAX: u8` generic parameter that strictly caps push count
and tightens the growth schedule (doubles until it would exceed MAX,
then caps exactly at MAX). Default is `u8::MAX = 255` for backward
compatibility; the schema macro emits `TinyVec<LazyField, N>` where N
is the exact lazy-field count. A compile-time static assert rejects
`MAX = 0` at monomorphization.
* Add 3 const-generic tests (tight_max_caps_growth_exactly,
tight_max_panics_at_limit, tight_max_growth_schedule) and 6
retain_mut tests (basic, can_mutate, empty, keeps_all, removes_all,
panic_safety, element_drop_panic).
Net effect: unsafe blocks went from ~19 (in the original hand-rolled
version) to 5 in the hot path plus 1 in retain_mut and 1 in IntoIter
— each upholding a single local invariant or just round-tripping
through Vec.1 parent d772e48 commit 42ece5a
6 files changed
Lines changed: 299 additions & 261 deletions
File tree
- turbopack/crates
- turbo-tasks-backend/src
- backend/operation
- turbo-tasks-macros/src/derive
- turbo-tasks
- benches
- src
Lines changed: 0 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
176 | 176 | | |
177 | 177 | | |
178 | 178 | | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | 179 | | |
184 | 180 | | |
185 | 181 | | |
| |||
Lines changed: 0 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
138 | 138 | | |
139 | 139 | | |
140 | 140 | | |
141 | | - | |
142 | | - | |
143 | 141 | | |
144 | 142 | | |
145 | 143 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | 88 | | |
95 | 89 | | |
96 | 90 | | |
| |||
Lines changed: 18 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1296 | 1296 | | |
1297 | 1297 | | |
1298 | 1298 | | |
1299 | | - | |
1300 | | - | |
1301 | 1299 | | |
| 1300 | + | |
| 1301 | + | |
| 1302 | + | |
| 1303 | + | |
| 1304 | + | |
| 1305 | + | |
| 1306 | + | |
| 1307 | + | |
| 1308 | + | |
| 1309 | + | |
| 1310 | + | |
1302 | 1311 | | |
1303 | 1312 | | |
1304 | | - | |
| 1313 | + | |
1305 | 1314 | | |
1306 | 1315 | | |
1307 | 1316 | | |
| |||
3686 | 3695 | | |
3687 | 3696 | | |
3688 | 3697 | | |
3689 | | - | |
3690 | | - | |
3691 | | - | |
3692 | | - | |
| 3698 | + | |
| 3699 | + | |
| 3700 | + | |
| 3701 | + | |
3693 | 3702 | | |
3694 | 3703 | | |
3695 | 3704 | | |
| |||
3746 | 3755 | | |
3747 | 3756 | | |
3748 | 3757 | | |
3749 | | - | |
| 3758 | + | |
3750 | 3759 | | |
3751 | 3760 | | |
3752 | 3761 | | |
| |||
3770 | 3779 | | |
3771 | 3780 | | |
3772 | 3781 | | |
3773 | | - | |
| 3782 | + | |
3774 | 3783 | | |
3775 | 3784 | | |
3776 | 3785 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
| 48 | + | |
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| |||
0 commit comments