Skip to content

Commit

Permalink
Merge pull request #1606 from alexcrichton/gc-elss
Browse files Browse the repository at this point in the history
Preserve the function table during early gc passes
  • Loading branch information
alexcrichton committed Jun 19, 2019
2 parents 8d90655 + c9ee88b commit e7902f3
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions crates/cli-support/src/descriptors.rs
Expand Up @@ -40,7 +40,24 @@ pub fn execute(module: &mut Module) -> Result<WasmBindgenDescriptorsSectionId, E

// Delete all descriptor functions and imports from the module now that
// we've executed all of them.
//
// Note though that during this GC pass it's a bit aggressive in that it can
// delete the function table entirely. We don't actually know at this point
// whether we need the function table or not. The bindings generation may
// need to export the table so the JS glue can call functions in it, and
// that's only discovered during binding selection. For now we just add
// synthetic root exports for all tables in the module, and then we delete
// the exports just after GC. This should keep tables like the function
// table alive during GC all the way through to the bindings generation
// where we can either actually export it or gc it out since it's not used.
let mut exported_tables = Vec::new();
for table in module.tables.iter() {
exported_tables.push(module.exports.add("foo", table.id()));
}
walrus::passes::gc::run(module);
for export in exported_tables {
module.exports.delete(export);
}

Ok(module.customs.add(section))
}
Expand Down

0 comments on commit e7902f3

Please sign in to comment.