Skip to content

Fix non-determinism in the order of with remappings - #1737

Merged
alexcrichton merged 1 commit into
bytecodealliance:mainfrom
alexkirsz:alexk/with-stable-order
Oct 6, 2026
Merged

alexcrichton merged 1 commit into
bytecodealliance:mainfrom
alexkirsz:alexk/with-stable-order

Conversation

@alexkirsz

Copy link
Copy Markdown
Contributor

I stumbled upon several issues with non-determinism in our crates depending on the Temporal SDK, one of which led to this transitive dependency.

generate! parses with: { ... } into a HashMap and flattens it into a Vec, so the remappings come out in a non-deterministic order.

Repro:

wit/world.wit

package repro:demo@0.1.0;

interface types {
    record a { x: u32 }
    record b { x: u32 }
    record c { x: u32 }
    record d { x: u32 }
    record e { x: u32 }
}

world w {
    use types.{a, b, c, d, e};
    export f: func(a: a, b: b, c: c, d: d, e: e);
}

src/lib.rs

pub mod types {
    pub struct A { pub x: u32 }
    pub struct B { pub x: u32 }
    pub struct C { pub x: u32 }
    pub struct D { pub x: u32 }
    pub struct E { pub x: u32 }
}

pub mod bindings {
    wit_bindgen::generate!({
        path: "wit",
        world: "w",
        with: {
            "repro:demo/types@0.1.0/a": crate::types::A,
            "repro:demo/types@0.1.0/b": crate::types::B,
            "repro:demo/types@0.1.0/c": crate::types::C,
            "repro:demo/types@0.1.0/d": crate::types::D,
            "repro:demo/types@0.1.0/e": crate::types::E,
        },
    });
}
for i in 1 2 3 4 5 6; do
  touch src/lib.rs
  cargo build --release --lib -q
  ar p target/release/librepro.rlib lib.rmeta | shasum -a 256 | cut -c1-16
done

This will print different hashes.

@alexcrichton alexcrichton left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

@alexcrichton
alexcrichton added this pull request to the merge queue Oct 6, 2026
Merged via the queue into bytecodealliance:main with commit 687dbb8 Oct 6, 2026
29 checks passed
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