Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sorted_iter_mut for NonstandardWitSection.adapters for determinism #3851

Merged
merged 1 commit into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
* Add bindings for `CanvasState.reset()`, affecting `CanvasRenderingContext2D` and `OffscreenCanvasRenderingContext2D`.
[#3844](https://github.com/rustwasm/wasm-bindgen/pull/3844)

### Fixed

* Make .wasm output deterministic when using `--reference-types`.
[#3851](https://github.com/rustwasm/wasm-bindgen/pull/3851)

--------------------------------------------------------------------------------

## [0.2.91](https://github.com/rustwasm/wasm-bindgen/compare/0.2.90...0.2.91)
Expand Down
4 changes: 2 additions & 2 deletions crates/cli-support/src/externref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub fn process(module: &mut Module) -> Result<()> {

// Transform all exported functions in the module, using the bindings listed
// for each exported function.
for (id, adapter) in section.adapters.iter_mut() {
for (id, adapter) in crate::sorted_iter_mut(&mut section.adapters) {
let instructions = match &mut adapter.kind {
AdapterKind::Local { instructions } => instructions,
AdapterKind::Import { .. } => continue,
Expand Down Expand Up @@ -77,7 +77,7 @@ pub fn process(module: &mut Module) -> Result<()> {
// Additionally we may need to update some adapter instructions other than
// those found for the externref pass. These are some general "fringe support"
// things necessary to get absolutely everything working.
for (_, adapter) in section.adapters.iter_mut() {
for (_, adapter) in crate::sorted_iter_mut(&mut section.adapters) {
let instrs = match &mut adapter.kind {
AdapterKind::Local { instructions } => instructions,
AdapterKind::Import { .. } => continue,
Expand Down
10 changes: 10 additions & 0 deletions crates/cli-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -785,3 +785,13 @@ where
pairs.sort_by_key(|(k, _)| *k);
pairs.into_iter()
}

/// Like `sorted_iter`, but produces mutable references to the values
fn sorted_iter_mut<K, V>(map: &mut HashMap<K, V>) -> impl Iterator<Item = (&K, &mut V)>
where
K: Ord,
{
let mut pairs = map.iter_mut().collect::<Vec<_>>();
pairs.sort_by_key(|(k, _)| *k);
pairs.into_iter()
}
2 changes: 1 addition & 1 deletion crates/cli-support/src/multivalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub fn run(module: &mut Module) -> Result<(), Error> {
let mut to_xform = Vec::new();
let mut slots = Vec::new();

for (_, adapter) in adapters.adapters.iter_mut() {
for (_, adapter) in crate::sorted_iter_mut(&mut adapters.adapters) {
extract_xform(module, adapter, &mut to_xform, &mut slots);
}
if to_xform.is_empty() {
Expand Down
Loading