From 395d362c985aed01dd13afe5016e822ef3fb0305 Mon Sep 17 00:00:00 2001 From: sasa630 Date: Thu, 6 Mar 2025 01:50:52 +0200 Subject: [PATCH] use implicit insert and remove insert_type method from the context object (#3395) gcc/rust/ChangeLog: * typecheck/rust-typecheck-context.cc (TypeCheckContext::insert_type): Remove. * typecheck/rust-hir-type-check.h: Remove declaration of insert_type method. * typecheck/rust-tyty-subst.cc: Replace all insert_type with insert_implicit_type. * typecheck/rust-tyty-util.cc: Likewise. * typecheck/rust-tyty.cc: Likewise. * typecheck/rust-substitution-mapper.cc: Likewise. * typecheck/rust-hir-trait-resolve.cc: Likewise. * typecheck/rust-hir-type-check-base.cc: Likewise. * typecheck/rust-hir-type-check-enumitem.cc: Likewise. * typecheck/rust-hir-type-check-expr.cc: use Likewise. * typecheck/rust-hir-type-check-implitem.cc: Likewise. * typecheck/rust-hir-type-check-item.cc: use Likewise. * typecheck/rust-hir-type-check-pattern.cc: Likewise. * typecheck/rust-hir-type-check-stmt.cc: Likewise. * typecheck/rust-hir-type-check-struct.cc: Likewise. * typecheck/rust-hir-type-check-type.cc: Likewise. * typecheck/rust-hir-type-check.cc: Likewise. * typecheck/rust-unify.cc: Likewise. Signed-off-by: sasa630 --- gcc/rust/typecheck/rust-hir-trait-resolve.cc | 5 +-- .../typecheck/rust-hir-type-check-base.cc | 12 ++++--- .../typecheck/rust-hir-type-check-enumitem.cc | 15 ++++---- .../typecheck/rust-hir-type-check-expr.cc | 13 ++++--- .../typecheck/rust-hir-type-check-implitem.cc | 28 +++++++++------ .../typecheck/rust-hir-type-check-item.cc | 35 ++++++++++++------- .../typecheck/rust-hir-type-check-pattern.cc | 9 +++-- .../typecheck/rust-hir-type-check-stmt.cc | 3 +- .../typecheck/rust-hir-type-check-struct.cc | 3 +- .../typecheck/rust-hir-type-check-type.cc | 6 ++-- gcc/rust/typecheck/rust-hir-type-check.cc | 12 ++++--- gcc/rust/typecheck/rust-hir-type-check.h | 2 -- .../typecheck/rust-substitution-mapper.cc | 11 +++--- gcc/rust/typecheck/rust-typecheck-context.cc | 15 +------- gcc/rust/typecheck/rust-tyty-subst.cc | 8 +---- gcc/rust/typecheck/rust-tyty-util.cc | 11 ++---- gcc/rust/typecheck/rust-tyty.cc | 6 +--- gcc/rust/typecheck/rust-unify.cc | 3 +- 18 files changed, 98 insertions(+), 99 deletions(-) diff --git a/gcc/rust/typecheck/rust-hir-trait-resolve.cc b/gcc/rust/typecheck/rust-hir-trait-resolve.cc index ceb5b7a91b22..aad2dfb2f272 100644 --- a/gcc/rust/typecheck/rust-hir-trait-resolve.cc +++ b/gcc/rust/typecheck/rust-hir-trait-resolve.cc @@ -219,7 +219,8 @@ TraitResolver::resolve_trait (HIR::Trait *trait_reference) bool apply_sized = !is_self; auto param_type = TypeResolveGenericParam::Resolve (*generic_param, apply_sized); - context->insert_type (generic_param->get_mappings (), param_type); + context->insert_implicit_type ( + generic_param->get_mappings ().get_hirid (), param_type); substitutions.push_back ( TyTy::SubstitutionParamMapping (typaram, param_type)); @@ -361,7 +362,7 @@ TraitItemReference::resolve_item (HIR::TraitItemType &type) = new TyTy::PlaceholderType (type.get_name ().as_string (), type.get_mappings ().get_defid (), type.get_mappings ().get_hirid ()); - context->insert_type (type.get_mappings (), ty); + context->insert_implicit_type (type.get_mappings ().get_hirid (), ty); } void diff --git a/gcc/rust/typecheck/rust-hir-type-check-base.cc b/gcc/rust/typecheck/rust-hir-type-check-base.cc index b6d2f035ad44..9df20ce40710 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-base.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-base.cc @@ -263,7 +263,8 @@ TypeCheckBase::resolve_literal (const Analysis::NodeMapping &expr_mappings, TyTy::BaseType *expected_ty = nullptr; ok = context->lookup_builtin ("usize", &expected_ty); rust_assert (ok); - context->insert_type (capacity_mapping, expected_ty); + context->insert_implicit_type (capacity_mapping.get_hirid (), + expected_ty); Analysis::NodeMapping array_mapping (crate_num, UNKNOWN_NODEID, mappings.get_next_hir_id ( @@ -274,7 +275,7 @@ TypeCheckBase::resolve_literal (const Analysis::NodeMapping &expr_mappings, = new TyTy::ArrayType (array_mapping.get_hirid (), locus, *literal_capacity, TyTy::TyVar (u8->get_ref ())); - context->insert_type (array_mapping, array); + context->insert_implicit_type (array_mapping.get_hirid (), array); infered = new TyTy::ReferenceType (expr_mappings.get_hirid (), TyTy::TyVar (array->get_ref ()), @@ -401,14 +402,15 @@ TypeCheckBase::resolve_generic_params ( param.get_locus ()); } - context->insert_type (generic_param->get_mappings (), - specified_type); + context->insert_implicit_type ( + generic_param->get_mappings ().get_hirid (), specified_type); } break; case HIR::GenericParam::GenericKind::TYPE: { auto param_type = TypeResolveGenericParam::Resolve (*generic_param); - context->insert_type (generic_param->get_mappings (), param_type); + context->insert_implicit_type ( + generic_param->get_mappings ().get_hirid (), param_type); substitutions.push_back (TyTy::SubstitutionParamMapping ( static_cast (*generic_param), param_type)); diff --git a/gcc/rust/typecheck/rust-hir-type-check-enumitem.cc b/gcc/rust/typecheck/rust-hir-type-check-enumitem.cc index 527c8dfbbeac..fde8322b029d 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-enumitem.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-enumitem.cc @@ -77,7 +77,7 @@ TypeCheckEnumItem::visit (HIR::EnumItem &item) TyTy::BaseType *isize = nullptr; bool ok = context->lookup_builtin ("isize", &isize); rust_assert (ok); - context->insert_type (mapping, isize); + context->insert_implicit_type (mapping.get_hirid (), isize); tl::optional canonical_path; @@ -117,7 +117,8 @@ TypeCheckEnumItem::visit (HIR::EnumItemDiscriminant &item) TyTy::ISizeType *expected_ty = new TyTy::ISizeType (discriminant.get_mappings ().get_hirid ()); - context->insert_type (discriminant.get_mappings (), expected_ty); + context->insert_implicit_type (discriminant.get_mappings ().get_hirid (), + expected_ty); unify_site (item.get_mappings ().get_hirid (), TyTy::TyWithLocation (expected_ty), @@ -166,7 +167,8 @@ TypeCheckEnumItem::visit (HIR::EnumItemTuple &item) std::to_string (idx), field_type, field.get_locus ()); fields.push_back (ty_field); - context->insert_type (field.get_mappings (), ty_field->get_field_type ()); + context->insert_implicit_type (field.get_mappings ().get_hirid (), + ty_field->get_field_type ()); idx++; } @@ -183,7 +185,7 @@ TypeCheckEnumItem::visit (HIR::EnumItemTuple &item) TyTy::BaseType *isize = nullptr; bool ok = context->lookup_builtin ("isize", &isize); rust_assert (ok); - context->insert_type (mapping, isize); + context->insert_implicit_type (mapping.get_hirid (), isize); tl::optional canonical_path; @@ -227,7 +229,8 @@ TypeCheckEnumItem::visit (HIR::EnumItemStruct &item) field.get_field_name ().as_string (), field_type, field.get_locus ()); fields.push_back (ty_field); - context->insert_type (field.get_mappings (), ty_field->get_field_type ()); + context->insert_implicit_type (field.get_mappings ().get_hirid (), + ty_field->get_field_type ()); } Analysis::NodeMapping mapping (item.get_mappings ().get_crate_num (), @@ -243,7 +246,7 @@ TypeCheckEnumItem::visit (HIR::EnumItemStruct &item) TyTy::BaseType *isize = nullptr; bool ok = context->lookup_builtin ("isize", &isize); rust_assert (ok); - context->insert_type (mapping, isize); + context->insert_implicit_type (mapping.get_hirid (), isize); tl::optional canonical_path; diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc b/gcc/rust/typecheck/rust-hir-type-check-expr.cc index 8d000113c082..591066188391 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc @@ -51,7 +51,8 @@ TypeCheckExpr::Resolve (HIR::Expr &expr) auto ref = expr.get_mappings ().get_hirid (); resolver.infered->set_ref (ref); - resolver.context->insert_type (expr.get_mappings (), resolver.infered); + resolver.context->insert_implicit_type (expr.get_mappings ().get_hirid (), + resolver.infered); return resolver.infered; } @@ -1007,8 +1008,9 @@ TypeCheckExpr::visit (HIR::ArrayExpr &expr) TyTy::BaseType *expected_ty = nullptr; bool ok = context->lookup_builtin ("usize", &expected_ty); rust_assert (ok); - context->insert_type (elems.get_num_copies_expr ().get_mappings (), - expected_ty); + context->insert_implicit_type ( + elems.get_num_copies_expr ().get_mappings ().get_hirid (), + expected_ty); unify_site (expr.get_mappings ().get_hirid (), TyTy::TyWithLocation (expected_ty), @@ -1056,7 +1058,7 @@ TypeCheckExpr::visit (HIR::ArrayExpr &expr) TyTy::BaseType *expected_ty = nullptr; bool ok = context->lookup_builtin ("usize", &expected_ty); rust_assert (ok); - context->insert_type (mapping, expected_ty); + context->insert_implicit_type (mapping.get_hirid (), expected_ty); } break; } @@ -1314,7 +1316,8 @@ TypeCheckExpr::visit (HIR::MethodCallExpr &expr) } // store the expected fntype - context->insert_type (expr.get_method_name ().get_mappings (), lookup); + context->insert_implicit_type ( + expr.get_method_name ().get_mappings ().get_hirid (), lookup); if (flag_name_resolution_2_0) { diff --git a/gcc/rust/typecheck/rust-hir-type-check-implitem.cc b/gcc/rust/typecheck/rust-hir-type-check-implitem.cc index 31164c1358a0..557470bdf489 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-implitem.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-implitem.cc @@ -61,7 +61,8 @@ TypeCheckTopLevelExternItem::visit (HIR::ExternalStaticItem &item) { TyTy::BaseType *actual_type = TypeCheckType::Resolve (item.get_item_type ()); - context->insert_type (item.get_mappings (), actual_type); + context->insert_implicit_type (item.get_mappings ().get_hirid (), + actual_type); resolved = actual_type; } @@ -91,8 +92,8 @@ TypeCheckTopLevelExternItem::visit (HIR::ExternalFunctionItem &function) case HIR::GenericParam::GenericKind::TYPE: { auto param_type = TypeResolveGenericParam::Resolve (*generic_param); - context->insert_type (generic_param->get_mappings (), - param_type); + context->insert_implicit_type ( + generic_param->get_mappings ().get_hirid (), param_type); substitutions.push_back (TyTy::SubstitutionParamMapping ( static_cast (*generic_param), param_type)); @@ -149,7 +150,8 @@ TypeCheckTopLevelExternItem::visit (HIR::ExternalFunctionItem &function) params.push_back (TyTy::FnParam (std::move (param_pattern), param_tyty)); - context->insert_type (param.get_mappings (), param_tyty); + context->insert_implicit_type (param.get_mappings ().get_hirid (), + param_tyty); // FIXME do we need error checking for patterns here? // see https://github.com/Rust-GCC/gccrs/issues/995 @@ -181,7 +183,7 @@ TypeCheckTopLevelExternItem::visit (HIR::ExternalFunctionItem &function) context->get_lifetime_resolver ().get_num_bound_regions ()), region_constraints); - context->insert_type (function.get_mappings (), fnType); + context->insert_implicit_type (function.get_mappings ().get_hirid (), fnType); resolved = fnType; } @@ -450,7 +452,8 @@ TypeCheckImplItem::visit (HIR::Function &function) } } - context->insert_type (self_param.get_mappings (), self_type); + context->insert_implicit_type (self_param.get_mappings ().get_hirid (), + self_type); params.push_back (TyTy::FnParam (std::move (self_pattern), self_type)); } @@ -459,7 +462,8 @@ TypeCheckImplItem::visit (HIR::Function &function) // get the name as well required for later on auto param_tyty = TypeCheckType::Resolve (param.get_type ()); - context->insert_type (param.get_mappings (), param_tyty); + context->insert_implicit_type (param.get_mappings ().get_hirid (), + param_tyty); TypeCheckPattern::Resolve (param.get_param_name (), param_tyty); params.push_back ( @@ -496,7 +500,7 @@ TypeCheckImplItem::visit (HIR::Function &function) context->get_lifetime_resolver ().get_num_bound_regions ()), region_constraints); - context->insert_type (function.get_mappings (), fnType); + context->insert_implicit_type (function.get_mappings ().get_hirid (), fnType); result = fnType; // need to get the return type from this @@ -530,7 +534,8 @@ TypeCheckImplItem::visit (HIR::ConstantItem &constant) TyTy::TyWithLocation (type, constant.get_type ().get_locus ()), TyTy::TyWithLocation (expr_type, constant.get_expr ().get_locus ()), constant.get_locus ()); - context->insert_type (constant.get_mappings (), unified); + context->insert_implicit_type (constant.get_mappings ().get_hirid (), + unified); result = unified; } @@ -545,7 +550,8 @@ TypeCheckImplItem::visit (HIR::TypeAlias &alias) TyTy::BaseType *actual_type = TypeCheckType::Resolve (alias.get_type_aliased ()); - context->insert_type (alias.get_mappings (), actual_type); + context->insert_implicit_type (alias.get_mappings ().get_hirid (), + actual_type); result = actual_type; TyTy::RegionConstraints region_constraints; for (auto &where_clause_item : alias.get_where_clause ().get_items ()) @@ -688,7 +694,7 @@ TypeCheckImplItemWithTrait::visit (HIR::TypeAlias &type) raw_trait_item->get_mappings ().get_defid (), substitutions); - context->insert_type (type.get_mappings (), projection); + context->insert_implicit_type (type.get_mappings ().get_hirid (), projection); raw_trait_item->associated_type_set (projection); } diff --git a/gcc/rust/typecheck/rust-hir-type-check-item.cc b/gcc/rust/typecheck/rust-hir-type-check-item.cc index 5a427c5ef480..c19613551f4d 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-item.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-item.cc @@ -153,7 +153,8 @@ TypeCheckItem::visit (HIR::TypeAlias &alias) TyTy::BaseType *actual_type = TypeCheckType::Resolve (alias.get_type_aliased ()); - context->insert_type (alias.get_mappings (), actual_type); + context->insert_implicit_type (alias.get_mappings ().get_hirid (), + actual_type); TyTy::RegionConstraints region_constraints; for (auto &where_clause_item : alias.get_where_clause ().get_items ()) @@ -189,7 +190,8 @@ TypeCheckItem::visit (HIR::TupleStruct &struct_decl) std::to_string (idx), field_type, field.get_locus ()); fields.push_back (ty_field); - context->insert_type (field.get_mappings (), ty_field->get_field_type ()); + context->insert_implicit_type (field.get_mappings ().get_hirid (), + ty_field->get_field_type ()); idx++; } @@ -241,7 +243,9 @@ TypeCheckItem::visit (HIR::TupleStruct &struct_decl) context->get_lifetime_resolver ().get_num_bound_regions ()), region_constraints); - context->insert_type (struct_decl.get_mappings (), type); + context->insert_implicit_type (struct_decl.get_mappings ().get_hirid (), + type); + infered = type; context->get_variance_analysis_ctx ().add_type_constraints (*type); @@ -272,7 +276,8 @@ TypeCheckItem::visit (HIR::StructStruct &struct_decl) field.get_field_name ().as_string (), field_type, field.get_locus ()); fields.push_back (ty_field); - context->insert_type (field.get_mappings (), ty_field->get_field_type ()); + context->insert_implicit_type (field.get_mappings ().get_hirid (), + ty_field->get_field_type ()); } auto path = CanonicalPath::create_empty (); @@ -323,7 +328,8 @@ TypeCheckItem::visit (HIR::StructStruct &struct_decl) context->get_lifetime_resolver ().get_num_bound_regions ()), region_constraints); - context->insert_type (struct_decl.get_mappings (), type); + context->insert_implicit_type (struct_decl.get_mappings ().get_hirid (), + type); infered = type; context->get_variance_analysis_ctx ().add_type_constraints (*type); @@ -382,7 +388,7 @@ TypeCheckItem::visit (HIR::Enum &enum_decl) TyTy::ADTType::ADTKind::ENUM, std::move (variants), std::move (substitutions), repr); - context->insert_type (enum_decl.get_mappings (), type); + context->insert_implicit_type (enum_decl.get_mappings ().get_hirid (), type); infered = type; context->get_variance_analysis_ctx ().add_type_constraints (*type); @@ -412,8 +418,8 @@ TypeCheckItem::visit (HIR::Union &union_decl) variant.get_field_name ().as_string (), variant_type, variant.get_locus ()); fields.push_back (ty_variant); - context->insert_type (variant.get_mappings (), - ty_variant->get_field_type ()); + context->insert_implicit_type (variant.get_mappings ().get_hirid (), + ty_variant->get_field_type ()); } // get the path @@ -453,7 +459,7 @@ TypeCheckItem::visit (HIR::Union &union_decl) TyTy::ADTType::ADTKind::UNION, std::move (variants), std::move (substitutions)); - context->insert_type (union_decl.get_mappings (), type); + context->insert_implicit_type (union_decl.get_mappings ().get_hirid (), type); infered = type; context->get_variance_analysis_ctx ().add_type_constraints (*type); @@ -471,7 +477,7 @@ TypeCheckItem::visit (HIR::StaticItem &var) TyTy::TyWithLocation (expr_type, var.get_expr ().get_locus ()), var.get_locus ()); - context->insert_type (var.get_mappings (), unified); + context->insert_implicit_type (var.get_mappings ().get_hirid (), unified); infered = unified; } @@ -486,7 +492,8 @@ TypeCheckItem::visit (HIR::ConstantItem &constant) TyTy::TyWithLocation (type, constant.get_type ().get_locus ()), TyTy::TyWithLocation (expr_type, constant.get_expr ().get_locus ()), constant.get_locus ()); - context->insert_type (constant.get_mappings (), unified); + context->insert_implicit_type (constant.get_mappings ().get_hirid (), + unified); infered = unified; } @@ -585,7 +592,8 @@ TypeCheckItem::visit (HIR::Function &function) { // get the name as well required for later on auto param_tyty = TypeCheckType::Resolve (param.get_type ()); - context->insert_type (param.get_mappings (), param_tyty); + context->insert_implicit_type (param.get_mappings ().get_hirid (), + param_tyty); TypeCheckPattern::Resolve (param.get_param_name (), param_tyty); params.push_back ( TyTy::FnParam (param.get_param_name ().clone_pattern (), param_tyty)); @@ -622,7 +630,8 @@ TypeCheckItem::visit (HIR::Function &function) context->get_lifetime_resolver ().get_num_bound_regions ()), region_constraints); - context->insert_type (function.get_mappings (), fn_type); + context->insert_implicit_type (function.get_mappings ().get_hirid (), + fn_type); // need to get the return type from this TyTy::FnType *resolved_fn_type = fn_type; diff --git a/gcc/rust/typecheck/rust-hir-type-check-pattern.cc b/gcc/rust/typecheck/rust-hir-type-check-pattern.cc index bc816fd49ab4..0307b306daf3 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-pattern.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-pattern.cc @@ -41,7 +41,8 @@ TypeCheckPattern::Resolve (HIR::Pattern &pattern, TyTy::BaseType *parent) if (resolver.infered == nullptr) return new TyTy::ErrorType (pattern.get_mappings ().get_hirid ()); - resolver.context->insert_type (pattern.get_mappings (), resolver.infered); + resolver.context->insert_implicit_type (pattern.get_mappings ().get_hirid (), + resolver.infered); return resolver.infered; } @@ -246,7 +247,8 @@ TypeCheckPattern::visit (HIR::TupleStructPattern &pattern) TyTy::BaseType *fty = field->get_field_type (); // setup the type on this pattern type - context->insert_type (pattern->get_mappings (), fty); + context->insert_implicit_type ( + pattern->get_mappings ().get_hirid (), fty); TypeCheckPattern::Resolve (*pattern, fty); } } @@ -357,7 +359,8 @@ TypeCheckPattern::visit (HIR::StructPattern &pattern) // setup the type on this pattern TyTy::BaseType *fty = field->get_field_type (); - context->insert_type (ident.get_mappings (), fty); + context->insert_implicit_type (ident.get_mappings ().get_hirid (), + fty); } break; } diff --git a/gcc/rust/typecheck/rust-hir-type-check-stmt.cc b/gcc/rust/typecheck/rust-hir-type-check-stmt.cc index 87a7733848a1..8309496e9eb4 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-stmt.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-stmt.cc @@ -67,7 +67,8 @@ TypeCheckStmt::visit (HIR::ConstantItem &constant) TyTy::TyWithLocation (type, constant.get_type ().get_locus ()), TyTy::TyWithLocation (expr_type, constant.get_expr ().get_locus ()), constant.get_locus ()); - context->insert_type (constant.get_mappings (), infered); + context->insert_implicit_type (constant.get_mappings ().get_hirid (), + infered); } void diff --git a/gcc/rust/typecheck/rust-hir-type-check-struct.cc b/gcc/rust/typecheck/rust-hir-type-check-struct.cc index 1931f08ff4d2..d9e4635568c3 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-struct.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-struct.cc @@ -131,7 +131,8 @@ TypeCheckStructExpr::resolve (HIR::StructExprStructFields &struct_expr) break; } - context->insert_type (field->get_mappings (), resolved_field_value_expr); + context->insert_implicit_type (field->get_mappings ().get_hirid (), + resolved_field_value_expr); } // something failed setting up the fields diff --git a/gcc/rust/typecheck/rust-hir-type-check-type.cc b/gcc/rust/typecheck/rust-hir-type-check-type.cc index 5668838c79f3..12a349086187 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-type.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-type.cc @@ -69,7 +69,8 @@ TypeCheckType::Resolve (HIR::Type &type) TypeCheckType resolver (type.get_mappings ().get_hirid ()); type.accept_vis (resolver); rust_assert (resolver.translated != nullptr); - resolver.context->insert_type (type.get_mappings (), resolver.translated); + resolver.context->insert_implicit_type (type.get_mappings ().get_hirid (), + resolver.translated); return resolver.translated; } @@ -689,7 +690,8 @@ TypeCheckType::visit (HIR::ArrayType &type) TyTy::BaseType *expected_ty = nullptr; bool ok = context->lookup_builtin ("usize", &expected_ty); rust_assert (ok); - context->insert_type (type.get_size_expr ().get_mappings (), expected_ty); + context->insert_implicit_type ( + type.get_size_expr ().get_mappings ().get_hirid (), expected_ty); unify_site (type.get_size_expr ().get_mappings ().get_hirid (), TyTy::TyWithLocation (expected_ty), diff --git a/gcc/rust/typecheck/rust-hir-type-check.cc b/gcc/rust/typecheck/rust-hir-type-check.cc index 1e9f7d2f00dd..a31ebc320df5 100644 --- a/gcc/rust/typecheck/rust-hir-type-check.cc +++ b/gcc/rust/typecheck/rust-hir-type-check.cc @@ -186,8 +186,8 @@ TraitItemReference::get_type_from_fn (/*const*/ HIR::TraitItemFunc &fn) const case HIR::GenericParam::GenericKind::TYPE: { auto param_type = TypeResolveGenericParam::Resolve (*generic_param); - context->insert_type (generic_param->get_mappings (), - param_type); + context->insert_implicit_type ( + generic_param->get_mappings ().get_hirid (), param_type); substitutions.push_back (TyTy::SubstitutionParamMapping ( static_cast (*generic_param), param_type)); @@ -287,7 +287,8 @@ TraitItemReference::get_type_from_fn (/*const*/ HIR::TraitItemFunc &fn) const } } - context->insert_type (self_param.get_mappings (), self_type); + context->insert_implicit_type (self_param.get_mappings ().get_hirid (), + self_type); params.push_back (TyTy::FnParam (std::move (self_pattern), self_type)); } @@ -295,7 +296,8 @@ TraitItemReference::get_type_from_fn (/*const*/ HIR::TraitItemFunc &fn) const { // get the name as well required for later on auto param_tyty = TypeCheckType::Resolve (param.get_type ()); - context->insert_type (param.get_mappings (), param_tyty); + context->insert_implicit_type (param.get_mappings ().get_hirid (), + param_tyty); TypeCheckPattern::Resolve (param.get_param_name (), param_tyty); // FIXME: Should we take the name ? Use a shared pointer instead ? params.push_back ( @@ -331,7 +333,7 @@ TraitItemReference::get_type_from_fn (/*const*/ HIR::TraitItemFunc &fn) const TyTy::SubstitutionArgumentMappings::empty ( context->get_lifetime_resolver ().get_num_bound_regions ()), region_constraints); - context->insert_type (fn.get_mappings (), resolved); + context->insert_implicit_type (fn.get_mappings ().get_hirid (), resolved); return resolved; } diff --git a/gcc/rust/typecheck/rust-hir-type-check.h b/gcc/rust/typecheck/rust-hir-type-check.h index 65f38c6099cd..d5be564c3c90 100644 --- a/gcc/rust/typecheck/rust-hir-type-check.h +++ b/gcc/rust/typecheck/rust-hir-type-check.h @@ -169,8 +169,6 @@ class TypeCheckContext void insert_builtin (HirId id, NodeId ref, TyTy::BaseType *type); const std::vector> &get_builtins () const; - void insert_type (const Analysis::NodeMapping &mappings, - TyTy::BaseType *type); bool lookup_type (HirId id, TyTy::BaseType **type) const; void clear_type (TyTy::BaseType *ty); diff --git a/gcc/rust/typecheck/rust-substitution-mapper.cc b/gcc/rust/typecheck/rust-substitution-mapper.cc index 20fe8f04adcb..ffbf3991f6a1 100644 --- a/gcc/rust/typecheck/rust-substitution-mapper.cc +++ b/gcc/rust/typecheck/rust-substitution-mapper.cc @@ -152,18 +152,15 @@ SubstMapperInternal::Resolve (TyTy::BaseType *base, = context->lookup_type (mapper.resolved->get_ty_ref (), &unused); if (!is_ty_available) { - context->insert_type ( - Analysis::NodeMapping (0, 0, mapper.resolved->get_ty_ref (), 0), - mapper.resolved); + context->insert_implicit_type (mapper.resolved->get_ty_ref (), + mapper.resolved); } bool is_ref_available = context->lookup_type (mapper.resolved->get_ref (), &unused); if (!is_ref_available) { - context->insert_type (Analysis::NodeMapping (0, 0, - mapper.resolved->get_ref (), - 0), - mapper.resolved); + context->insert_implicit_type (mapper.resolved->get_ref (), + mapper.resolved); } return mapper.resolved; diff --git a/gcc/rust/typecheck/rust-typecheck-context.cc b/gcc/rust/typecheck/rust-typecheck-context.cc index 907833fba971..a4ec0cf74c41 100644 --- a/gcc/rust/typecheck/rust-typecheck-context.cc +++ b/gcc/rust/typecheck/rust-typecheck-context.cc @@ -79,17 +79,6 @@ TypeCheckContext::get_builtins () const return builtins; } -void -TypeCheckContext::insert_type (const Analysis::NodeMapping &mappings, - TyTy::BaseType *type) -{ - rust_assert (type != nullptr); - NodeId ref = mappings.get_nodeid (); - HirId id = mappings.get_hirid (); - node_id_refs[ref] = id; - resolved[id] = type; -} - void TypeCheckContext::insert_implicit_type (HirId id, TyTy::BaseType *type) { @@ -597,9 +586,7 @@ TypeCheckContext::compute_inference_variables (bool error) rust_assert (result); rust_assert (result->get_kind () != TyTy::TypeKind::ERROR); result->set_ref (id); - insert_type (Analysis::NodeMapping (mappings.get_current_crate (), 0, id, - UNKNOWN_LOCAL_DEFID), - result); + insert_implicit_type (id, result); return true; }); diff --git a/gcc/rust/typecheck/rust-tyty-subst.cc b/gcc/rust/typecheck/rust-tyty-subst.cc index 26afe1bd4914..0af29db83fa5 100644 --- a/gcc/rust/typecheck/rust-tyty-subst.cc +++ b/gcc/rust/typecheck/rust-tyty-subst.cc @@ -157,14 +157,8 @@ SubstitutionParamMapping::override_context () if (!param->can_resolve ()) return; - auto &mappings = Analysis::Mappings::get (); auto context = Resolver::TypeCheckContext::get (); - - context->insert_type (Analysis::NodeMapping (mappings.get_current_crate (), - UNKNOWN_NODEID, - param->get_ref (), - UNKNOWN_LOCAL_DEFID), - param->resolve ()); + context->insert_implicit_type (param->get_ref (), param->resolve ()); } SubstitutionArg::SubstitutionArg (const SubstitutionParamMapping *param, diff --git a/gcc/rust/typecheck/rust-tyty-util.cc b/gcc/rust/typecheck/rust-tyty-util.cc index e18246db541f..6dbc85d24e3b 100644 --- a/gcc/rust/typecheck/rust-tyty-util.cc +++ b/gcc/rust/typecheck/rust-tyty-util.cc @@ -50,11 +50,7 @@ TyVar::get_implicit_infer_var (location_t locus) InferType *infer = new InferType (mappings.get_next_hir_id (), InferType::InferTypeKind::GENERAL, InferType::TypeHint::Default (), locus); - context->insert_type (Analysis::NodeMapping (mappings.get_current_crate (), - UNKNOWN_NODEID, - infer->get_ref (), - UNKNOWN_LOCAL_DEFID), - infer); + context->insert_implicit_type (infer->get_ref (), infer); mappings.insert_location (infer->get_ref (), locus); return TyVar (infer->get_ref ()); @@ -95,10 +91,7 @@ TyVar::monomorphized_clone () const c->set_ref (mappings.get_next_hir_id ()); // insert it - context->insert_type (Analysis::NodeMapping (mappings.get_current_crate (), - UNKNOWN_NODEID, c->get_ref (), - UNKNOWN_LOCAL_DEFID), - c); + context->insert_implicit_type (c->get_ref (), c); return TyVar (c->get_ref ()); } diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc index ca88c4c7b03e..db74ff837f42 100644 --- a/gcc/rust/typecheck/rust-tyty.cc +++ b/gcc/rust/typecheck/rust-tyty.cc @@ -1027,11 +1027,7 @@ InferType::clone () const = new InferType (mappings.get_next_hir_id (), get_infer_kind (), default_hint, get_ident ().locus, get_combined_refs ()); - context->insert_type (Analysis::NodeMapping (mappings.get_current_crate (), - UNKNOWN_NODEID, - clone->get_ref (), - UNKNOWN_LOCAL_DEFID), - clone); + context->insert_implicit_type (clone->get_ref (), clone); mappings.insert_location (clone->get_ref (), mappings.lookup_location (get_ref ())); diff --git a/gcc/rust/typecheck/rust-unify.cc b/gcc/rust/typecheck/rust-unify.cc index 45c4cbaa7df8..3a4dc8242a50 100644 --- a/gcc/rust/typecheck/rust-unify.cc +++ b/gcc/rust/typecheck/rust-unify.cc @@ -107,7 +107,8 @@ UnifyRules::commit (TyTy::BaseType *base, TyTy::BaseType *other, auto node = Analysis::NodeMapping (mappings.get_current_crate (), UNKNOWN_NODEID, ref, UNKNOWN_LOCAL_DEFID); - context.insert_type (node, resolved->clone ()); + context.insert_implicit_type (node.get_hirid (), + resolved->clone ()); } } }