From 2b5be6ca49161d96ec619285e2681a8bd9a8fcfe Mon Sep 17 00:00:00 2001 From: Jesse Brault Date: Thu, 9 Oct 2025 17:14:22 -0500 Subject: [PATCH] Change scope_ids table to use refs. --- src/name_analysis/gather.rs | 110 ++++++++++++++++++------------------ src/name_analysis/mod.rs | 2 +- 2 files changed, 56 insertions(+), 56 deletions(-) diff --git a/src/name_analysis/gather.rs b/src/name_analysis/gather.rs index b607992..f3df01d 100644 --- a/src/name_analysis/gather.rs +++ b/src/name_analysis/gather.rs @@ -53,11 +53,11 @@ fn handle_insert_error( } } -fn gather_node_children( - node: &impl AstNode, +fn gather_node_children<'a>( + node: &'a impl AstNode, symbol_table: &mut SymbolTable, fqn_context: &mut FqnContext, - scope_ids: &mut HashMap, + scope_ids: &mut HashMap<&'a VariableUse, usize>, diagnostics: &mut Vec, ) { for child in node.children() { @@ -65,11 +65,11 @@ fn gather_node_children( } } -fn gather_node( - node: AstNodeRef, +fn gather_node<'a>( + node: AstNodeRef<'a>, symbol_table: &mut SymbolTable, fqn_context: &mut FqnContext, - scope_ids: &mut HashMap, + scope_ids: &mut HashMap<&'a VariableUse, usize>, diagnostics: &mut Vec, ) { match node { @@ -333,11 +333,11 @@ fn gather_node( } } -pub fn gather_compilation_unit( - compilation_unit: &mut CompilationUnit, +pub fn gather_compilation_unit<'a>( + compilation_unit: &'a mut CompilationUnit, file_name: &str, symbol_table: &mut SymbolTable, - scope_ids: &mut HashMap, + scope_ids: &mut HashMap<&'a VariableUse, usize>, diagnostics: &mut Vec, ) { let mut fqn_context = FqnContext::new(); @@ -421,11 +421,11 @@ fn gather_concrete_use_symbol( } } -fn gather_module( - module: &Module, +fn gather_module<'a>( + module: &'a Module, symbol_table: &mut SymbolTable, fqn_context: &mut FqnContext, - scope_ids: &mut HashMap, + scope_ids: &mut HashMap<&'a VariableUse, usize>, diagnostics: &mut Vec, ) { let module_symbol = ModuleSymbol::new( @@ -462,11 +462,11 @@ fn gather_module( fqn_context.pop(); } -fn gather_interface( - interface: &Interface, +fn gather_interface<'a>( + interface: &'a Interface, symbol_table: &mut SymbolTable, fqn_context: &mut FqnContext, - scope_ids: &mut HashMap, + scope_ids: &mut HashMap<&'a VariableUse, usize>, diagnostics: &mut Vec, ) { let type_symbol = ConcreteTypeSymbol::new( @@ -506,11 +506,11 @@ fn gather_interface( fqn_context.pop(); } -fn gather_class( - class: &Class, +fn gather_class<'a>( + class: &'a Class, symbol_table: &mut SymbolTable, fqn_context: &mut FqnContext, - scope_ids: &mut HashMap, + scope_ids: &mut HashMap<&'a VariableUse, usize>, diagnostics: &mut Vec, ) { let class_symbol = ConcreteTypeSymbol::new( @@ -557,11 +557,11 @@ fn gather_class( fqn_context.pop(); } -fn gather_function( - function: &Function, +fn gather_function<'a>( + function: &'a Function, symbol_table: &mut SymbolTable, fqn_context: &mut FqnContext, - scope_ids: &mut HashMap, + scope_ids: &mut HashMap<&'a VariableUse, usize>, diagnostics: &mut Vec, ) { let function_symbol = FunctionSymbol::without_parameters_or_return_type( @@ -613,11 +613,11 @@ fn gather_function( symbol_table.pop_scope(); } -fn gather_operator_function( - operator_function: &OperatorFunction, +fn gather_operator_function<'a>( + operator_function: &'a OperatorFunction, symbol_table: &mut SymbolTable, fqn_context: &mut FqnContext, - scope_ids: &mut HashMap, + scope_ids: &mut HashMap<&'a VariableUse, usize>, diagnostics: &mut Vec, ) { let function_symbol = FunctionSymbol::without_parameters_or_return_type( @@ -674,11 +674,11 @@ fn gather_operator_function( symbol_table.pop_scope(); } -fn gather_platform_function( - platform_function: &PlatformFunction, +fn gather_platform_function<'a>( + platform_function: &'a PlatformFunction, symbol_table: &mut SymbolTable, fqn_context: &mut FqnContext, - scope_ids: &mut HashMap, + scope_ids: &mut HashMap<&'a VariableUse, usize>, diagnostics: &mut Vec, ) { let function_symbol = FunctionSymbol::without_parameters_or_return_type( @@ -728,11 +728,11 @@ fn gather_platform_function( symbol_table.pop_scope(); } -fn gather_platform_operator_function( - platform_operator_function: &PlatformOperatorFunction, +fn gather_platform_operator_function<'a>( + platform_operator_function: &'a PlatformOperatorFunction, symbol_table: &mut SymbolTable, fqn_context: &mut FqnContext, - scope_ids: &mut HashMap, + scope_ids: &mut HashMap<&'a VariableUse, usize>, diagnostics: &mut Vec, ) { let function_symbol = FunctionSymbol::without_parameters_or_return_type( @@ -782,11 +782,11 @@ fn gather_platform_operator_function( symbol_table.pop_scope(); } -fn gather_interface_function( - interface_function: &InterfaceFunction, +fn gather_interface_function<'a>( + interface_function: &'a InterfaceFunction, symbol_table: &mut SymbolTable, fqn_context: &mut FqnContext, - scope_ids: &mut HashMap, + scope_ids: &mut HashMap<&'a VariableUse, usize>, diagnostics: &mut Vec, ) { let function_symbol = FunctionSymbol::without_parameters_or_return_type( @@ -836,11 +836,11 @@ fn gather_interface_function( symbol_table.pop_scope(); } -fn gather_interface_default_function( - interface_default_function: &InterfaceDefaultFunction, +fn gather_interface_default_function<'a>( + interface_default_function: &'a InterfaceDefaultFunction, symbol_table: &mut SymbolTable, fqn_context: &mut FqnContext, - scope_ids: &mut HashMap, + scope_ids: &mut HashMap<&'a VariableUse, usize>, diagnostics: &mut Vec, ) { let function_symbol = FunctionSymbol::without_parameters_or_return_type( @@ -897,11 +897,11 @@ fn gather_interface_default_function( symbol_table.pop_scope(); } -fn gather_interface_operator_function( - interface_operator_function: &InterfaceOperatorFunction, +fn gather_interface_operator_function<'a>( + interface_operator_function: &'a InterfaceOperatorFunction, symbol_table: &mut SymbolTable, fqn_context: &mut FqnContext, - scope_ids: &mut HashMap, + scope_ids: &mut HashMap<&'a VariableUse, usize>, diagnostics: &mut Vec, ) { let function_symbol = FunctionSymbol::without_parameters_or_return_type( @@ -951,11 +951,11 @@ fn gather_interface_operator_function( symbol_table.pop_scope(); } -fn gather_interface_default_operator_function( - interface_default_operator_function: &InterfaceDefaultOperatorFunction, +fn gather_interface_default_operator_function<'a>( + interface_default_operator_function: &'a InterfaceDefaultOperatorFunction, symbol_table: &mut SymbolTable, fqn_context: &mut FqnContext, - scope_ids: &mut HashMap, + scope_ids: &mut HashMap<&'a VariableUse, usize>, diagnostics: &mut Vec, ) { let function_symbol = FunctionSymbol::without_parameters_or_return_type( @@ -1032,11 +1032,11 @@ fn gather_interface_default_operator_function( symbol_table.pop_scope(); } -fn gather_function_body( - function_body: &FunctionBody, +fn gather_function_body<'a>( + function_body: &'a FunctionBody, symbol_table: &mut SymbolTable, fqn_context: &mut FqnContext, - scope_ids: &mut HashMap, + scope_ids: &mut HashMap<&'a VariableUse, usize>, diagnostics: &mut Vec, ) { symbol_table.push_scope("FunctionBodyScope"); @@ -1050,11 +1050,11 @@ fn gather_function_body( symbol_table.pop_scope(); } -fn gather_member( - member: &Member, +fn gather_member<'a>( + member: &'a Member, symbol_table: &mut SymbolTable, fqn_context: &mut FqnContext, - scope_ids: &mut HashMap, + scope_ids: &mut HashMap<&'a VariableUse, usize>, diagnostics: &mut Vec, ) { let member_symbol = ClassMemberSymbol::new( @@ -1082,11 +1082,11 @@ fn gather_member( ); } -fn gather_variable_declaration( - variable_declaration: &VariableDeclaration, +fn gather_variable_declaration<'a>( + variable_declaration: &'a VariableDeclaration, symbol_table: &mut SymbolTable, fqn_context: &mut FqnContext, - scope_ids: &mut HashMap, + scope_ids: &mut HashMap<&'a VariableUse, usize>, diagnostics: &mut Vec, ) { let variable_symbol = VariableSymbol::new( @@ -1117,10 +1117,10 @@ fn gather_variable_declaration( } } -fn gather_variable_use( - variable_use: &VariableUse, +fn gather_variable_use<'a>( + variable_use: &'a VariableUse, symbol_table: &mut SymbolTable, - scope_ids: &mut HashMap, + scope_ids: &mut HashMap<&'a VariableUse, usize>, ) { - scope_ids.insert(variable_use.clone(), symbol_table.current_scope_id()); + scope_ids.insert(variable_use, symbol_table.current_scope_id()); } diff --git a/src/name_analysis/mod.rs b/src/name_analysis/mod.rs index ca6f682..6f38c6b 100644 --- a/src/name_analysis/mod.rs +++ b/src/name_analysis/mod.rs @@ -39,7 +39,7 @@ pub fn analyze_names<'a, F: Files<'a, FileId = usize, Name = String>>( symbol_table: &mut SymbolTable, ) -> Vec { let mut diagnostics = vec![]; - let mut scope_ids: HashMap = HashMap::new(); + let mut scope_ids: HashMap<&VariableUse, usize> = HashMap::new(); // gather symbols for compilation_unit in compilation_units.iter_mut() {