Skip to content

Commit

Permalink
Remove Namespace.lookup_submodule_from_absolute_path.
Browse files Browse the repository at this point in the history
  • Loading branch information
tritao committed Oct 26, 2024
1 parent 15af0d1 commit cb97cdb
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ pub(crate) fn resolve_method_name(
let type_info_prefix = ctx
.namespace()
.prepend_module_path(&call_path_binding.inner.prefixes);
ctx.namespace().lookup_submodule_from_absolute_path(
ctx.namespace().root_module().lookup_submodule(
handler,
engines,
&type_info_prefix,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ pub(crate) fn struct_instantiation(
// find the module that the struct decl is in
let type_info_prefix = ctx.namespace().prepend_module_path(prefixes);
ctx.namespace()
.lookup_submodule_from_absolute_path(handler, engines, &type_info_prefix)?;
.root_module()
.lookup_submodule(handler, engines, &type_info_prefix)?;

// resolve the type of the struct decl
let type_id = ctx
Expand Down
11 changes: 1 addition & 10 deletions sway-core/src/semantic_analysis/namespace/namespace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use super::{
module::Module, root::Root, submodule_namespace::SubmoduleNamespace, ModulePath, ModulePathBuf,
};

use sway_error::handler::{ErrorEmitted, Handler};
use sway_error::handler::Handler;
use sway_types::span::Span;

/// The set of items that represent the namespace context passed throughout type checking.
Expand Down Expand Up @@ -118,15 +118,6 @@ impl Namespace {
.unwrap()
}

pub fn lookup_submodule_from_absolute_path(
&self,
handler: &Handler,
engines: &Engines,
path: &ModulePath,
) -> Result<&Module, ErrorEmitted> {
self.root.module.lookup_submodule(handler, engines, path)
}

/// Returns true if the current module being checked is a direct or indirect submodule of
/// the module given by the `absolute_module_path`.
///
Expand Down
2 changes: 1 addition & 1 deletion sway-core/src/semantic_analysis/symbol_resolve_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ impl<'a> SymbolResolveContext<'a> {
resolve_call_path(
handler,
self.engines(),
self.namespace(),
self.namespace().root(),
&self.namespace().mod_path,
call_path,
self.self_type(),
Expand Down
8 changes: 4 additions & 4 deletions sway-core/src/semantic_analysis/type_check_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ impl<'a> TypeCheckContext<'a> {
resolve_call_path(
handler,
self.engines(),
self.namespace(),
self.namespace().root(),
&self.namespace().mod_path,
call_path,
self.self_type(),
Expand All @@ -739,7 +739,7 @@ impl<'a> TypeCheckContext<'a> {
resolve_call_path(
handler,
self.engines(),
self.namespace(),
self.namespace().root(),
self.namespace().mod_path(),
call_path,
self.self_type(),
Expand Down Expand Up @@ -768,7 +768,7 @@ impl<'a> TypeCheckContext<'a> {
}

// grab the local module
let local_module = self.namespace().lookup_submodule_from_absolute_path(
let local_module = self.namespace().root_module().lookup_submodule(
handler,
self.engines(),
&self.namespace().mod_path,
Expand Down Expand Up @@ -796,7 +796,7 @@ impl<'a> TypeCheckContext<'a> {
.unwrap_or_else(|err| type_engine.insert(self.engines, TypeInfo::ErrorRecovery(err), None));

// grab the module where the type itself is declared
let type_module = self.namespace().lookup_submodule_from_absolute_path(
let type_module = self.namespace().root_module().lookup_submodule(
handler,
self.engines(),
item_prefix,
Expand Down
12 changes: 6 additions & 6 deletions sway-core/src/semantic_analysis/type_resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
CallPath, QualifiedCallPath,
},
monomorphization::type_decl_opt_to_type_id,
namespace::{Module, ModulePath, ResolvedDeclaration, ResolvedTraitImplItem},
namespace::{Module, ModulePath, ResolvedDeclaration, ResolvedTraitImplItem, Root},
type_system::SubstTypes,
EnforceTypeArguments, Engines, Namespace, SubstTypesContext, TypeId, TypeInfo,
};
Expand Down Expand Up @@ -252,7 +252,7 @@ pub fn resolve_qualified_call_path(
let type_decl = resolve_call_path(
handler,
engines,
namespace,
namespace.root(),
mod_path,
&qualified_call_path.clone().to_call_path(handler)?,
self_type,
Expand Down Expand Up @@ -301,7 +301,7 @@ pub fn resolve_qualified_call_path(
resolve_call_path(
handler,
engines,
namespace,
namespace.root(),
mod_path,
&qualified_call_path.call_path,
self_type,
Expand All @@ -321,7 +321,7 @@ pub fn resolve_qualified_call_path(
pub fn resolve_call_path(
handler: &Handler,
engines: &Engines,
namespace: &Namespace,
root: &Root,
mod_path: &ModulePath,
call_path: &CallPath,
self_type: Option<TypeId>,
Expand All @@ -336,7 +336,7 @@ pub fn resolve_call_path(
let (decl, mod_path) = resolve_symbol_and_mod_path(
handler,
engines,
namespace.root_module(),
&root.module,
&symbol_path,
&call_path.suffix,
self_type,
Expand All @@ -359,7 +359,7 @@ pub fn resolve_call_path(
// check the visibility of the call path elements
// we don't check the first prefix because direct children are always accessible
for prefix in iter_prefixes(&call_path.prefixes).skip(1) {
let module = namespace.lookup_submodule_from_absolute_path(handler, engines, prefix)?;
let module = root.module.lookup_submodule(handler, engines, prefix)?;
if module.visibility().is_private() {
let prefix_last = prefix[prefix.len() - 1].clone();
handler.emit_err(CompileError::ImportPrivateModule {
Expand Down
3 changes: 2 additions & 1 deletion sway-core/src/type_system/ast_elements/binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ impl TypeBinding<CallPath<(TypeInfo, Ident)>> {
// find the module that the symbol is in
let type_info_prefix = ctx.namespace().prepend_module_path(&self.inner.prefixes);
ctx.namespace()
.lookup_submodule_from_absolute_path(handler, engines, &type_info_prefix)?;
.root_module()
.lookup_submodule(handler, engines, &type_info_prefix)?;

// create the type info object
let type_info = type_info.apply_type_arguments(
Expand Down

0 comments on commit cb97cdb

Please sign in to comment.