Skip to content

Start supporting 64-bit memories in wit-component - #2805

Merged
alexcrichton merged 1 commit into
bytecodealliance:mainfrom
alexcrichton:cm64-wit-component
Nov 3, 2026
Merged

alexcrichton merged 1 commit into
bytecodealliance:mainfrom
alexcrichton:cm64-wit-component

Conversation

@alexcrichton

Copy link
Copy Markdown
Member

This commit is a start to support the cm64 feature in wit-component itself. This is intended to start plumbing necessary knobs, variables, etc, to be able to produce a component when the linear memory uses a 64-bit index type instead of today's 32-bit index type. No output from today is expected to change, but modules using a 64-bit linear memory are intended to, in theory "just start working" with this.

Note that this is not yet fully complete. The goal of this commit is to set up a lot of the initial plumbing for index types but there are a few notable exceptions to supporting this:

  1. Exported functions taking a borrow<T> which is owned by the component itself do not work correctly. These incorrectly are expected to take i32 instead of the resource's rep field, in this case i64. Part of this is Fix handling of non-i32 resource reps #2804 where wasmparser's validation needs to be updated, but part of this is that larger wit-parser changes are going to be necessary since it's not as simple to produce the core wasm signature of a WIT function any more. Overall this is untested at this time and deferred to a future change.

  2. The wasm-tools component link command does not yet work. That stage still only supports 32-bit modules and 64-bit modules is entirely unsupported. That's intended to come as a future change as well.

  3. The wasm-tools component embed --dummy subcommand only supports 32-bit memories so far and doesn't support 64-bit just yet.

The general intent here is to fill out the "easy" part of memory64 support to move the needle a bit on supporting it. Wasmtime does not yet support this, for example, but that doesn't meant that tooling shouldn't. In theory this should make the next sufficiently-motivated individual to work on cm64 have a little less work to do.

One final notable part of this PR is that this removes the interim names added for some intrinsics in initial cm64 support. Specifically the support added in #2502 and #2514 is removed where the types required and involved are inferred and don't need explicit annotation in the import name itself. This is intended to make bindings easier to generate (just need the types to be right, not the names), and it's expected that no existing generator is relying on these names just yet.

This commit is a start to support the `cm64` feature in wit-component
itself. This is intended to start plumbing necessary knobs, variables,
etc, to be able to produce a component when the linear memory uses a
64-bit index type instead of today's 32-bit index type. No output from
today is expected to change, but modules using a 64-bit linear memory
are intended to, in theory "just start working" with this.

Note that this is not yet fully complete. The goal of this commit is to
set up a lot of the initial plumbing for index types but there are a few
notable exceptions to supporting this:

1. Exported functions taking a `borrow<T>` which is owned by the
   component itself do not work correctly. These incorrectly are
   expected to take `i32` instead of the resource's `rep` field, in this
   case `i64`. Part of this is bytecodealliance#2804 where `wasmparser`'s validation
   needs to be updated, but part of this is that larger `wit-parser`
   changes are going to be necessary since it's not as simple to produce
   the core wasm signature of a WIT function any more. Overall this is
   untested at this time and deferred to a future change.

2. The `wasm-tools component link` command does not yet work. That stage
   still only supports 32-bit modules and 64-bit modules is entirely
   unsupported. That's intended to come as a future change as well.

3. The `wasm-tools component embed --dummy` subcommand only supports
   32-bit memories so far and doesn't support 64-bit just yet.

The general intent here is to fill out the "easy" part of memory64
support to move the needle a bit on supporting it. Wasmtime does not yet
support this, for example, but that doesn't meant that tooling
shouldn't. In theory this should make the next sufficiently-motivated
individual to work on cm64 have a little less work to do.

One final notable part of this PR is that this removes the interim names
added for some intrinsics in initial cm64 support. Specifically the
support added in bytecodealliance#2502 and bytecodealliance#2514 is removed where the types required and
involved are inferred and don't need explicit annotation in the import
name itself. This is intended to make bindings easier to generate (just
need the types to be right, not the names), and it's expected that no
existing generator is relying on these names just yet.
@alexcrichton
alexcrichton requested a review from a team as a code owner November 2, 2026 21:53
@alexcrichton
alexcrichton requested review from dicej and removed request for a team November 2, 2026 21:53
if let Some(slot) = names.context_get(name) {
let slot_ty = match ty.results() {
[t] if is_i32_or_i64(*t) => *t,
_ => ValType::I32,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Under what circumstances would we hit the _ here (and for context.set, thread.new-indirect, etc. below)?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

That's there for invalid modules to have the erroneous part show up in an error message saying "expected [i32] found ...". Not the best of error messages, but in theory something to improve later too

@alexcrichton
alexcrichton added this pull request to the merge queue Nov 3, 2026
Merged via the queue into bytecodealliance:main with commit 02af0a8 Nov 3, 2026
37 checks passed
@alexcrichton
alexcrichton deleted the cm64-wit-component branch November 3, 2026 17:42
imikushin pushed a commit to imikushin/wasm-tools that referenced this pull request Nov 6, 2026
…ce#2807)

This commit builds on bytecodealliance#2804 and bytecodealliance#2805 to fix the first exception of
missing support outlined in bytecodealliance#2805. Notably `borrow<T>` is now correctly
handled when lowering and is converted to `WasmType::Pointer` rather
than most of the time being turned into `WasmType::I32`. This improved
support removes a previous hack that is now no longer necessary where
the first argument of methods was hardcoded as
`WasmType::Pointer`-overriding-`WasmType::I32`.

The fix in this commit is to pass a `world: WorldId` parameter into the
`wit-parser` crate where `borrow<T>` is lowered to its flat
representation. With the `world` on-hand it's possible to consult the
resource's owner and if it's exported from the world then the
representation is a `Pointer`, otherwise it's a normal `I32` handle.
Callers will now be required to thread through the `world` parameter
more deeply, and that's most of what this change is doing.
imikushin pushed a commit to imikushin/wasm-tools that referenced this pull request Nov 6, 2026
* Add initial cm64 support to `component link`

This commit goes through the `wasm-tools component link` subcommand and
generalizes locations that hardcoded a 32-bit pointer into an index type
using the infrastructure from bytecodealliance#2805. These resulting components are not
yet runnable but the intention is to at least be able to start building
valid components and going from there.

This additionally builds out some infrastructure to build a 32-bit and
64-bit libdl.so which are bundled in to get linked with `wit-component`.

* Update builds of libdl.so

* Update binaries again

* Re-bless tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants