diff --git a/schala-lang/language/src/ast/visitor.rs b/schala-lang/language/src/ast/visitor.rs index 161a217..02c9b8a 100644 --- a/schala-lang/language/src/ast/visitor.rs +++ b/schala-lang/language/src/ast/visitor.rs @@ -92,8 +92,8 @@ pub fn walk_expression(v: &mut V, expr: &Expression) { walk_expression(v, f); for arg in arguments.iter() { match arg { - InvocationArgument::Positional(expr) => walk_expression(v, expr), - InvocationArgument::Keyword { expr, .. } => walk_expression(v, expr), //TODO maybe I can combine this pattern + InvocationArgument::Positional(expr) | InvocationArgument::Keyword { expr, .. } => + walk_expression(v, expr), _ => (), } } diff --git a/schala-lang/language/src/symbol_table/mod.rs b/schala-lang/language/src/symbol_table/mod.rs index 4e9a948..071ba2a 100644 --- a/schala-lang/language/src/symbol_table/mod.rs +++ b/schala-lang/language/src/symbol_table/mod.rs @@ -147,6 +147,7 @@ pub struct SymbolTable { fqsn_to_symbol: HashMap>, id_to_symbol: HashMap>, + def_to_symbol: HashMap>, } impl SymbolTable { @@ -159,6 +160,7 @@ impl SymbolTable { fqsn_to_symbol: HashMap::new(), id_to_symbol: HashMap::new(), + def_to_symbol: HashMap::new(), } } @@ -184,9 +186,8 @@ impl SymbolTable { self.id_to_symbol.get(id).map(|s| s.as_ref()) } - //TODO optimize this pub fn lookup_symbol_by_def(&self, def: &DefId) -> Option<&Symbol> { - self.id_to_symbol.iter().find(|(_, sym)| sym.def_id == *def).map(|(_, sym)| sym.as_ref()) + self.def_to_symbol.get(def).map(|s| s.as_ref()) } #[allow(dead_code)] @@ -205,7 +206,8 @@ impl SymbolTable { let symbol = Rc::new(Symbol { fully_qualified_name: fqsn.clone(), spec, def_id }); self.symbol_trie.insert(&fqsn); self.fqsn_to_symbol.insert(fqsn, symbol.clone()); - self.id_to_symbol.insert(*id, symbol); + self.id_to_symbol.insert(*id, symbol.clone()); + self.def_to_symbol.insert(def_id, symbol); } }