Skip to content

Commit

Permalink
Change resolve_symbol_and_mod_path to be private.
Browse files Browse the repository at this point in the history
  • Loading branch information
tritao committed Oct 26, 2024
1 parent cb97cdb commit 93ec256
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 53 deletions.
56 changes: 28 additions & 28 deletions sway-core/src/semantic_analysis/ast_node/declaration/declaration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,20 +188,20 @@ impl TyDecl {

// save decl_refs for the LSP
for supertrait in trait_decl.supertraits.iter_mut() {
let _ = ctx
.resolve_call_path(handler, &supertrait.name)
.map(|supertrait_decl| {
if let ty::TyDecl::TraitDecl(ty::TraitDecl {
decl_id: supertrait_decl_id,
}) = supertrait_decl
{
supertrait.decl_ref = Some(DeclRef::new(
engines.de().get(&supertrait_decl_id).name.clone(),
supertrait_decl_id,
engines.de().get(&supertrait_decl_id).span.clone(),
));
}
});
let _ =
ctx.resolve_call_path(handler, &supertrait.name)
.map(|supertrait_decl| {
if let ty::TyDecl::TraitDecl(ty::TraitDecl {
decl_id: supertrait_decl_id,
}) = supertrait_decl
{
supertrait.decl_ref = Some(DeclRef::new(
engines.de().get(&supertrait_decl_id).name.clone(),
supertrait_decl_id,
engines.de().get(&supertrait_decl_id).span.clone(),
));
}
});
}

let decl: ty::TyDecl = decl_engine
Expand Down Expand Up @@ -359,20 +359,20 @@ impl TyDecl {

// save decl_refs for the LSP
for supertrait in abi_decl.supertraits.iter_mut() {
let _ = ctx
.resolve_call_path(handler, &supertrait.name)
.map(|supertrait_decl| {
if let ty::TyDecl::TraitDecl(ty::TraitDecl {
decl_id: supertrait_decl_id,
}) = supertrait_decl
{
supertrait.decl_ref = Some(DeclRef::new(
engines.de().get(&supertrait_decl_id).name.clone(),
supertrait_decl_id,
engines.de().get(&supertrait_decl_id).span.clone(),
));
}
});
let _ =
ctx.resolve_call_path(handler, &supertrait.name)
.map(|supertrait_decl| {
if let ty::TyDecl::TraitDecl(ty::TraitDecl {
decl_id: supertrait_decl_id,
}) = supertrait_decl
{
supertrait.decl_ref = Some(DeclRef::new(
engines.de().get(&supertrait_decl_id).name.clone(),
supertrait_decl_id,
engines.de().get(&supertrait_decl_id).span.clone(),
));
}
});
}

let decl: ty::TyDecl = decl_engine.insert(abi_decl.clone(), Some(&decl_id)).into();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ use sway_error::{
};
use sway_types::{integer_bits::IntegerBits, u256::U256, Ident, Named, Span, Spanned};
use symbol_collection_context::SymbolCollectionContext;
use type_resolve::resolve_symbol_and_mod_path;
use type_resolve::{resolve_call_path, VisibilityCheck};

#[allow(clippy::too_many_arguments)]
impl ty::TyExpression {
Expand Down Expand Up @@ -298,8 +298,7 @@ impl ty::TyExpression {
is_absolute: false,
};
if matches!(
ctx.resolve_call_path(&Handler::default(), &call_path,)
.ok(),
ctx.resolve_call_path(&Handler::default(), &call_path,).ok(),
Some(ty::TyDecl::EnumVariantDecl { .. })
) {
Self::type_check_delineated_path(
Expand Down Expand Up @@ -1234,13 +1233,14 @@ impl ty::TyExpression {
let storage_key_ident = Ident::new_with_override("StorageKey".into(), span.clone());

// Search for the struct declaration with the call path above.
let (storage_key_decl, _) = resolve_symbol_and_mod_path(
let storage_key_decl = resolve_call_path(
handler,
engines,
ctx.namespace().root_module(),
ctx.namespace().root(),
&storage_key_mod_path,
&storage_key_ident,
&storage_key_ident.into(),
None,
VisibilityCheck::No,
)?;

let storage_key_struct_decl_id = storage_key_decl
Expand Down Expand Up @@ -1791,7 +1791,7 @@ impl ty::TyExpression {
match abi_name {
// look up the call path and get the declaration it references
AbiName::Known(abi_name) => {
let unknown_decl = ctx.resolve_call_path(handler, abi_name)?;
let unknown_decl = ctx.resolve_call_path(handler, abi_name)?;
unknown_decl.to_abi_ref(handler, engines)?
}
AbiName::Deferred => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -819,11 +819,9 @@ pub(crate) fn resolve_method_name(
let type_info_prefix = ctx
.namespace()
.prepend_module_path(&call_path_binding.inner.prefixes);
ctx.namespace().root_module().lookup_submodule(
handler,
engines,
&type_info_prefix,
)?;
ctx.namespace()
.root_module()
.lookup_submodule(handler, engines, &type_info_prefix)?;

// find the method
let decl_ref = ctx.find_method_for_type(
Expand Down
14 changes: 6 additions & 8 deletions sway-core/src/semantic_analysis/type_check_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ use sway_types::{span::Span, Ident, Spanned};

use super::{
symbol_collection_context::SymbolCollectionContext,
type_resolve::{
resolve_call_path, resolve_qualified_call_path, resolve_symbol_and_mod_path, resolve_type,
VisibilityCheck,
},
type_resolve::{resolve_call_path, resolve_qualified_call_path, resolve_type, VisibilityCheck},
GenericShadowingMode,
};

Expand Down Expand Up @@ -701,15 +698,16 @@ impl<'a> TypeCheckContext<'a> {
handler: &Handler,
symbol: &Ident,
) -> Result<ty::TyDecl, ErrorEmitted> {
resolve_symbol_and_mod_path(
resolve_call_path(
handler,
self.engines(),
self.namespace().root_module(),
self.namespace().root(),
self.namespace().mod_path(),
symbol,
&symbol.clone().into(),
self.self_type(),
VisibilityCheck::No,
)
.map(|d| d.0.expect_typed())
.map(|d| d.expect_typed())
}

/// Short-hand for calling [Root::resolve_call_path_with_visibility_check] on `root` with the `mod_path`.
Expand Down
2 changes: 1 addition & 1 deletion sway-core/src/semantic_analysis/type_resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ pub fn resolve_call_path(
Ok(decl)
}

pub fn resolve_symbol_and_mod_path(
fn resolve_symbol_and_mod_path(
handler: &Handler,
engines: &Engines,
module: &Module,
Expand Down
5 changes: 1 addition & 4 deletions sway-core/src/type_system/ast_elements/type_parameter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,7 @@ impl TypeParameter {
ctx: &TypeCheckContext,
tc: &TraitConstraint,
) -> Vec<TraitConstraint> {
match ctx
.resolve_call_path(handler, &tc.trait_name)
.ok()
{
match ctx.resolve_call_path(handler, &tc.trait_name).ok() {
Some(ty::TyDecl::TraitDecl(ty::TraitDecl { decl_id, .. })) => {
let trait_decl = ctx.engines.de().get_trait(&decl_id);
let mut result = trait_decl
Expand Down

0 comments on commit 93ec256

Please sign in to comment.