umem: deny unsafe_op_in_unsafe_fn #94

Closed
github-bot wants to merge 1 commit from github-bot/gh-94 into main AGit
Owner

@⁠TheRifai on GitHub · 2026-12-01 13:14 UTC · original
TheRifai:umem-rustc-lints → main · +50 −33 · 5 files · 1 commits · closed without merging

What

umem now denies unsafe_op_in_unsafe_fn (docs/TASKS.md “The root workspace's rustc lints everywhere”, issue #41). The 17 unsafe operations that were implicitly allowed inside unsafe fn bodies are wrapped in explicit unsafe {} blocks, each with a // SAFETY: note naming the caller contract that makes it sound. The wraps were produced by cargo fix (scope-correct) and reviewed function by function; no caller or behaviour changed.

This is the first crate in greenfield to carry the lint; the workspace-wide switch can be turned on once the other crates' sites are wrapped the same way.

The reference

The root Cargo.toml already denies this lint for the primary workspace; this brings umem in line with it.

Evidence

  • cargo check -p umem --all-targets --locked and cargo check --workspace --all-targets --locked in greenfield/ are clean with the deny in place; tools/build.sh succeeds.
  • cargo test -p umem --lib --locked: 16 pass.

Checklist (docs/AGENTS.md)

  • One topic; docs/TASKS.md not edited (rule 29/31)
  • No fallback added (rule 33)
  • No constants or switches added (rules 2/9b)
  • No queues changed (rule 35)
  • Every new unsafe block has a // SAFETY: comment (rule 36)
  • Check, build and tests pass; no translator output change (rule 27)
  • Comments say what is true now (rule 3)
  • Nothing from the title, no non-free data pointers (hard constraints)
**@⁠TheRifai** on GitHub · 2026-12-01 13:14 UTC · [original](https://github.com/vktory6/VKtory/pull/94) `TheRifai:umem-rustc-lints` → `main` · +50 −33 · 5 files · 1 commits · closed without merging ## What `umem` now denies `unsafe_op_in_unsafe_fn` (docs/TASKS.md “The root workspace's rustc lints everywhere”, issue #41). The 17 unsafe operations that were implicitly allowed inside `unsafe fn` bodies are wrapped in explicit `unsafe {}` blocks, each with a `// SAFETY:` note naming the caller contract that makes it sound. The wraps were produced by `cargo fix` (scope-correct) and reviewed function by function; no caller or behaviour changed. This is the first crate in greenfield to carry the lint; the workspace-wide switch can be turned on once the other crates' sites are wrapped the same way. ## The reference The root Cargo.toml already denies this lint for the primary workspace; this brings umem in line with it. ## Evidence - `cargo check -p umem --all-targets --locked` and `cargo check --workspace --all-targets --locked` in `greenfield/` are clean with the deny in place; `tools/build.sh` succeeds. - `cargo test -p umem --lib --locked`: 16 pass. ## Checklist (docs/AGENTS.md) - [x] One topic; `docs/TASKS.md` not edited (rule 29/31) - [x] No fallback added (rule 33) - [x] No constants or switches added (rules 2/9b) - [x] No queues changed (rule 35) - [x] Every new `unsafe` block has a `// SAFETY:` comment (rule 36) - [x] Check, build and tests pass; no translator output change (rule 27) - [x] Comments say what is true now (rule 3) - [x] Nothing from the title, no non-free data pointers (hard constraints)
Add the root workspace's rustc lint to umem (docs/TASKS.md 'The root workspace's
rustc lints everywhere') and wrap the 17 operations in unsafe fn bodies with
explicit unsafe blocks and SAFETY notes. All umem callers keep their contracts;
cargo fix supplied scope-correct wraps and every block now names its reason.
Check, build and native tests pass.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 13:14:54 +00:00
github-bot closed this pull request 2026-12-01 13:20:07 +00:00
Author
Owner

@⁠TheRifai on GitHub · 2026-12-01 13:19 UTC · original

Superseded by a workspace-wide lint PR that also covers frame, vkback, the wine crates and xtask's lint-table check.

**@⁠TheRifai** on GitHub · 2026-12-01 13:19 UTC · [original](https://github.com/vktory6/VKtory/pull/94#issuecomment-7312437818) Superseded by a workspace-wide lint PR that also covers frame, vkback, the wine crates and xtask's lint-table check.
Author
Owner

@⁠vktory6 on GitHub · 2026-12-01 13:20 UTC · original

Thanks, the lint is wanted (#41), but this version can't go in as it is, and maintainer edits are off here so I can't adjust it myself.

The problem is the shape cargo fix produces: it wraps each whole function body in one unsafe { … }. That is the same as before the lint. Its point is that every unsafe operation inside an unsafe fn gets its own block and its own reason, so a reader sees exactly which calls are unsafe and why each is fine.

What would make it mergeable (rule 36):

  1. Narrow blocks: one unsafe { } around each unsafe operation (the FFI call, the pointer read, the mmap), not around the body.
  2. // SAFETY: at each block, saying why that operation is sound at that point (e.g. "p..p+len was checked against the chunk's extent above").
  3. The caller's contract as a /// # Safety doc section on the unsafe fn, where the current comments are trying to say it. Right now one sits between two parameters of the debug callback, and destroy has none.
  4. Only claims you checked. Several notes say things like "the caller holds State's lock" or "no submission uses the chunk". If that's true, name what guarantees it (the guard type, the function that waits for the timeline); if you're not sure, say "not proven: …" instead. A SAFETY comment that hasn't been checked is worse than none, because it makes the code look audited.

Doing umem first and the other crates later is fine.

**@⁠vktory6** on GitHub · 2026-12-01 13:20 UTC · [original](https://github.com/vktory6/VKtory/pull/94#issuecomment-7312468626) Thanks, the lint is wanted (#41), but this version can't go in as it is, and maintainer edits are off here so I can't adjust it myself. The problem is the shape `cargo fix` produces: it wraps each whole function body in one `unsafe { … }`. That is the same as before the lint. Its point is that every unsafe operation inside an `unsafe fn` gets its own block and its own reason, so a reader sees exactly which calls are unsafe and why each is fine. What would make it mergeable (rule 36): 1. **Narrow blocks:** one `unsafe { }` around each unsafe operation (the FFI call, the pointer read, the `mmap`), not around the body. 2. **`// SAFETY:` at each block**, saying why *that* operation is sound at that point (e.g. "`p..p+len` was checked against the chunk's extent above"). 3. **The caller's contract as a `/// # Safety` doc section** on the `unsafe fn`, where the current comments are trying to say it. Right now one sits between two parameters of the debug callback, and `destroy` has none. 4. **Only claims you checked.** Several notes say things like "the caller holds `State`'s lock" or "no submission uses the chunk". If that's true, name what guarantees it (the guard type, the function that waits for the timeline); if you're not sure, say "not proven: …" instead. A SAFETY comment that hasn't been checked is worse than none, because it makes the code look audited. Doing umem first and the other crates later is fine.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.