Skip to content

Commit eac621c

Browse files
Perf(parser): Pre-compute SSA alias table in SSAChunk to eliminate per-call HashMap.
1 parent 3b8a680 commit eac621c

File tree

2 files changed

+2
-17
lines changed

2 files changed

+2
-17
lines changed

compiler/src/modules/parser/types.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ pub struct SSAChunk {
9999
pub classes: Vec<SSAChunk>,
100100
pub is_pure: bool,
101101
pub overflow: bool,
102+
pub prev_slots: Vec<Option<u16>>,
102103
pub(super) name_index: HashMap<String, u16>
103104
}
104105

compiler/src/modules/vm/mod.rs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -200,23 +200,7 @@ impl<'a> VM<'a> {
200200
let mut ip = 0usize;
201201
let mut phi_idx = 0usize;
202202

203-
// SSA backward-compat alias table
204-
let prev_slots = {
205-
let mut ps: Vec<Option<usize>> = vec![None; chunk.names.len()]; // SSA alias table: maps each versioned slot to its predecessor for backward compatibility
206-
let mut name_map: HashMap<&str, usize> = HashMap::with_capacity(chunk.names.len());
207-
for (i, name) in chunk.names.iter().enumerate() { name_map.insert(name.as_str(), i); }
208-
for (i, name) in chunk.names.iter().enumerate() {
209-
if let Some(pos) = name.rfind('_') {
210-
if let Ok(ver) = name[pos+1..].parse::<u32>() {
211-
if ver > 0 {
212-
let prev = format!("{}_{}", &name[..pos], ver - 1);
213-
if let Some(&j) = name_map.get(prev.as_str()) { ps[i] = Some(j); }
214-
}
215-
}
216-
}
217-
}
218-
Box::new(ps)
219-
};
203+
let prev_slots = &chunk.prev_slots; // SSA alias table: pre-computed in SSAChunk, maps each versioned slot to its predecessor.
220204

221205
loop {
222206
if ip >= n { return Ok(Val::none()); }

0 commit comments

Comments
 (0)