Skip to content

Conversation

posborne
Copy link
Collaborator

These changes pull in the cranelift changes from #10177 with some additional stacked changes to resolve conflicts, align with previous changes in the stack-switching series, and address feedback items which were raised on previous iterations of the PR (but mostly not changing anything of significant substance). Tracking Issue: #10248.

The stack-switching feature flag is retained and used minimally in this changeset in order to avoid compilation problems, but not really used beyond that. There is at least one item in the tracking issue already related to likely finding a way to drop these compilation flags in most places but I think it is worth deferring that here as it will required touching code more broadly.

CC @frank-emrich @dhil

frank-emrich and others added 7 commits June 10, 2025 16:17
This initial commit represents the "pr2" base commit with
minimal merge conflicts resolved.  Due to OOB conflicts, this
commit is not functional as-is, but using it as a base in
order to allow for easier reviewing of the delta from
this commit to what will be used for the PR against upstream.

Co-authored-by: Daniel Hillerström <[email protected]>
Co-authored-by: Paul Osborne <[email protected]>
This first set of changes updates the base pr in order to
compiled and pass basic checks (compile, clippy, fmt) with
the biggest part of the change being to eliminate injection
of tracing/assertions in JIT'ed code.
At this point, the only bit we really branch on is what we
do in order to avoid problems tying into wasmtime_environ.
This is basd on the approach and macro used by the gc code for
converting presence/absence of the cranelift feature flag to
cranelift compile time.  This is a bit of a half-measure for now
as we still compile most stack-switching code in cranelift, but
this does enough to avoid causing problems with missing definitions
in wasmtime_environ.
Replace either with infallible From or fallible, panicing
TryFrom alternatives where required.
After removing emission of runtime trace logging and assertions,
there were several unused parameters.  Remove those from the
ControlEffect signatures completely.
This matches a change to the mirrored runtime type in
the upstream changes.
@posborne posborne requested review from a team as code owners June 10, 2025 17:47
@posborne posborne requested review from alexcrichton and removed request for a team June 10, 2025 17:47
@fitzgen fitzgen requested review from fitzgen and removed request for alexcrichton June 10, 2025 18:13
@github-actions github-actions bot added cranelift Issues related to the Cranelift code generator cranelift:area:x64 Issues related to x64 codegen labels Jun 10, 2025
Copy link
Member

@fitzgen fitzgen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Lots of comments below but for the most part these should be pretty straightforward to fix.

posborne and others added 10 commits June 11, 2025 13:27
Co-authored-by: Daniel Hillerström <[email protected]>
The extra parameters here used to be used for emitting runtime
assertions, but with those gone we just had unused params
and lifetimes, clean those out.
There's already a stub elsewhere and this is not called, when
exceptions are added and it is time to revisit, this method
can be restored.
Rename VMHostArray -> VMHostArrayRef
Change impl to compute address with offset upfront rather than
on each load.
@posborne
Copy link
Collaborator Author

Pushed most of the updates but still need to make the suggested updates around the fat pointer stuff and resolve conflicts with upstream.

This matches the directory structure for gc and aids in visibility
for a few members required by stack-switching code in cranelift.
@posborne
Copy link
Collaborator Author

@fitzgen I did run the test changes now -- a subset of those tests are now failing as it looks like there are some codepaths hit due to upstream changes where we end up calling Val::null_top which currently panics for continuation types.

This type is not fully complete until continuation/gc integration
is revisited (bytecodealliance#10248) but without these changes, test cases are
now failing on panics as we need some representation of
continuation references in the runtime Val enumeration.

Runtime errors with TODO notes are added for the stubbed
code paths to revisit later.
@posborne posborne force-pushed the stack-switching-cranelift branch from 83b22a2 to 7d4e678 Compare August 27, 2025 22:51
@posborne
Copy link
Collaborator Author

@fitzgen I did run the test changes now -- a subset of those tests are now failing as it looks like there are some codepaths hit due to upstream changes where we end up calling Val::null_top which currently panics for continuation types.

To get tests going with the upstream stuff, I did end up adding a minimal Val::ContRef member which doesn't seem avoidable. I tried to keep this as small and I could bundle it with the test changes, but it does appear to be required in order to have ref.null globals for continuations and some other cases.

@github-actions github-actions bot added the wasmtime:ref-types Issues related to reference types and GC in Wasmtime label Aug 28, 2025
Copy link

Subscribe to Label Action

cc @fitzgen

This issue or pull request has been labeled: "cranelift", "cranelift:area:x64", "wasmtime:api", "wasmtime:ref-types"

Thus the following users have been cc'd because of the following labels:

  • fitzgen: wasmtime:ref-types

To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file.

Learn more.

@posborne posborne requested a review from a team as a code owner August 28, 2025 16:21
@posborne posborne requested review from alexcrichton and removed request for a team August 28, 2025 16:21
@github-actions github-actions bot added fuzzing Issues related to our fuzzing infrastructure wasmtime:c-api Issues pertaining to the C API. labels Aug 28, 2025
Copy link

Subscribe to Label Action

cc @fitzgen

This issue or pull request has been labeled: "fuzzing", "wasmtime:c-api"

Thus the following users have been cc'd because of the following labels:

  • fitzgen: fuzzing

To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file.

Learn more.

Copy link
Member

@fitzgen fitzgen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with the below addressed, thanks!

@posborne posborne enabled auto-merge August 28, 2025 20:09
@posborne posborne added this pull request to the merge queue Aug 28, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Aug 28, 2025
Disas tests were failing on i686 targeting x86_64 as the size of the
host pointer was leaking into what we were using to do codegen
in a few paths.  This patch is a bit of a hack as it seems like
using a generic <T> for T: *mut u8 (as an example) is a bit
questionable.  To keep things small, I do a hacky typecheck to map
pointers to the target pointer size here.
@posborne posborne force-pushed the stack-switching-cranelift branch from 7a29573 to ed4b010 Compare August 29, 2025 18:22
Comment on lines 307 to 319
// TODO: hack around host pointer size being mixed up with target
let (align, entry_size) =
if core::any::TypeId::of::<T>() == core::any::TypeId::of::<*mut u8>() {
(env.pointer_type().bytes() as u8, env.pointer_type().bytes())
} else {
(
u8::try_from(std::mem::align_of::<T>()).unwrap(),
u32::try_from(std::mem::size_of::<T>()).unwrap(),
)
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This stuff should be a method on the PtrSize trait that we define in vmoffsets.rs (maybe fn vm_host_array_layout(&self) -> (u8, u32)) and ultimately we should have access to that method here via env.offsets.ptr.

We should definitely avoid any kind of std::mem::{size,align}_of calls, as that ends up being pretty fragile (doesn't work for f64 across 32- and 64-bit architectures, for example, where the alignment is different despite size being the same).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To clarify a little more:

To avoid the std::mem::{size,align}_of calls, you may have to have different PtrSize methods for each concrete T that is used, and then bound T by T: HostArrayLayout and define

trait HostArrayLayout {
    fn host_array_layout<P: PtrSize>(p: &P) -> (u8, u32);
}

and implement that for each concreate T such that it calls the appropriate PtrSize method.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, I'll take a look at making changes to revise VMHostArray and any other problematic parts I can find (or see if @dhil can help out). I wanted to get a basic version of the commit up to get this kind of feedback as doing operations on the generic T here (from the original impl) seemed problematic for the reasons you describe.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 9343ab9 if my interpretation was correct.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

Revisiting the previous commit with an approach that should be
less brittle.
@posborne posborne requested a review from fitzgen September 4, 2025 19:54
@posborne posborne added this pull request to the merge queue Sep 4, 2025
Merged via the queue into bytecodealliance:main with commit a631d20 Sep 4, 2025
168 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cranelift:area:x64 Issues related to x64 codegen cranelift Issues related to the Cranelift code generator fuzzing Issues related to our fuzzing infrastructure wasmtime:api Related to the API of the `wasmtime` crate itself wasmtime:c-api Issues pertaining to the C API. wasmtime:ref-types Issues related to reference types and GC in Wasmtime

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants