From 17fe4f1772ff2445b3af3c1869ebd621bc2fa2c3 Mon Sep 17 00:00:00 2001 From: imaqtkatt Date: Tue, 2 Apr 2024 14:07:42 -0300 Subject: [PATCH] Use hvmc prune implementation --- src/hvmc_net/mod.rs | 1 - src/hvmc_net/prune.rs | 32 -------------------------------- src/lib.rs | 4 ++-- 3 files changed, 2 insertions(+), 35 deletions(-) delete mode 100644 src/hvmc_net/prune.rs diff --git a/src/hvmc_net/mod.rs b/src/hvmc_net/mod.rs index 7a785a16e..ebe85388c 100644 --- a/src/hvmc_net/mod.rs +++ b/src/hvmc_net/mod.rs @@ -1,2 +1 @@ pub mod mutual_recursion; -pub mod prune; diff --git a/src/hvmc_net/prune.rs b/src/hvmc_net/prune.rs deleted file mode 100644 index 627241fa3..000000000 --- a/src/hvmc_net/prune.rs +++ /dev/null @@ -1,32 +0,0 @@ -use hvmc::ast::{Book, Tree}; -use std::collections::HashSet; - -use crate::builtins::CORE_BUILTINS; - -pub fn prune_defs(book: &mut Book, entrypoint: String) { - let mut used_defs = HashSet::from_iter(CORE_BUILTINS.iter().map(|x| x.to_string())); - // Start visiting the given entrypoint - let mut to_visit = vec![entrypoint.clone()]; - - while let Some(nam) = to_visit.pop() { - let def = &book[&nam]; - used_defs_in_tree(&def.root, &mut used_defs, &mut to_visit); - for (a, b) in &def.redexes { - used_defs_in_tree(a, &mut used_defs, &mut to_visit); - used_defs_in_tree(b, &mut used_defs, &mut to_visit); - } - } - let used_defs = used_defs.into_iter().collect::>(); - book.retain(|nam, _| used_defs.contains(nam) || *nam == entrypoint); -} - -fn used_defs_in_tree(tree: &Tree, used_defs: &mut HashSet, to_visit: &mut Vec) { - if let Tree::Ref { nam } = tree { - if used_defs.insert(nam.clone()) { - to_visit.push(nam.clone()); - } - } - for subtree in tree.children() { - used_defs_in_tree(subtree, used_defs, to_visit); - } -} diff --git a/src/lib.rs b/src/lib.rs index 01c0d3613..c962e9f53 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,7 +9,7 @@ use hvmc::{ host::Host, run::{DynNet, Heap, Rewrites}, }; -use hvmc_net::{mutual_recursion, prune::prune_defs}; +use hvmc_net::mutual_recursion; use net::{hvmc_to_net::hvmc_to_net, net_to_hvmc::nets_to_hvmc}; use std::{ sync::{Arc, Mutex}, @@ -63,7 +63,7 @@ pub fn compile_book( diagnostics.fatal(())?; } if opts.prune { - prune_defs(&mut core_book, book.hvmc_entrypoint().to_string()); + core_book.prune(&[book.hvmc_entrypoint().to_string()]); } mutual_recursion::check_cycles(&core_book, &mut diagnostics)?;