Change scope_ids table to use refs.

This commit is contained in:
Jesse Brault 2025-10-09 17:14:22 -05:00
parent f0772fbf11
commit 2b5be6ca49
2 changed files with 56 additions and 56 deletions

View File

@ -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<VariableUse, usize>,
scope_ids: &mut HashMap<&'a VariableUse, usize>,
diagnostics: &mut Vec<DmDiagnostic>,
) {
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<VariableUse, usize>,
scope_ids: &mut HashMap<&'a VariableUse, usize>,
diagnostics: &mut Vec<DmDiagnostic>,
) {
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<VariableUse, usize>,
scope_ids: &mut HashMap<&'a VariableUse, usize>,
diagnostics: &mut Vec<DmDiagnostic>,
) {
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<VariableUse, usize>,
scope_ids: &mut HashMap<&'a VariableUse, usize>,
diagnostics: &mut Vec<DmDiagnostic>,
) {
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<VariableUse, usize>,
scope_ids: &mut HashMap<&'a VariableUse, usize>,
diagnostics: &mut Vec<DmDiagnostic>,
) {
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<VariableUse, usize>,
scope_ids: &mut HashMap<&'a VariableUse, usize>,
diagnostics: &mut Vec<DmDiagnostic>,
) {
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<VariableUse, usize>,
scope_ids: &mut HashMap<&'a VariableUse, usize>,
diagnostics: &mut Vec<DmDiagnostic>,
) {
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<VariableUse, usize>,
scope_ids: &mut HashMap<&'a VariableUse, usize>,
diagnostics: &mut Vec<DmDiagnostic>,
) {
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<VariableUse, usize>,
scope_ids: &mut HashMap<&'a VariableUse, usize>,
diagnostics: &mut Vec<DmDiagnostic>,
) {
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<VariableUse, usize>,
scope_ids: &mut HashMap<&'a VariableUse, usize>,
diagnostics: &mut Vec<DmDiagnostic>,
) {
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<VariableUse, usize>,
scope_ids: &mut HashMap<&'a VariableUse, usize>,
diagnostics: &mut Vec<DmDiagnostic>,
) {
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<VariableUse, usize>,
scope_ids: &mut HashMap<&'a VariableUse, usize>,
diagnostics: &mut Vec<DmDiagnostic>,
) {
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<VariableUse, usize>,
scope_ids: &mut HashMap<&'a VariableUse, usize>,
diagnostics: &mut Vec<DmDiagnostic>,
) {
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<VariableUse, usize>,
scope_ids: &mut HashMap<&'a VariableUse, usize>,
diagnostics: &mut Vec<DmDiagnostic>,
) {
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<VariableUse, usize>,
scope_ids: &mut HashMap<&'a VariableUse, usize>,
diagnostics: &mut Vec<DmDiagnostic>,
) {
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<VariableUse, usize>,
scope_ids: &mut HashMap<&'a VariableUse, usize>,
diagnostics: &mut Vec<DmDiagnostic>,
) {
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<VariableUse, usize>,
scope_ids: &mut HashMap<&'a VariableUse, usize>,
diagnostics: &mut Vec<DmDiagnostic>,
) {
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<VariableUse, usize>,
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());
}

View File

@ -39,7 +39,7 @@ pub fn analyze_names<'a, F: Files<'a, FileId = usize, Name = String>>(
symbol_table: &mut SymbolTable,
) -> Vec<DmDiagnostic> {
let mut diagnostics = vec![];
let mut scope_ids: HashMap<VariableUse, usize> = HashMap::new();
let mut scope_ids: HashMap<&VariableUse, usize> = HashMap::new();
// gather symbols
for compilation_unit in compilation_units.iter_mut() {