b84330808 opened PR #15159 from b84330808:entity-forbid-unsafe to bytecodealliance:main:
cranelift-entity had two
unsafeblocks left, and neither needs to be unsafe.
PrimaryMap::into_boxed_sliceturned the backingBoxinto a raw pointer and rebuilt aBoxedSlicewithfrom_raw. It now constructs theBoxedSlicedirectly, andfrom_rawis removed since nothing else used it.
get_raw_mutalready bounds-checks the index before the pointer arithmetic;wrapping_addandaddproduce the same pointer here. On x86-64 release builds the generated assembly is identical except that the GEP losesinbounds nuw. This function currently has no callers in the tree, so if you would rather see it deleted than kept, I am happy to do that instead.With both gone, the crate now carries
#![forbid(unsafe_code)].Testing:
cargo test -p cranelift-entitypasses (60 unit tests, 2 doc-tests) and Miri is clean.
b84330808 removed the review request for wasmtime-compiler-reviewers from PR #15159.
b84330808 requested wasmtime-compiler-reviewers for a review on PR #15159.
b84330808 requested cfallin for a review on PR #15159.
github-actions[bot] added the label cranelift on PR #15159.
:memo: bjorn3 submitted PR review.
:speech_balloon: bjorn3 created PR review comment:
This would likely cause LLVM to do a worse job at optimizing as the result of
wrapping_addis not known to be in-bounds. And if theaddwas UB, the user would end up with UB anyway when dereferencing this pointer.
:memo: bjorn3 submitted PR review.
:speech_balloon: bjorn3 created PR review comment:
Is this method actually used anywhere?
b84330808 updated PR #15159.
b84330808 requested wasmtime-core-reviewers for a review on PR #15159.
:memo: b84330808 submitted PR review.
:speech_balloon: b84330808 created PR review comment:
You're right — and it turns out nothing calls it. I grepped the whole workspace: the only references were its own unit test and the
TryPrimaryMap::get_raw_mutwrapper in wasmtime-environ, which also has no callers. I've removed both (and the test) in a follow-up commit, so thewrapping_addis gone entirely andforbid(unsafe_code)no longer depends on it.cargo test -p cranelift-entityandcargo check -p wasmtime-environpass.
:speech_balloon: b84330808 created PR review comment:
It isn't. The only callers in the workspace were the
BoxedSlicetests in this crate; every otherinto_boxed_slicehit is theVec/TryVecmethod on unrelated types. I've removedPrimaryMap::into_boxed_slice, and the tests now build the slice directly through thepub(crate)BoxedSlice::new.That leaves
BoxedSliceitself with no users and no way to construct one from outside the crate. Do you want me to removeBoxedSliceentirely in this PR as well, or keep it?
:memo: b84330808 submitted PR review.
b84330808 edited PR #15159:
cranelift-entity had two
unsafeblocks left, and neither needs to be unsafe.
PrimaryMap::into_boxed_sliceturned the backingBoxinto a raw pointer and rebuilt aBoxedSlicewithfrom_raw. It now constructs theBoxedSlicedirectly, andfrom_rawis removed since nothing else used it.With both gone, the crate now carries
#![forbid(unsafe_code)].Update per review:
get_raw_mutandinto_boxed_sliceturned out to have no callers anywhere in the workspace —get_raw_mutwas referenced only by its own unit test and theTryPrimaryMap::get_raw_mutwrapper in wasmtime-environ (itself unused), andinto_boxed_sliceonly by theBoxedSlicetests in this crate. Both methods are therefore removed instead of rewritten, and thewrapping_addfrom the first version is gone withget_raw_mut. TheBoxedSlicetests now construct the slice directly through thepub(crate)constructor.Testing:
cargo test -p cranelift-entitypasses (59 unit tests, 2 doc-tests) andcargo check -p wasmtime-environpasses.
:memo: fitzgen submitted PR review:
Is there some specific motivation here? I feel like this PR is missing context. I don't think we necessarily want to
forbid(unsafe_code), there are valid reasons we might want to useunsafein this crate in the future.
b84330808 updated PR #15159.
Last updated: Nov 19 2026 at 20:05 UTC