next.js
70fc4293 - turbo-tasks: tighten TaskStorage Drop, iteration, and insert paths

Commit
66 days ago
turbo-tasks: tighten TaskStorage Drop, iteration, and insert paths - Promote head alignment / size / TAIL_BUFFER_ALIGN checks from `debug_assert!` in `layout()` to compile-time `const _: () = assert!` so misalignment fails the build instead of being missed in release. - Replace `from_size_align_unchecked` with the checked variant + a proof-of-validity message; size+align bounds (u16 cap, power-of-two align) make the check trivially satisfied. - Snapshot `cap` before `drop_in_place` in `TaskStorage::drop` so the dealloc layout never has to read through a dropped value; drop the redundant `present`/`len` reset (auto-derived `LazyTail` drop is a no-op so nothing re-interprets the bytes). - Add explicit no-op `Drop` impl on `LazyTail` documenting that payload + buffer lifecycle is owned by `TaskStorage`. - Add `LazyTail::try_for_each_present` / `for_each_present` as the single iteration primitive for the bitmap walk. Encapsulates `sum_padded_sizes` (now private) and accumulates offsets across iterations, dropping the walk from O(popcount²) to O(popcount). Three call sites updated: `Drop`, `Debug::fmt`, `all_lazy_in_mask_empty`. - `insert_unchecked` returns `&mut T`; `lazy_get_or_create` uses it to skip the second `lazy_find_mut` lookup. - Compute `above_bytes` in `insert_unchecked` and `take` as `self.len - offset[ - payload_size]` rather than a second `sum_padded_sizes` walk over `mask_above`. - Factor `offset_for(tag)` out of `offset_of` so the unconditional offset math has one home. - Add `lazy_insert_shifts_existing_payloads` test exercising insert-side and take-side byte shifts across three direct lazy fields with distinct types.
Author
Committer
Parents
Loading