mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-03-16 02:00:51 +00:00
Fix a bug in coalescing types with GC
When a duplicate type is found is should no longer be considered used!
This commit is contained in:
parent
31c11f0781
commit
40b68c66d9
@ -172,7 +172,7 @@ matrix:
|
||||
install:
|
||||
- git clone https://github.com/WebAssembly/wabt
|
||||
- mkdir -p wabt/build
|
||||
- (cd wabt/wabt && cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=sccache -DCMAKE_CXX_COMPILER_ARG1=c++ && cmake --build . -- -j4)
|
||||
- (cd wabt/build && cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=sccache -DCMAKE_CXX_COMPILER_ARG1=c++ -DBUILD_TESTS=OFF && cmake --build . -- -j4)
|
||||
- export PATH=$PATH:`pwd`/wabt/build
|
||||
script: cargo test -p wasm-bindgen-gc
|
||||
if: branch = master
|
||||
|
@ -29,6 +29,15 @@ impl BitSet {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn remove(&mut self, i: &u32) {
|
||||
let i = *i as usize;
|
||||
let idx = i / BITS;
|
||||
let bit = 1 << (i % BITS);
|
||||
if let Some(slot) = self.bits.get_mut(idx) {
|
||||
*slot &= !bit;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn contains(&self, i: &u32) -> bool {
|
||||
let i = *i as usize;
|
||||
let idx = i / BITS;
|
||||
|
@ -51,7 +51,7 @@ impl Config {
|
||||
}
|
||||
|
||||
fn run(config: &mut Config, module: &mut Module) {
|
||||
let analysis = {
|
||||
let mut analysis = {
|
||||
let mut cx = LiveContext::new(&module);
|
||||
cx.blacklist.insert("rust_eh_personality");
|
||||
cx.blacklist.insert("__indirect_function_table");
|
||||
@ -80,7 +80,7 @@ fn run(config: &mut Config, module: &mut Module) {
|
||||
cx.analysis
|
||||
};
|
||||
|
||||
let cx = RemapContext::new(&module, &analysis, config);
|
||||
let cx = RemapContext::new(&module, &mut analysis, config);
|
||||
for i in (0..module.sections().len()).rev() {
|
||||
let retain = match module.sections_mut()[i] {
|
||||
Section::Unparsed { .. } => {
|
||||
@ -476,7 +476,7 @@ struct RemapContext<'a> {
|
||||
}
|
||||
|
||||
impl<'a> RemapContext<'a> {
|
||||
fn new(m: &Module, analysis: &'a Analysis, config: &'a Config) -> RemapContext<'a> {
|
||||
fn new(m: &Module, analysis: &'a mut Analysis, config: &'a Config) -> RemapContext<'a> {
|
||||
let mut nfunctions = 0;
|
||||
let mut functions = Vec::new();
|
||||
let mut nglobals = 0;
|
||||
@ -494,6 +494,7 @@ impl<'a> RemapContext<'a> {
|
||||
if analysis.types.contains(&(i as u32)) {
|
||||
if let Some(prev) = map.get(&ty) {
|
||||
types.push(*prev);
|
||||
analysis.types.remove(&(i as u32));
|
||||
continue
|
||||
}
|
||||
map.insert(ty, ntypes);
|
||||
|
34
crates/gc/tests/wat/remove-unused-type.wat
Normal file
34
crates/gc/tests/wat/remove-unused-type.wat
Normal file
@ -0,0 +1,34 @@
|
||||
(module
|
||||
(type (func))
|
||||
(type (func (param i32)))
|
||||
(type (func (param i32)))
|
||||
(type (func (result i32)))
|
||||
|
||||
(func $f1 (type 0))
|
||||
(func $f2 (type 1))
|
||||
(func $f3 (type 2))
|
||||
(func $f4 (type 3)
|
||||
i32.const 0
|
||||
)
|
||||
|
||||
(export "a" (func $f1))
|
||||
(export "b" (func $f2))
|
||||
(export "c" (func $f3))
|
||||
(export "d" (func $f4))
|
||||
)
|
||||
|
||||
;; STDOUT (update this section with `BLESS_TESTS=1` while running tests)
|
||||
;; (module
|
||||
;; (type (;0;) (func))
|
||||
;; (type (;1;) (func (param i32)))
|
||||
;; (type (;2;) (func (result i32)))
|
||||
;; (func $f1 (type 0))
|
||||
;; (func $f2 (type 1) (param i32))
|
||||
;; (func $f3 (type 1) (param i32))
|
||||
;; (func $f4 (type 2) (result i32)
|
||||
;; i32.const 0)
|
||||
;; (export "a" (func $f1))
|
||||
;; (export "b" (func $f2))
|
||||
;; (export "c" (func $f3))
|
||||
;; (export "d" (func $f4)))
|
||||
;; STDOUT
|
Loading…
x
Reference in New Issue
Block a user