Skip to content

Commit

Permalink
Renamed CallPathType::Resolved to CallPathType::Full
Browse files Browse the repository at this point in the history
  • Loading branch information
jjcnn committed Oct 15, 2024
1 parent 7ec3af9 commit 512ce8a
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 29 deletions.
41 changes: 25 additions & 16 deletions sway-core/src/language/call_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,23 @@ impl DebugWithEngines for QualifiedCallPath {

#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub enum CallPathType {
// An unresolved path on the form `::X::Y`. The path must be resolved relative to the package
// root module.
/// An unresolved path on the form `::X::Y::Z`. The path must be resolved relative to the package
/// root module.
/// The path can be converted to a full path by prepending the package name, so if the path
/// `::X::Y::Z` occurs in package `A`, then the corresponding full path will be `A::X::Y::Z`.
RelativeToPackageRoot,
// An unresolved path on the form `X::Y`. The path must either be resolved relative to the
// current module or as an absolute path.
/// An unresolved path on the form `X::Y::Z`. The path must either be resolved relative to the
/// current module, in which case `X` is either a submodule or a name bound in the current
/// module, or as a full path, in which case `X` is the name of the current package.
/// If the path is resolved relative to the current module, and the current module has a module
/// path `A::B::C`, then the corresponding full path is `A::B::C::X::Y::Z`.
/// If the path is resolved as a full path, then the full path is obviously `X::Y::Z`.
Ambiguous,
// A fully resolved, absolute path
Resolved,
/// A full path on the form `X::Y::Z`. The first identifier `X` refers to the current package
/// name. After that comes a (possibly empty) series of names of submodules. Then comes the name
/// of an item (a type, a trait, a function, or something else declared in that
/// module). Additionally, there may be additional names such as the name of an enum variant.
Full,
}

/// In the expression `a::b::c()`, `a` and `b` are the prefixes and `c` is the suffix.
Expand Down Expand Up @@ -306,7 +315,7 @@ impl CallPath {
.map(|&x| Ident::new_no_span(x.into()))
.collect(),
suffix: path.last().map(|&x| Ident::new_no_span(x.into())).unwrap(),
callpath_type: CallPathType::Resolved,
callpath_type: CallPathType::Full,
}
}

Expand All @@ -332,7 +341,7 @@ impl CallPath {
let new_callpath_type = match self.callpath_type {
CallPathType::RelativeToPackageRoot
| CallPathType::Ambiguous => CallPathType::Ambiguous,
CallPathType::Resolved => CallPathType::RelativeToPackageRoot,
CallPathType::Full => CallPathType::RelativeToPackageRoot,
};
CallPath {
prefixes: self.prefixes[1..self.prefixes.len()].to_vec(),
Expand Down Expand Up @@ -360,7 +369,7 @@ impl CallPath {
for mod_path in namespace.current_mod_path() {
res.prefixes.push(mod_path.clone())
}
res.callpath_type = CallPathType::Resolved;
res.callpath_type = CallPathType::Full;
res
}

Expand All @@ -373,7 +382,7 @@ impl CallPath {
/// and are left unchanged since `std` is a root of the package `std`.
pub fn to_fullpath(&self, _engines: &Engines, namespace: &Namespace) -> CallPath {
match self.callpath_type {
CallPathType::Resolved => self.clone(),
CallPathType::Full => self.clone(),
CallPathType::RelativeToPackageRoot => {
let mut prefixes = vec!();
for ident in self.prefixes.iter() {
Expand All @@ -382,7 +391,7 @@ impl CallPath {
Self {
prefixes,
suffix: self.suffix.clone(),
callpath_type: CallPathType::Resolved,
callpath_type: CallPathType::Full,
}
},
CallPathType::Ambiguous => {
Expand Down Expand Up @@ -429,7 +438,7 @@ impl CallPath {
// CallPath {
// prefixes: mod_path.clone(),
// suffix: self.suffix.clone(),
// callpath_type: CallPathType::Resolved,
// callpath_type: CallPathType::Full,
// }
// // synonym_prefixes.clone_from(&mod_path);
// // is_absolute = true;
Expand All @@ -439,7 +448,7 @@ impl CallPath {
CallPath {
prefixes: namespace.current_mod_path.clone(),
suffix: self.suffix.clone(),
callpath_type: CallPathType::Resolved,
callpath_type: CallPathType::Full,
}

// // let mut prefixes: Vec<Ident> = vec![];
Expand All @@ -463,7 +472,7 @@ impl CallPath {
// // CallPath {
// // prefixes,
// // suffix: self.suffix.clone(),
// // callpath_type: CallPathType::Resolved,
// // callpath_type: CallPathType::Full,
// // }
} else if namespace.current_module_has_submodule(&self.prefixes[0])
{
Expand All @@ -482,14 +491,14 @@ impl CallPath {
CallPath {
prefixes: namespace.prepend_module_path(&self.prefixes),
suffix: self.suffix.clone(),
callpath_type: CallPathType::Resolved,
callpath_type: CallPathType::Full,
}
} else {
// Fully qualified path
CallPath {
prefixes: self.prefixes.clone(),
suffix: self.suffix.clone(),
callpath_type: CallPathType::Resolved,
callpath_type: CallPathType::Full,
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion sway-core/src/language/ty/declaration/struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ pub struct StructAccessInfo {
impl StructAccessInfo {
pub fn get_info(engines: &Engines, struct_decl: &TyStructDecl, namespace: &Namespace) -> Self {
assert!(
matches!(struct_decl.call_path.callpath_type, CallPathType::Resolved),
matches!(struct_decl.call_path.callpath_type, CallPathType::Full),
"The call path of the struct declaration must always be fully resolved."
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl ty::TyExpression {
span: span.clone(),
}
.to_var_name(),
callpath_type: CallPathType::Resolved,
callpath_type: CallPathType::Full,
};
let mut method_name_binding = TypeBinding {
inner: MethodName::FromTrait {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ pub(crate) fn resolve_method_name(
}
path
},
CallPathType::Resolved => call_path.prefixes.clone(),
CallPathType::Full => call_path.prefixes.clone(),
CallPathType::Ambiguous => {
if ctx.namespace().current_module().submodules().contains_key(call_path.prefixes.first().unwrap().as_str()) {
ctx.namespace().prepend_module_path(&call_path.prefixes)
Expand Down
2 changes: 1 addition & 1 deletion sway-core/src/semantic_analysis/namespace/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ impl Root {
// .chain(&call_path.prefixes)
// .cloned()
// .collect();
assert!(matches!(call_path.callpath_type, CallPathType::Resolved));
assert!(matches!(call_path.callpath_type, CallPathType::Full));
self.resolve_symbol_and_mod_path(
handler,
engines,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2527,7 +2527,7 @@ fn op_call(
Ident::new_with_override("ops".into(), op_span.clone()),
],
suffix: Ident::new_with_override(name.into(), op_span.clone()),
callpath_type: CallPathType::Resolved,
callpath_type: CallPathType::Full,
},
},
type_arguments: TypeArgs::Regular(vec![]),
Expand Down
8 changes: 4 additions & 4 deletions sway-core/src/type_system/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,8 @@ impl PartialEqWithEngines for TypeInfo {
let l_decl = ctx.engines().de().get_enum(l_decl_ref);
let r_decl = ctx.engines().de().get_enum(r_decl_ref);
assert!(
matches!(l_decl.call_path.callpath_type, CallPathType::Resolved) &&
matches!(r_decl.call_path.callpath_type, CallPathType::Resolved),
matches!(l_decl.call_path.callpath_type, CallPathType::Full) &&
matches!(r_decl.call_path.callpath_type, CallPathType::Full),
"The call paths of the enum declarations must always be resolved."
);
l_decl.call_path == r_decl.call_path
Expand All @@ -354,8 +354,8 @@ impl PartialEqWithEngines for TypeInfo {
let l_decl = ctx.engines().de().get_struct(l_decl_ref);
let r_decl = ctx.engines().de().get_struct(r_decl_ref);
assert!(
matches!(l_decl.call_path.callpath_type, CallPathType::Resolved) &&
matches!(r_decl.call_path.callpath_type, CallPathType::Resolved),
matches!(l_decl.call_path.callpath_type, CallPathType::Full) &&
matches!(r_decl.call_path.callpath_type, CallPathType::Full),
"The call paths of the struct declarations must always be resolved."
);
l_decl.call_path == r_decl.call_path
Expand Down
8 changes: 4 additions & 4 deletions sway-core/src/type_system/unify/unify_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -708,8 +708,8 @@ impl<'a> UnifyCheck<'a> {

pub(crate) fn check_enums(&self, left: &TyEnumDecl, right: &TyEnumDecl) -> bool {
assert!(
matches!(left.call_path.callpath_type, CallPathType::Resolved) &&
matches!(right.call_path.callpath_type, CallPathType::Resolved),
matches!(left.call_path.callpath_type, CallPathType::Full) &&
matches!(right.call_path.callpath_type, CallPathType::Full),
"The call paths of the enum declarations must always be resolved."
);

Expand Down Expand Up @@ -769,8 +769,8 @@ impl<'a> UnifyCheck<'a> {

pub(crate) fn check_structs(&self, left: &TyStructDecl, right: &TyStructDecl) -> bool {
assert!(
matches!(left.call_path.callpath_type, CallPathType::Resolved) &&
matches!(right.call_path.callpath_type, CallPathType::Resolved),
matches!(left.call_path.callpath_type, CallPathType::Full) &&
matches!(right.call_path.callpath_type, CallPathType::Full),
"The call paths of the enum declarations must always be resolved."
);

Expand Down

0 comments on commit 512ce8a

Please sign in to comment.