Skip to content

Generated WebAssembly unexpectedly requires reference types #128475

Closed
@PlasmaPower

Description

@PlasmaPower

Code

This can be replicated with a minimal test.rs:

fn main() {}

Compile it to WASM with rustc test.rs -o test.wasm --target wasm32-unknown-unknown

Then, check if the generated WASM uses reference types:

$ wasm-validate --disable-reference-types test.wasm
0000260: error: call_indirect reserved value must be 0

Version it worked on

It most recently worked on: nightly-2024-07-30 (and previous stable rust versions)

On those versions, compiling the above test.rs and then running wasm-validate with --disable-reference-types doesn't fail.

Version with regression

rustc --version --verbose:

rustc 1.82.0-nightly (28a58f2fa 2024-07-31)
binary: rustc
commit-hash: 28a58f2fa7f0c46b8fab8237c02471a915924fe5
commit-date: 2024-07-31
host: x86_64-unknown-linux-gnu
release: 1.82.0-nightly
LLVM version: 19.1.0

@rustbot modify labels: +regression-from-stable-to-nightly -regression-untriaged

This seems to have been caused by #127513

The compatibility note there says:

The WebAssembly target features multivalue and reference-types are now both enabled by default, but generated code is not affected by default

However, the generated code seems to be indeed affected by default. Interestingly, reference types seem to be used unnecessarily, as using wasm2wat to turn the generated test.wasm into wat and then wat2wasm to turn it back into wasm removes the reference types.

As-is, this breaks compatibility with the WebAssembly 1.0 spec.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.O-wasmTarget: WASM (WebAssembly), http://webassembly.org/P-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions