next.js
6a733742 - Improve unsafe code safety documentation in turbo-tasks-backend (#90755)

Commit
48 days ago
Improve unsafe code safety documentation in turbo-tasks-backend (#90755) ### What? Improves safety documentation for all `unsafe` code in the `turbo-tasks-backend` crate (6 files, comment-only changes). ### Why? A comprehensive audit of all 14 files containing `unsafe` code in `turbo-tasks-backend` found **no soundness bugs**, but identified several safety comments that were incorrect, misleading, or missing entirely. Correct safety documentation is critical for maintaining unsafe code over time — reviewers and future contributors rely on these comments to understand invariants. ### How? **Fixes applied (comment-only, no behavior changes):** 1. **`backend/operation/mod.rs`** — Fixed transmute safety comment that referenced wrong lifetime names (`'a`/`'l` → `'e`/`'tx`) 2. **`database/read_transaction_cache.rs`** — Fixed reference to wrong struct name (`LmdbBackingStorage` → `ReadTransactionCache`); added struct-level doc explaining the field-ordering invariant required for drop safety 3. **`database/startup_cache.rs`** — Added struct-level doc explaining the self-referential pattern and field-ordering invariant; improved inline safety comment 4. **`utils/dash_map_multi.rs`** — Added safety justification for `unsafe impl Send/Sync` on `RefMut` explaining bucket pointer exclusivity 5. **`backing_storage.rs`** — Added `// Safety:` comments to 6 `unsafe` blocks in the `Either` impl that were missing them 6. **`kv_backing_storage.rs`** — Made the `flush()` safety comment more specific about what "finished processing" means **Audit summary (14 files reviewed):** | Risk | Category | Files | Verdict | |------|----------|-------|---------| | HIGH | Lifetime transmutation | 3 | Sound ✓ — comments fixed | | MEDIUM | DashMap raw bucket access | 3 | Sound ✓ — Send/Sync docs added | | LOW | Unsafe trait method contracts | 8 | Sound ✓ — missing comments added | | NEGLIGIBLE | Test code | 1 | No issues |
Author
Parents
Loading