Stream: git-wasmtime

Topic: wasmtime / PR #15159 cranelift-entity: remove the remaini...


view this post on Zulip Wasmtime GitHub notifications bot (Nov 05 2026 at 07:37):

b84330808 opened PR #15159 from b84330808:entity-forbid-unsafe to bytecodealliance:main:

cranelift-entity had two unsafe blocks left, and neither needs to be unsafe.

PrimaryMap::into_boxed_slice turned the backing Box into a raw pointer and rebuilt a BoxedSlice with from_raw. It now constructs the BoxedSlice directly, and from_raw is removed since nothing else used it.

get_raw_mut already bounds-checks the index before the pointer arithmetic; wrapping_add and add produce the same pointer here. On x86-64 release builds the generated assembly is identical except that the GEP loses inbounds 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-entity passes (60 unit tests, 2 doc-tests) and Miri is clean.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 05 2026 at 07:37):

b84330808 removed the review request for wasmtime-compiler-reviewers from PR #15159.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 05 2026 at 07:37):

b84330808 requested wasmtime-compiler-reviewers for a review on PR #15159.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 05 2026 at 07:37):

b84330808 requested cfallin for a review on PR #15159.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 05 2026 at 09:44):

github-actions[bot] added the label cranelift on PR #15159.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 05 2026 at 10:09):

:memo: bjorn3 submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 05 2026 at 10:09):

:speech_balloon: bjorn3 created PR review comment:

This would likely cause LLVM to do a worse job at optimizing as the result of wrapping_add is not known to be in-bounds. And if the add was UB, the user would end up with UB anyway when dereferencing this pointer.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 05 2026 at 10:12):

:memo: bjorn3 submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 05 2026 at 10:12):

:speech_balloon: bjorn3 created PR review comment:

Is this method actually used anywhere?

view this post on Zulip Wasmtime GitHub notifications bot (Nov 05 2026 at 10:22):

b84330808 updated PR #15159.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 05 2026 at 10:22):

b84330808 requested wasmtime-core-reviewers for a review on PR #15159.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 05 2026 at 10:22):

:memo: b84330808 submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 05 2026 at 10:22):

: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_mut wrapper in wasmtime-environ, which also has no callers. I've removed both (and the test) in a follow-up commit, so the wrapping_add is gone entirely and forbid(unsafe_code) no longer depends on it. cargo test -p cranelift-entity and cargo check -p wasmtime-environ pass.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 05 2026 at 10:22):

:speech_balloon: b84330808 created PR review comment:

It isn't. The only callers in the workspace were the BoxedSlice tests in this crate; every other into_boxed_slice hit is the Vec/TryVec method on unrelated types. I've removed PrimaryMap::into_boxed_slice, and the tests now build the slice directly through the pub(crate) BoxedSlice::new.

That leaves BoxedSlice itself with no users and no way to construct one from outside the crate. Do you want me to remove BoxedSlice entirely in this PR as well, or keep it?

view this post on Zulip Wasmtime GitHub notifications bot (Nov 05 2026 at 10:22):

:memo: b84330808 submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 05 2026 at 10:22):

b84330808 edited PR #15159:

cranelift-entity had two unsafe blocks left, and neither needs to be unsafe.

PrimaryMap::into_boxed_slice turned the backing Box into a raw pointer and rebuilt a BoxedSlice with from_raw. It now constructs the BoxedSlice directly, and from_raw is removed since nothing else used it.

With both gone, the crate now carries #![forbid(unsafe_code)].

Update per review: get_raw_mut and into_boxed_slice turned out to have no callers anywhere in the workspace — get_raw_mut was referenced only by its own unit test and the TryPrimaryMap::get_raw_mut wrapper in wasmtime-environ (itself unused), and into_boxed_slice only by the BoxedSlice tests in this crate. Both methods are therefore removed instead of rewritten, and the wrapping_add from the first version is gone with get_raw_mut. The BoxedSlice tests now construct the slice directly through the pub(crate) constructor.

Testing: cargo test -p cranelift-entity passes (59 unit tests, 2 doc-tests) and cargo check -p wasmtime-environ passes.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 05 2026 at 14:38):

: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 use unsafe in this crate in the future.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 05 2026 at 14:48):

b84330808 updated PR #15159.


Last updated: Nov 19 2026 at 20:05 UTC