diff --git a/sway-core/src/language/parsed/expression/scrutinee.rs b/sway-core/src/language/parsed/expression/scrutinee.rs index 20384fb446b..e700c60e7d8 100644 --- a/sway-core/src/language/parsed/expression/scrutinee.rs +++ b/sway-core/src/language/parsed/expression/scrutinee.rs @@ -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() @@ -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() diff --git a/sway-core/src/semantic_analysis/ast_node/expression/typed_expression.rs b/sway-core/src/semantic_analysis/ast_node/expression/typed_expression.rs index ac4941bcb70..51672758fba 100644 --- a/sway-core/src/semantic_analysis/ast_node/expression/typed_expression.rs +++ b/sway-core/src/semantic_analysis/ast_node/expression/typed_expression.rs @@ -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 { @@ -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 { @@ -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, }) }); diff --git a/sway-core/src/semantic_analysis/ast_node/expression/typed_expression/method_application.rs b/sway-core/src/semantic_analysis/ast_node/expression/typed_expression/method_application.rs index 2619ab21664..3c118c43536 100644 --- a/sway-core/src/semantic_analysis/ast_node/expression/typed_expression/method_application.rs +++ b/sway-core/src/semantic_analysis/ast_node/expression/typed_expression/method_application.rs @@ -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![]; diff --git a/sway-core/src/semantic_analysis/ast_node/expression/typed_expression/struct_instantiation.rs b/sway-core/src/semantic_analysis/ast_node/expression/typed_expression/struct_instantiation.rs index 23ff00f7894..1d84a623fbd 100644 --- a/sway-core/src/semantic_analysis/ast_node/expression/typed_expression/struct_instantiation.rs +++ b/sway-core/src/semantic_analysis/ast_node/expression/typed_expression/struct_instantiation.rs @@ -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, }, }; diff --git a/sway-core/src/semantic_analysis/namespace/trait_map.rs b/sway-core/src/semantic_analysis/namespace/trait_map.rs index 1fb39cf2982..6b966d16b5a 100644 --- a/sway-core/src/semantic_analysis/namespace/trait_map.rs +++ b/sway-core/src/semantic_analysis/namespace/trait_map.rs @@ -1404,7 +1404,6 @@ impl TraitMap { } else { Some(suffix.args.to_vec()) }, - root_type_id: None, }, suffix.name.span().source_id(), ); @@ -1431,7 +1430,6 @@ impl TraitMap { } else { Some(constraint_type_arguments.clone()) }, - root_type_id: None, }, constraint_trait_name.span().source_id(), ); @@ -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)); diff --git a/sway-core/src/semantic_analysis/node_dependencies.rs b/sway-core/src/semantic_analysis/node_dependencies.rs index c34feeab4e6..e0a5b5b3f0b 100644 --- a/sway-core/src/semantic_analysis/node_dependencies.rs +++ b/sway-core/src/semantic_analysis/node_dependencies.rs @@ -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| { diff --git a/sway-core/src/semantic_analysis/type_check_context.rs b/sway-core/src/semantic_analysis/type_check_context.rs index c0340715571..4a7e6ccf852 100644 --- a/sway-core/src/semantic_analysis/type_check_context.rs +++ b/sway-core/src/semantic_analysis/type_check_context.rs @@ -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()); diff --git a/sway-core/src/semantic_analysis/type_resolve.rs b/sway-core/src/semantic_analysis/type_resolve.rs index f2498364acf..e4c676fda1e 100644 --- a/sway-core/src/semantic_analysis/type_resolve.rs +++ b/sway-core/src/semantic_analysis/type_resolve.rs @@ -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, @@ -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(), diff --git a/sway-core/src/transform/to_parsed_lang/convert_parse_tree.rs b/sway-core/src/transform/to_parsed_lang/convert_parse_tree.rs index eda5d23a533..e40c9148fda 100644 --- a/sway-core/src/transform/to_parsed_lang/convert_parse_tree.rs +++ b/sway-core/src/transform/to_parsed_lang/convert_parse_tree.rs @@ -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(), ); @@ -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(), ); @@ -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 @@ -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, } } } diff --git a/sway-core/src/type_system/id.rs b/sway-core/src/type_system/id.rs index 2f5c0ec0ed8..7a7480fe838 100644 --- a/sway-core/src/type_system/id.rs +++ b/sway-core/src/type_system/id.rs @@ -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 { diff --git a/sway-core/src/type_system/info.rs b/sway-core/src/type_system/info.rs index d4bcae5b8bf..29767d81fc0 100644 --- a/sway-core/src/type_system/info.rs +++ b/sway-core/src/type_system/info.rs @@ -152,11 +152,6 @@ pub enum TypeInfo { Custom { qualified_call_path: QualifiedCallPath, type_arguments: Option>, - /// 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, }, B256, /// This means that specific type of a number is not yet known. It will be @@ -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); @@ -325,12 +318,10 @@ 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 @@ -338,7 +329,6 @@ impl PartialEqWithEngines for TypeInfo { .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(), @@ -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 @@ -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)) => { @@ -874,7 +861,6 @@ impl TypeInfo { qualified_path_root: None, }, type_arguments: None, - root_type_id: None, } } @@ -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 @@ -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) } diff --git a/sway-core/src/type_system/unify/unify_check.rs b/sway-core/src/type_system/unify/unify_check.rs index 7479a4142ac..b1e1a9db62a 100644 --- a/sway-core/src/type_system/unify/unify_check.rs +++ b/sway-core/src/type_system/unify/unify_check.rs @@ -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 @@ -289,16 +287,6 @@ impl<'a> UnifyCheck<'a> { .iter() .map(|x| x.type_id) .collect::>(); - 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(), @@ -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); diff --git a/sway-lsp/src/traverse/parsed_tree.rs b/sway-lsp/src/traverse/parsed_tree.rs index 880915f915b..04e7750fa69 100644 --- a/sway-lsp/src/traverse/parsed_tree.rs +++ b/sway-lsp/src/traverse/parsed_tree.rs @@ -798,7 +798,6 @@ impl Parse for ParsedDeclId { if let TypeInfo::Custom { qualified_call_path, type_arguments, - root_type_id: _, } = &&*ctx .engines .te() @@ -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(); diff --git a/sway-lsp/src/traverse/typed_tree.rs b/sway-lsp/src/traverse/typed_tree.rs index 3c6098cc43d..0c2745c6f21 100644 --- a/sway-lsp/src/traverse/typed_tree.rs +++ b/sway-lsp/src/traverse/typed_tree.rs @@ -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