From eda921ae439ed0f2e266482b4a3b945eac75b575 Mon Sep 17 00:00:00 2001 From: Aaron Councilman <aaronjc4@illinois.edu> Date: Thu, 13 Feb 2025 20:35:08 -0600 Subject: [PATCH] Fix delete uncalled bugs --- hercules_opt/src/delete_uncalled.rs | 5 +++++ juno_utils/src/env.rs | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/hercules_opt/src/delete_uncalled.rs b/hercules_opt/src/delete_uncalled.rs index 1a19ee01..733576a4 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 93395ce8..b52a5680 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()); -- GitLab