Skip to content

RustGlue: generated alignment assert for RocDec fails on wasm32 (Rust aligns u128 to 8) #6

Description

@ESRogs

Summary

The Rust glue generator emits a compile-time alignment assertion that is wrong on wasm32, so generated glue fails to compile for anyone who has a Rust wasm32 target installed.

src/glue/src/RustGlue.roc:916 emits:

const _: [(); 16] = [(); core::mem::align_of::<RocDec>()];

RocDec is backed by i128/u128. On x86_64 and aarch64, Rust aligns 128-bit integers to 16, so the assert holds. On wasm32, Rust aligns them to 8, making the const evaluate to [(); 8], which fails to unify with the annotated [(); 16] — a compile error in every generated glue crate that touches RocDec.

Impact

Five RustGlue test failures when running the glue test suite on a machine with a Rust wasm32 target installed (observed 2026-07-11 on macOS aarch64). The failures are masked on machines without the wasm32 target — which is presumably why CI hasn't caught it — and appeared locally immediately after installing the target.

Repro

  1. rustup target add wasm32-unknown-unknown (any Rust wasm32 target)
  2. Run the RustGlue test suite
  3. The wasm32 glue compilations fail on the RocDec alignment assert

Suggested fix

Emit the expected alignment target-conditionally, e.g.:

#[cfg(target_arch = "wasm32")]
const _: [(); 8] = [(); core::mem::align_of::<RocDec>()];
#[cfg(not(target_arch = "wasm32"))]
const _: [(); 16] = [(); core::mem::align_of::<RocDec>()];

— or derive the constant from the target the glue is being generated for. Note this is not only an assert problem: if the Roc side assumes 16-byte alignment for RocDec on wasm32 while Rust structs assume 8, actual layout mismatches are possible in records containing RocDec; the assert is doing its job by failing, and the layout question deserves a look at the same time.


Staged in this fork for review before filing upstream (roc-lang/roc).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions