diff --git a/Cargo.toml b/Cargo.toml index 7947a6a0f28..8e3c57ad20f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -82,3 +82,4 @@ members = [ [patch.crates-io] wasm-bindgen = { path = '.' } +parity-wasm = { git = 'https://github.com/alexcrichton/parity-wasm', branch = 'hash' } diff --git a/crates/gc/src/lib.rs b/crates/gc/src/lib.rs index 2dde3002b02..217289a0791 100644 --- a/crates/gc/src/lib.rs +++ b/crates/gc/src/lib.rs @@ -9,7 +9,7 @@ extern crate log; extern crate rustc_demangle; use std::mem; -use std::collections::HashSet; +use std::collections::{HashSet, HashMap}; use parity_wasm::elements::*; @@ -457,14 +457,20 @@ impl<'a> RemapContext<'a> { let mut memories = Vec::new(); if let Some(s) = m.type_section() { - let mut removed = 0; - for i in 0..(s.types().len() as u32) { - if analysis.types.contains(&i) { - types.push(i - removed); + let mut ntypes = 0; + let mut map = HashMap::new(); + for (i, ty) in s.types().iter().enumerate() { + if analysis.types.contains(&(i as u32)) { + if let Some(prev) = map.get(&ty) { + types.push(*prev); + continue + } + map.insert(ty, ntypes); + types.push(ntypes); + ntypes += 1; } else { debug!("gc type {}", i); types.push(u32::max_value()); - removed += 1; } } }