Skip to content

Commit

Permalink
GC private tables (#265)
Browse files Browse the repository at this point in the history
  • Loading branch information
zetanumbers committed Jul 2, 2024
1 parent 70bbaf1 commit 1bace0e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
6 changes: 4 additions & 2 deletions crates/tests/tests/spec-tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,10 @@ fn run(wast: &Path) -> Result<(), anyhow::Error> {
// Tests which assert that they're not linkable tend to not work with
// the gc pass because it removes things which would cause a module to
// become unlinkable. This doesn't matter too much in the real world
// (hopefully), so just don't gc assert_unlinkable modules.
if cmd != "assert_unlinkable" {
// (hopefully), so just don't gc assert_unlinkable modules. The same
// applies to assert_uninstantiable modules due to removal of unused
// elements and tables.
if !matches!(cmd.as_str(), "assert_unlinkable" | "assert_uninstantiable") {
walrus::passes::gc::run(&mut module);
}

Expand Down
12 changes: 9 additions & 3 deletions src/passes/used.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,15 @@ impl Used {
for elem in module.elements.iter() {
match elem.kind {
// Active segments are rooted because they initialize imported
// or exported tables. Declared segments can probably get gc'd
// but for now we're conservative and we root them.
ElementKind::Active { .. } | ElementKind::Declared => {
// tables.
ElementKind::Active { table, .. } => {
if module.tables.get(table).import.is_some() {
stack.push_element(elem.id());
}
}
// Declared segments can probably get gc'd but for now we're
// conservative and we root them
ElementKind::Declared => {
stack.push_element(elem.id());
}
ElementKind::Passive => {}
Expand Down

0 comments on commit 1bace0e

Please sign in to comment.