diff --git a/hercules_opt/src/delete_uncalled.rs b/hercules_opt/src/delete_uncalled.rs index 1a19ee010e4772b8a2367b928f8226109dbef32c..733576a43b7017b626199abab7d17927b028266e 100644 --- a/hercules_opt/src/delete_uncalled.rs +++ b/hercules_opt/src/delete_uncalled.rs @@ -50,6 +50,11 @@ pub fn delete_uncalled( // that all nodes in all functions will be mutable, so panic if any // edit fails. for editor in editors.iter_mut() { + // Don't make edits to dead functions as they may include calls to dead functions + if new_idx[editor.func_id().idx()].is_none() { + continue; + } + let callsites: Vec<_> = editor .node_ids() .filter(|id| editor.func().nodes[id.idx()].is_call()) diff --git a/juno_utils/src/env.rs b/juno_utils/src/env.rs index 93395ce8c37fa03177914fbcd5882e354886f24e..b52a5680997265b13a6d0d15e5d54fb71be724c1 100644 --- a/juno_utils/src/env.rs +++ b/juno_utils/src/env.rs @@ -2,6 +2,7 @@ use std::collections::HashMap; use std::collections::HashSet; use std::hash::Hash; +#[derive(Debug)] pub struct Env<K, V> { table: HashMap<K, Vec<V>>, scope: Vec<HashSet<K>>, @@ -98,6 +99,11 @@ impl<K: Eq + Hash + Copy, V> Env<K, V> { let mut new_scopes: HashMap<K, Vec<usize>> = HashMap::new(); for (k, vs) in std::mem::take(&mut self.table) { + if vs.is_empty() { + assert!(!scopes.contains_key(&k)); + continue; + } + let scope_list = scopes.remove(&k).unwrap(); assert!(scope_list.len() == vs.len());