From 9bb9ed5c43f895d49b9ce41d9c467e28c75032b6 Mon Sep 17 00:00:00 2001 From: Philippe Laferriere Date: Thu, 18 Jul 2024 11:32:25 -0400 Subject: [PATCH] fix `NameResolver` --- assembly/src/assembler/module_graph/mod.rs | 6 +++--- assembly/src/assembler/module_graph/name_resolver.rs | 9 +++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/assembly/src/assembler/module_graph/mod.rs b/assembly/src/assembler/module_graph/mod.rs index fa0b83636e..1963ca8864 100644 --- a/assembly/src/assembler/module_graph/mod.rs +++ b/assembly/src/assembler/module_graph/mod.rs @@ -101,9 +101,9 @@ impl WrapperModule { } } - pub fn unwrap_ast(&self) -> Arc { + pub fn unwrap_ast(&self) -> &Arc { match self { - WrapperModule::Ast(module) => module.clone(), + WrapperModule::Ast(module) => module, WrapperModule::Exports(_) => { panic!("expected module to be in AST representation, but was compiled") } @@ -558,7 +558,7 @@ impl ModuleGraph { /// Fetch a [WrapperProcedure] by [GlobalProcedureIndex], or `None` if index is invalid. pub fn get_procedure(&self, id: GlobalProcedureIndex) -> Option { match &self.modules[id.module.as_usize()] { - WrapperModule::Ast(m) => m.get(id.index).map(|export| WrapperProcedure::Ast(export)), + WrapperModule::Ast(m) => m.get(id.index).map(WrapperProcedure::Ast), WrapperModule::Exports(m) => m .procedures .get(id.index.as_usize()) diff --git a/assembly/src/assembler/module_graph/name_resolver.rs b/assembly/src/assembler/module_graph/name_resolver.rs index 6070a52e18..8f4c93ee68 100644 --- a/assembly/src/assembler/module_graph/name_resolver.rs +++ b/assembly/src/assembler/module_graph/name_resolver.rs @@ -177,7 +177,7 @@ impl<'a> NameResolver<'a> { .get_name(gid.index) .clone() } else { - self.graph[gid].name().clone() + self.graph.get_procedure_unsafe(gid).name().clone() }; Ok(ResolvedTarget::Resolved { gid, @@ -210,6 +210,7 @@ impl<'a> NameResolver<'a> { .resolve_import(name) } else { self.graph[caller.module] + .unwrap_ast() .resolve_import(name) .map(|import| Span::new(import.span(), import.path())) } @@ -255,7 +256,7 @@ impl<'a> NameResolver<'a> { .get_name(gid.index) .clone() } else { - self.graph[gid].name().clone() + self.graph.get_procedure_unsafe(gid).name().clone() }; Ok(ResolvedTarget::Resolved { gid, @@ -315,7 +316,7 @@ impl<'a> NameResolver<'a> { if module_index >= pending_offset { self.pending[module_index - pending_offset].resolver.resolve(callee) } else { - self.graph[module].resolve(callee) + self.graph[module].unwrap_ast().resolve(callee) } } @@ -487,7 +488,7 @@ impl<'a> NameResolver<'a> { if module_index >= pending_offset { self.pending[module_index - pending_offset].source_file.clone() } else { - self.graph[module].source_file() + self.graph[module].unwrap_ast().source_file() } }