b84330808 edited PR #15159:
This removes two methods in
cranelift-entitywhoseunsafecode has no callers left in the workspace:
PrimaryMap::get_raw_mut— only referenced by its own unit test and by an equally unused wrapper inwasmtime-environ(TryPrimaryMap::get_raw_mut); both are removed. This also addresses bjorn3's point on the earlier revision: thewrapping_addthere had no in-bounds guarantee to lean on, so the sound thing is for the method not to exist.PrimaryMap::into_boxed_slice— only used by theBoxedSlicetests; they now constructBoxedSlicedirectly through itspub(crate)constructor.Motivation: reducing the
unsafesurface where the code is dead anyway. There is no bug behind this — the methods were not called, they just carriedunsafecontracts for no benefit. This kind of unsafe-reduction is also the class of change covered by Google's Patch Rewards program for OSS-Fuzz projects (Tier 2 hardening), which is part of why I went looking for it.An earlier version of this PR also added
#![forbid(unsafe_code)]to the crate; I removed that again after fitzgen's review, since the crate may legitimately wantunsafein the future.Testing:
cargo test -p cranelift-entity— 59 unit tests and 2 doc tests pass;cargo check -p wasmtime-environpasses.Open question from the review thread:
BoxedSliceitself now has no users and cannot be constructed from outside the crate. I'm happy to remove it in this PR too if the maintainers want that.
b84330808 commented on PR #15159:
Fair question, and sorry for the missing context — I should have written this in the description from the start.
The motivation is honestly pretty modest. I've been looking for places where
unsafecan be removed outright rather than justified, and in this crate the only two remaining pieces ofunsafeturned out to be methods with no callers:get_raw_mutandPrimaryMap::into_boxed_slice. There's no bug behind it — nothing crashed and nobody hit theget_raw_mutcontract in practice; it was dead code carrying an unsafe API for no benefit. For background, this kind of unsafe-reduction is also what Google's Patch Rewards program covers for OSS-Fuzz projects (Tier 2 hardening), which is part of why I went looking — but I'm not attached to landing this for that reason, and if the change isn't useful to you it shouldn't stay open just for that.On
forbid(unsafe_code): you're right, and I don't want to lock the crate against future legitimate uses ofunsafe. I've pushed a commit (47f59e9) that drops the#![forbid(unsafe_code)]attribute, so what's left is only the removal of the two unused methods, which bjorn3 already reviewed above. TheBoxedSlicequestion I asked bjorn3 in the thread is still open — happy to fold that removal in here or leave the type in place, whichever you both prefer.If even the trimmed-down version isn't something you want, please feel free to close this — no hard feelings.
fitzgen commented on PR #15159:
@b84330808 can you clarify whether your interactions here are abiding by the project's AI policy?
b84330808 commented on PR #15159:
Yes, happy to clarify. I'm directing this work myself and I review what goes in before anything is submitted. AI tools are part of my process, but there is no unattended agent acting here — the changes, the description and these replies are mine to answer for, and I can walk through the diff if that's useful (it's a small one: two methods with no callers in the workspace, plus their tests). The missing motivation up front was my oversight; the description has it now.
I also took your point on
forbid(unsafe_code)and dropped that part — the PR is just the dead-code removal at this point. If you still judge it not worth the review time, I understand closing it.
:thumbs_up: cfallin submitted PR review:
The DCE seems fine to me; this is very old code that probably was written as a generic data structure library before most of Cranelift+Wasmtime grew up around it and solidified our usage patterns.
Agreed with Nick that we don't want to forbid unsafe code; passively reducing it (if free) is always great though.
Just one nit below re: formatting. Thanks!
:speech_balloon: cfallin created PR review comment:
stray blank line inserted here?
:memo: b84330808 submitted PR review.
:speech_balloon: b84330808 created PR review comment:
Fixed in 860dab5f2d3c2b9ca5370db7bdf56f8c9840688a — thanks, that was left over from removing the test.
b84330808 updated PR #15159.
b84330808 updated PR #15159.
:memo: b84330808 submitted PR review.
:speech_balloon: b84330808 created PR review comment:
Also ran rustfmt over the crate and fixed a second stray blank line of the same kind at the end of the impl block (e52e0eb). The crate is rustfmt-clean now.
b84330808 updated PR #15159.
:memo: b84330808 submitted PR review.
:speech_balloon: b84330808 created PR review comment:
Went ahead with this: BoxedSlice is removed entirely in 7ddf5284191699ae98c59a8a69ba552b663b2a5d. After into_boxed_slice was deleted, BoxedSlice::new had no callers left, and CI (which builds with -D warnings) failed on the dead code, cascading into the dependent check and test jobs, so keeping the type was not viable. Locally, cargo check -p cranelift-entity --all-targets with -D warnings is clean, the tests pass (52 + 2; the seven dropped tests were BoxedSlice's own), and the crate is rustfmt-clean. Happy to restore the type if you would rather keep it.
cfallin commented on PR #15159:
Thanks; it looks like you have another rustfmt error with another stray line.
b84330808 updated PR #15159.
b84330808 commented on PR #15159:
Fixed in b33ef57f57ec4503cf873f2c90aa75d62cd97223 — you were right, there was one more. It was in
crates/environ/src/collections/primary_map.rs: a stray blank line before the closing brace of theTryPrimaryMapimpl, left over from removingget_raw_mut. My earlier rustfmt pass only covered the cranelift-entity crate, which is how I missed this one. I've now runrustfmt --checkover every file this PR touches; they are clean.
cfallin has enabled auto merge for PR #15159.
cfallin added PR #15159 cranelift-entity: remove unused get_raw_mut and into_boxed_slice to the merge queue
:check: cfallin merged PR #15159.
cfallin removed PR #15159 cranelift-entity: remove unused get_raw_mut and into_boxed_slice from the merge queue
Last updated: Nov 19 2026 at 20:05 UTC