From a1a2b3ee509f94a94c7bf17ae4fbdda13ab03411 Mon Sep 17 00:00:00 2001 From: Griffin Berlstein Date: Mon, 9 Sep 2024 17:25:26 -0400 Subject: [PATCH] [Cider] Fix traversal bug (#2280) Small fix for name traversal resolution --- .../structures/environment/traverser.rs | 63 ++++++++++--------- 1 file changed, 34 insertions(+), 29 deletions(-) diff --git a/interp/src/flatten/structures/environment/traverser.rs b/interp/src/flatten/structures/environment/traverser.rs index a2247011f..7e98fac6c 100644 --- a/interp/src/flatten/structures/environment/traverser.rs +++ b/interp/src/flatten/structures/environment/traverser.rs @@ -317,45 +317,50 @@ impl Traverser { } } else { let current_comp = *self.concrete_path.last().unwrap(); + let current_comp = if env.cells[current_comp].as_comp().is_some() { + current_comp + } else { + // we are in a primitive component so need to go up a level + self.concrete_path[self.concrete_path.len() - 2] + }; let current_comp_ledger = - env.cells[current_comp].as_comp().unwrap_or_else(|| { - // we are in a primitive component so need to go up a level - env.cells[self.concrete_path[self.concrete_path.len() - 2]] - .unwrap_comp() - }); + env.cells[current_comp].as_comp().unwrap(); let comp_def = &env.ctx().secondary[current_comp_ledger.comp_id]; - // check cells - for (offset, def_idx) in comp_def.cell_offset_map.iter() { - let def = &env.ctx().secondary[*def_idx]; - if env.ctx().lookup_name(def.name) == target.as_ref() { - return Ok(Path::Cell( - ¤t_comp_ledger.index_bases + offset, - )); + if current_comp == *self.concrete_path.last().unwrap() { + // looking for either a cell or a port on the current component + + // check cells + for (offset, def_idx) in comp_def.cell_offset_map.iter() { + let def = &env.ctx().secondary[*def_idx]; + if env.ctx().lookup_name(def.name) == target.as_ref() { + return Ok(Path::Cell( + ¤t_comp_ledger.index_bases + offset, + )); + } } - } - // check ref cells - for (offset, def_idx) in comp_def.ref_cell_offset_map.iter() { - let def = &env.ctx().secondary[*def_idx]; - if env.ctx().lookup_name(def.name) == target.as_ref() { - let global_offset = - ¤t_comp_ledger.index_bases + offset; + // check ref cells + for (offset, def_idx) in comp_def.ref_cell_offset_map.iter() { + let def = &env.ctx().secondary[*def_idx]; + if env.ctx().lookup_name(def.name) == target.as_ref() { + let global_offset = + ¤t_comp_ledger.index_bases + offset; + + return Ok(Path::AbstractCell(LazyCellPath { + concrete_prefix: self.concrete_path, + first_ref: global_offset, + abstract_suffix: SmallVec::new(), + })); + } - return Ok(Path::AbstractCell(LazyCellPath { - concrete_prefix: self.concrete_path, - first_ref: global_offset, - abstract_suffix: SmallVec::new(), - })); + // we don't check ports here since there can't be ref ports + // without first having visited a ref cell } - // we don't check ports here since there can't be ref ports - // without first having visited a ref cell - } + // check signature - // check ports - if current_comp == *self.concrete_path.last().unwrap() { for port in env.ctx().secondary[current_comp_ledger.comp_id].signature() {