Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Remove root_type_id from TypeInfo::Custom. #6676

Merged
merged 3 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions sway-core/src/language/parsed/expression/scrutinee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ impl Scrutinee {
let name = vec![TypeInfo::Custom {
qualified_call_path: struct_name.clone().into(),
type_arguments: None,
root_type_id: None,
}];
let fields = fields
.iter()
Expand All @@ -271,7 +270,6 @@ impl Scrutinee {
let name = vec![TypeInfo::Custom {
qualified_call_path: enum_name.clone().into(),
type_arguments: None,
root_type_id: None,
}];
let value = value.gather_approximate_typeinfo_dependencies();
[name, value].concat()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1358,7 +1358,6 @@ impl ty::TyExpression {
let type_info = TypeInfo::Custom {
qualified_call_path: qualified_call_path.clone(),
type_arguments: None,
root_type_id: None,
};

TypeBinding {
Expand Down Expand Up @@ -1491,7 +1490,6 @@ impl ty::TyExpression {
let type_info = type_name_to_type_info_opt(&type_name).unwrap_or(TypeInfo::Custom {
qualified_call_path: type_name.clone().into(),
type_arguments: None,
root_type_id: None,
});

let method_name_binding = TypeBinding {
Expand Down Expand Up @@ -1733,7 +1731,6 @@ impl ty::TyExpression {
type_name_to_type_info_opt(type_name).unwrap_or(TypeInfo::Custom {
qualified_call_path: type_name.clone().into(),
type_arguments: None,
root_type_id: None,
})
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,6 @@ pub(crate) fn type_check_method_application(
if let TypeInfo::Custom {
qualified_call_path,
type_arguments,
root_type_id: _,
} = &*type_engine.get(t.initial_type_id)
{
let mut subst_type_parameters = vec![];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,10 @@ pub(crate) fn struct_instantiation(
(_, true) => TypeInfo::Custom {
qualified_call_path: suffix.clone().into(),
type_arguments: None,
root_type_id: None,
},
(_, false) => TypeInfo::Custom {
qualified_call_path: suffix.clone().into(),
type_arguments: Some(type_arguments),
root_type_id: None,
},
};

Expand Down
3 changes: 0 additions & 3 deletions sway-core/src/semantic_analysis/namespace/trait_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1404,7 +1404,6 @@ impl TraitMap {
} else {
Some(suffix.args.to_vec())
},
root_type_id: None,
},
suffix.name.span().source_id(),
);
Expand All @@ -1431,7 +1430,6 @@ impl TraitMap {
} else {
Some(constraint_type_arguments.clone())
},
root_type_id: None,
},
constraint_trait_name.span().source_id(),
);
Expand Down Expand Up @@ -1472,7 +1470,6 @@ impl TraitMap {
if let TypeInfo::Custom {
qualified_call_path: _,
type_arguments: Some(type_arguments),
root_type_id: _,
} = &*type_engine.get(*constraint_type_id)
{
type_arguments_string = format!("<{}>", engines.help_out(type_arguments));
Expand Down
9 changes: 1 addition & 8 deletions sway-core/src/semantic_analysis/node_dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -791,21 +791,14 @@ impl Dependencies {
TypeInfo::Custom {
qualified_call_path: name,
type_arguments,
root_type_id,
} => {
self.deps
.insert(DependentSymbol::Symbol(name.clone().call_path.suffix));
let s = match type_arguments {
match type_arguments {
Some(type_arguments) => {
self.gather_from_type_arguments(engines, type_arguments)
}
None => self,
};
match root_type_id {
Some(root_type_id) => {
s.gather_from_typeinfo(engines, &engines.te().get(*root_type_id))
}
None => s,
}
}
TypeInfo::Tuple(elems) => self.gather_from_iter(elems.iter(), |deps, elem| {
Expand Down
1 change: 0 additions & 1 deletion sway-core/src/semantic_analysis/type_check_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,6 @@ impl<'a> TypeCheckContext<'a> {
if let TypeInfo::Custom {
qualified_call_path: call_path,
type_arguments,
root_type_id: _,
} = &*type_engine.get(as_trait)
{
qualified_call_path = Some(call_path.clone());
Expand Down
37 changes: 13 additions & 24 deletions sway-core/src/semantic_analysis/type_resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,31 +38,17 @@ pub fn resolve_type(
TypeInfo::Custom {
qualified_call_path,
type_arguments,
root_type_id,
} => {
let type_decl_opt = if let Some(root_type_id) = root_type_id {
resolve_call_path_and_root_type_id(
handler,
engines,
namespace.module(engines),
root_type_id,
None,
&qualified_call_path.clone().to_call_path(handler)?,
self_type,
)
.ok()
} else {
resolve_qualified_call_path(
handler,
engines,
namespace,
module_path,
&qualified_call_path,
self_type,
subst_ctx,
)
.ok()
};
let type_decl_opt = resolve_qualified_call_path(
handler,
engines,
namespace,
module_path,
&qualified_call_path,
self_type,
subst_ctx,
)
.ok();
type_decl_opt_to_type_id(
handler,
engines,
Expand Down Expand Up @@ -368,6 +354,9 @@ pub fn decl_to_type_info(
}
(*engines.te().get(type_decl.ty.clone().unwrap().type_id)).clone()
}
ty::TyDecl::GenericTypeForFunctionScope(decl) => {
(*engines.te().get(decl.type_id)).clone()
}
_ => {
return Err(handler.emit_err(CompileError::SymbolNotFound {
name: symbol.clone(),
Expand Down
16 changes: 1 addition & 15 deletions sway-core/src/transform/to_parsed_lang/convert_parse_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1260,7 +1260,6 @@ fn generic_params_opt_to_type_parameters_with_parent(
TypeInfo::Custom {
qualified_call_path: ident.clone().into(),
type_arguments: None,
root_type_id: None,
},
ident.span().source_id(),
);
Expand Down Expand Up @@ -4341,7 +4340,6 @@ fn ty_to_type_parameter(
TypeInfo::Custom {
qualified_call_path: name_ident.clone().into(),
type_arguments: None,
root_type_id: None,
},
name_ident.span().source_id(),
);
Expand Down Expand Up @@ -4625,23 +4623,12 @@ fn path_type_to_type_info(
}

if !suffix.is_empty() {
let (mut call_path, type_arguments) = path_type_to_call_path_and_type_arguments(
let (call_path, type_arguments) = path_type_to_call_path_and_type_arguments(
context, handler, engines, path_type,
)?;

let mut root_type_id = None;
if name.as_str() == "Self" {
call_path.call_path.prefixes.remove(0);
root_type_id = Some(engines.te().insert(
engines,
type_info,
name.span().source_id(),
));
}
TypeInfo::Custom {
qualified_call_path: call_path,
type_arguments: Some(type_arguments),
root_type_id,
}
} else {
type_info
Expand Down Expand Up @@ -4686,7 +4673,6 @@ fn path_type_to_type_info(
TypeInfo::Custom {
qualified_call_path: call_path,
type_arguments: Some(type_arguments),
root_type_id: None,
}
}
}
Expand Down
1 change: 0 additions & 1 deletion sway-core/src/type_system/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,6 @@ impl TypeId {
TypeInfo::Custom {
qualified_call_path: _,
type_arguments,
root_type_id: _,
} => {
if let Some(type_arguments) = type_arguments {
for type_arg in type_arguments {
Expand Down
18 changes: 1 addition & 17 deletions sway-core/src/type_system/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,6 @@ pub enum TypeInfo {
Custom {
qualified_call_path: QualifiedCallPath,
type_arguments: Option<Vec<TypeArgument>>,
/// When root_type_id contains some type id then the call path applies
/// to the specified root_type_id as root.
/// This is used by associated types which should produce a TypeInfo::Custom
/// such as Self::T.
root_type_id: Option<TypeId>,
},
B256,
/// This means that specific type of a number is not yet known. It will be
Expand Down Expand Up @@ -243,11 +238,9 @@ impl HashWithEngines for TypeInfo {
TypeInfo::Custom {
qualified_call_path: call_path,
type_arguments,
root_type_id,
} => {
call_path.hash(state, engines);
type_arguments.as_deref().hash(state, engines);
root_type_id.hash(state);
}
TypeInfo::Storage { fields } => {
fields.hash(state, engines);
Expand Down Expand Up @@ -325,20 +318,17 @@ impl PartialEqWithEngines for TypeInfo {
Self::Custom {
qualified_call_path: l_name,
type_arguments: l_type_args,
root_type_id: l_root_type_id,
},
Self::Custom {
qualified_call_path: r_name,
type_arguments: r_type_args,
root_type_id: r_root_type_id,
},
) => {
l_name.call_path.suffix == r_name.call_path.suffix
&& l_name
.qualified_path_root
.eq(&r_name.qualified_path_root, ctx)
&& l_type_args.as_deref().eq(&r_type_args.as_deref(), ctx)
&& l_root_type_id.eq(r_root_type_id)
}
(Self::StringSlice, Self::StringSlice) => true,
(Self::StringArray(l), Self::StringArray(r)) => l.val() == r.val(),
Expand Down Expand Up @@ -477,12 +467,10 @@ impl OrdWithEngines for TypeInfo {
Self::Custom {
qualified_call_path: l_call_path,
type_arguments: l_type_args,
root_type_id: l_root_type_id,
},
Self::Custom {
qualified_call_path: r_call_path,
type_arguments: r_type_args,
root_type_id: r_root_type_id,
},
) => l_call_path
.call_path
Expand All @@ -493,8 +481,7 @@ impl OrdWithEngines for TypeInfo {
.qualified_path_root
.cmp(&r_call_path.qualified_path_root, ctx)
})
.then_with(|| l_type_args.as_deref().cmp(&r_type_args.as_deref(), ctx))
.then_with(|| l_root_type_id.cmp(r_root_type_id)),
.then_with(|| l_type_args.as_deref().cmp(&r_type_args.as_deref(), ctx)),
(Self::StringArray(l), Self::StringArray(r)) => l.val().cmp(&r.val()),
(Self::UnsignedInteger(l), Self::UnsignedInteger(r)) => l.cmp(r),
(Self::Enum(l_decl_id), Self::Enum(r_decl_id)) => {
Expand Down Expand Up @@ -874,7 +861,6 @@ impl TypeInfo {
qualified_path_root: None,
},
type_arguments: None,
root_type_id: None,
}
}

Expand Down Expand Up @@ -1286,7 +1272,6 @@ impl TypeInfo {
TypeInfo::Custom {
qualified_call_path: call_path,
type_arguments: other_type_arguments,
root_type_id,
} => {
if other_type_arguments.is_some() {
Err(handler
Expand All @@ -1295,7 +1280,6 @@ impl TypeInfo {
let type_info = TypeInfo::Custom {
qualified_call_path: call_path,
type_arguments: Some(type_arguments),
root_type_id,
};
Ok(type_info)
}
Expand Down
15 changes: 1 addition & 14 deletions sway-core/src/type_system/unify/unify_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,12 +269,10 @@ impl<'a> UnifyCheck<'a> {
Custom {
qualified_call_path: l_name,
type_arguments: l_type_args,
root_type_id: l_root_type_id,
},
Custom {
qualified_call_path: r_name,
type_arguments: r_type_args,
root_type_id: r_root_type_id,
},
) => {
let l_types = l_type_args
Expand All @@ -289,16 +287,6 @@ impl<'a> UnifyCheck<'a> {
.iter()
.map(|x| x.type_id)
.collect::<Vec<_>>();
let l_root_type_ids = if let Some(l_root_type_id) = l_root_type_id {
vec![*l_root_type_id]
} else {
vec![]
};
let r_root_type_ids = if let Some(r_root_type_id) = r_root_type_id {
vec![*r_root_type_id]
} else {
vec![]
};
let same_qualified_path_root = match (
l_name.qualified_path_root.clone(),
r_name.qualified_path_root.clone(),
Expand All @@ -318,8 +306,7 @@ impl<'a> UnifyCheck<'a> {

return l_name.call_path.suffix == r_name.call_path.suffix
&& same_qualified_path_root
&& self.check_multiple(&l_types, &r_types)
&& self.check_multiple(&l_root_type_ids, &r_root_type_ids);
&& self.check_multiple(&l_types, &r_types);
}
(Enum(l_decl_ref), Enum(r_decl_ref)) => {
let l_decl = self.engines.de().get_enum(l_decl_ref);
Expand Down
2 changes: 0 additions & 2 deletions sway-lsp/src/traverse/parsed_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,6 @@ impl Parse for ParsedDeclId<ImplSelfOrTrait> {
if let TypeInfo::Custom {
qualified_call_path,
type_arguments,
root_type_id: _,
} = &&*ctx
.engines
.te()
Expand Down Expand Up @@ -1099,7 +1098,6 @@ fn collect_type_info_token(ctx: &ParseContext, type_info: &TypeInfo, type_span:
TypeInfo::Custom {
qualified_call_path,
type_arguments,
root_type_id: _,
} => {
collect_qualified_path_root(ctx, qualified_call_path.qualified_path_root.clone());
let ident = qualified_call_path.call_path.suffix.clone();
Expand Down
1 change: 0 additions & 1 deletion sway-lsp/src/traverse/typed_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1321,7 +1321,6 @@ fn collect_type_id(
TypeInfo::Custom {
type_arguments,
qualified_call_path: name,
root_type_id: _,
} => {
collect_qualified_path_root(ctx, name.qualified_path_root.clone());
if let Some(token) = ctx
Expand Down
Loading