Skip to content

Commit a80e9a4

Browse files
committed
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 <mostafayounis630@gmail.com>
1 parent bee59d6 commit a80e9a4

18 files changed

+61
-96
lines changed

gcc/rust/typecheck/rust-hir-trait-resolve.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ TraitResolver::resolve_trait (HIR::Trait *trait_reference)
219219
bool apply_sized = !is_self;
220220
auto param_type
221221
= TypeResolveGenericParam::Resolve (*generic_param, apply_sized);
222-
context->insert_type (generic_param->get_mappings (), param_type);
222+
context->insert_implicit_type (generic_param->get_mappings ().get_hirid (), param_type);
223223
substitutions.push_back (
224224
TyTy::SubstitutionParamMapping (typaram, param_type));
225225

@@ -361,7 +361,7 @@ TraitItemReference::resolve_item (HIR::TraitItemType &type)
361361
= new TyTy::PlaceholderType (type.get_name ().as_string (),
362362
type.get_mappings ().get_defid (),
363363
type.get_mappings ().get_hirid ());
364-
context->insert_type (type.get_mappings (), ty);
364+
context->insert_implicit_type (type.get_mappings ().get_hirid (), ty);
365365
}
366366

367367
void

gcc/rust/typecheck/rust-hir-type-check-base.cc

+4-4
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ TypeCheckBase::resolve_literal (const Analysis::NodeMapping &expr_mappings,
263263
TyTy::BaseType *expected_ty = nullptr;
264264
ok = context->lookup_builtin ("usize", &expected_ty);
265265
rust_assert (ok);
266-
context->insert_type (capacity_mapping, expected_ty);
266+
context->insert_implicit_type (capacity_mapping.get_hirid (), expected_ty);
267267

268268
Analysis::NodeMapping array_mapping (crate_num, UNKNOWN_NODEID,
269269
mappings.get_next_hir_id (
@@ -274,7 +274,7 @@ TypeCheckBase::resolve_literal (const Analysis::NodeMapping &expr_mappings,
274274
= new TyTy::ArrayType (array_mapping.get_hirid (), locus,
275275
*literal_capacity,
276276
TyTy::TyVar (u8->get_ref ()));
277-
context->insert_type (array_mapping, array);
277+
context->insert_implicit_type (array_mapping.get_hirid (), array);
278278

279279
infered = new TyTy::ReferenceType (expr_mappings.get_hirid (),
280280
TyTy::TyVar (array->get_ref ()),
@@ -401,14 +401,14 @@ TypeCheckBase::resolve_generic_params (
401401
param.get_locus ());
402402
}
403403

404-
context->insert_type (generic_param->get_mappings (),
404+
context->insert_implicit_type (generic_param->get_mappings ().get_hirid (),
405405
specified_type);
406406
}
407407
break;
408408

409409
case HIR::GenericParam::GenericKind::TYPE: {
410410
auto param_type = TypeResolveGenericParam::Resolve (*generic_param);
411-
context->insert_type (generic_param->get_mappings (), param_type);
411+
context->insert_implicit_type (generic_param->get_mappings ().get_hirid (), param_type);
412412

413413
substitutions.push_back (TyTy::SubstitutionParamMapping (
414414
static_cast<HIR::TypeParam &> (*generic_param), param_type));

gcc/rust/typecheck/rust-hir-type-check-enumitem.cc

+6-6
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ TypeCheckEnumItem::visit (HIR::EnumItem &item)
7777
TyTy::BaseType *isize = nullptr;
7878
bool ok = context->lookup_builtin ("isize", &isize);
7979
rust_assert (ok);
80-
context->insert_type (mapping, isize);
80+
context->insert_implicit_type (mapping.get_hirid (), isize);
8181

8282
tl::optional<CanonicalPath> canonical_path;
8383

@@ -117,7 +117,7 @@ TypeCheckEnumItem::visit (HIR::EnumItemDiscriminant &item)
117117

118118
TyTy::ISizeType *expected_ty
119119
= new TyTy::ISizeType (discriminant.get_mappings ().get_hirid ());
120-
context->insert_type (discriminant.get_mappings (), expected_ty);
120+
context->insert_implicit_type (discriminant.get_mappings ().get_hirid (), expected_ty);
121121

122122
unify_site (item.get_mappings ().get_hirid (),
123123
TyTy::TyWithLocation (expected_ty),
@@ -166,7 +166,7 @@ TypeCheckEnumItem::visit (HIR::EnumItemTuple &item)
166166
std::to_string (idx), field_type,
167167
field.get_locus ());
168168
fields.push_back (ty_field);
169-
context->insert_type (field.get_mappings (), ty_field->get_field_type ());
169+
context->insert_implicit_type (field.get_mappings ().get_hirid (), ty_field->get_field_type ());
170170
idx++;
171171
}
172172

@@ -183,7 +183,7 @@ TypeCheckEnumItem::visit (HIR::EnumItemTuple &item)
183183
TyTy::BaseType *isize = nullptr;
184184
bool ok = context->lookup_builtin ("isize", &isize);
185185
rust_assert (ok);
186-
context->insert_type (mapping, isize);
186+
context->insert_implicit_type (mapping.get_hirid (), isize);
187187

188188
tl::optional<CanonicalPath> canonical_path;
189189

@@ -227,7 +227,7 @@ TypeCheckEnumItem::visit (HIR::EnumItemStruct &item)
227227
field.get_field_name ().as_string (),
228228
field_type, field.get_locus ());
229229
fields.push_back (ty_field);
230-
context->insert_type (field.get_mappings (), ty_field->get_field_type ());
230+
context->insert_implicit_type (field.get_mappings ().get_hirid (), ty_field->get_field_type ());
231231
}
232232

233233
Analysis::NodeMapping mapping (item.get_mappings ().get_crate_num (),
@@ -243,7 +243,7 @@ TypeCheckEnumItem::visit (HIR::EnumItemStruct &item)
243243
TyTy::BaseType *isize = nullptr;
244244
bool ok = context->lookup_builtin ("isize", &isize);
245245
rust_assert (ok);
246-
context->insert_type (mapping, isize);
246+
context->insert_implicit_type (mapping.get_hirid (), isize);
247247

248248
tl::optional<CanonicalPath> canonical_path;
249249

gcc/rust/typecheck/rust-hir-type-check-expr.cc

+5-5
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ TypeCheckExpr::Resolve (HIR::Expr &expr)
5151

5252
auto ref = expr.get_mappings ().get_hirid ();
5353
resolver.infered->set_ref (ref);
54-
resolver.context->insert_type (expr.get_mappings (), resolver.infered);
54+
resolver.context->insert_implicit_type (expr.get_mappings ().get_hirid (), resolver.infered);
5555

5656
return resolver.infered;
5757
}
@@ -1007,8 +1007,8 @@ TypeCheckExpr::visit (HIR::ArrayExpr &expr)
10071007
TyTy::BaseType *expected_ty = nullptr;
10081008
bool ok = context->lookup_builtin ("usize", &expected_ty);
10091009
rust_assert (ok);
1010-
context->insert_type (elems.get_num_copies_expr ().get_mappings (),
1011-
expected_ty);
1010+
context->insert_implicit_type (elems.get_num_copies_expr ().get_mappings ().get_hirid (),
1011+
expected_ty);
10121012

10131013
unify_site (expr.get_mappings ().get_hirid (),
10141014
TyTy::TyWithLocation (expected_ty),
@@ -1056,7 +1056,7 @@ TypeCheckExpr::visit (HIR::ArrayExpr &expr)
10561056
TyTy::BaseType *expected_ty = nullptr;
10571057
bool ok = context->lookup_builtin ("usize", &expected_ty);
10581058
rust_assert (ok);
1059-
context->insert_type (mapping, expected_ty);
1059+
context->insert_implicit_type (mapping.get_hirid (), expected_ty);
10601060
}
10611061
break;
10621062
}
@@ -1314,7 +1314,7 @@ TypeCheckExpr::visit (HIR::MethodCallExpr &expr)
13141314
}
13151315

13161316
// store the expected fntype
1317-
context->insert_type (expr.get_method_name ().get_mappings (), lookup);
1317+
context->insert_implicit_type (expr.get_method_name ().get_mappings ().get_hirid (), lookup);
13181318

13191319
if (flag_name_resolution_2_0)
13201320
{

gcc/rust/typecheck/rust-hir-type-check-implitem.cc

+10-10
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ TypeCheckTopLevelExternItem::visit (HIR::ExternalStaticItem &item)
6161
{
6262
TyTy::BaseType *actual_type = TypeCheckType::Resolve (item.get_item_type ());
6363

64-
context->insert_type (item.get_mappings (), actual_type);
64+
context->insert_implicit_type (item.get_mappings ().get_hirid (), actual_type);
6565
resolved = actual_type;
6666
}
6767

@@ -91,7 +91,7 @@ TypeCheckTopLevelExternItem::visit (HIR::ExternalFunctionItem &function)
9191
case HIR::GenericParam::GenericKind::TYPE: {
9292
auto param_type
9393
= TypeResolveGenericParam::Resolve (*generic_param);
94-
context->insert_type (generic_param->get_mappings (),
94+
context->insert_implicit_type (generic_param->get_mappings ().get_hirid (),
9595
param_type);
9696

9797
substitutions.push_back (TyTy::SubstitutionParamMapping (
@@ -149,7 +149,7 @@ TypeCheckTopLevelExternItem::visit (HIR::ExternalFunctionItem &function)
149149

150150
params.push_back (TyTy::FnParam (std::move (param_pattern), param_tyty));
151151

152-
context->insert_type (param.get_mappings (), param_tyty);
152+
context->insert_implicit_type (param.get_mappings ().get_hirid (), param_tyty);
153153

154154
// FIXME do we need error checking for patterns here?
155155
// see https://github.com/Rust-GCC/gccrs/issues/995
@@ -181,7 +181,7 @@ TypeCheckTopLevelExternItem::visit (HIR::ExternalFunctionItem &function)
181181
context->get_lifetime_resolver ().get_num_bound_regions ()),
182182
region_constraints);
183183

184-
context->insert_type (function.get_mappings (), fnType);
184+
context->insert_implicit_type (function.get_mappings ().get_hirid (), fnType);
185185
resolved = fnType;
186186
}
187187

@@ -450,7 +450,7 @@ TypeCheckImplItem::visit (HIR::Function &function)
450450
}
451451
}
452452

453-
context->insert_type (self_param.get_mappings (), self_type);
453+
context->insert_implicit_type (self_param.get_mappings ().get_hirid (), self_type);
454454
params.push_back (TyTy::FnParam (std::move (self_pattern), self_type));
455455
}
456456

@@ -459,7 +459,7 @@ TypeCheckImplItem::visit (HIR::Function &function)
459459
// get the name as well required for later on
460460
auto param_tyty = TypeCheckType::Resolve (param.get_type ());
461461

462-
context->insert_type (param.get_mappings (), param_tyty);
462+
context->insert_implicit_type (param.get_mappings ().get_hirid (), param_tyty);
463463
TypeCheckPattern::Resolve (param.get_param_name (), param_tyty);
464464

465465
params.push_back (
@@ -496,7 +496,7 @@ TypeCheckImplItem::visit (HIR::Function &function)
496496
context->get_lifetime_resolver ().get_num_bound_regions ()),
497497
region_constraints);
498498

499-
context->insert_type (function.get_mappings (), fnType);
499+
context->insert_implicit_type (function.get_mappings ().get_hirid (), fnType);
500500
result = fnType;
501501

502502
// need to get the return type from this
@@ -530,7 +530,7 @@ TypeCheckImplItem::visit (HIR::ConstantItem &constant)
530530
TyTy::TyWithLocation (type, constant.get_type ().get_locus ()),
531531
TyTy::TyWithLocation (expr_type, constant.get_expr ().get_locus ()),
532532
constant.get_locus ());
533-
context->insert_type (constant.get_mappings (), unified);
533+
context->insert_implicit_type (constant.get_mappings ().get_hirid (), unified);
534534
result = unified;
535535
}
536536

@@ -545,7 +545,7 @@ TypeCheckImplItem::visit (HIR::TypeAlias &alias)
545545
TyTy::BaseType *actual_type
546546
= TypeCheckType::Resolve (alias.get_type_aliased ());
547547

548-
context->insert_type (alias.get_mappings (), actual_type);
548+
context->insert_implicit_type (alias.get_mappings ().get_hirid (), actual_type);
549549
result = actual_type;
550550
TyTy::RegionConstraints region_constraints;
551551
for (auto &where_clause_item : alias.get_where_clause ().get_items ())
@@ -688,7 +688,7 @@ TypeCheckImplItemWithTrait::visit (HIR::TypeAlias &type)
688688
raw_trait_item->get_mappings ().get_defid (),
689689
substitutions);
690690

691-
context->insert_type (type.get_mappings (), projection);
691+
context->insert_implicit_type (type.get_mappings ().get_hirid (), projection);
692692
raw_trait_item->associated_type_set (projection);
693693
}
694694

gcc/rust/typecheck/rust-hir-type-check-item.cc

+13-12
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ TypeCheckItem::visit (HIR::TypeAlias &alias)
153153
TyTy::BaseType *actual_type
154154
= TypeCheckType::Resolve (alias.get_type_aliased ());
155155

156-
context->insert_type (alias.get_mappings (), actual_type);
156+
context->insert_implicit_type (alias.get_mappings ().get_hirid (), actual_type);
157157

158158
TyTy::RegionConstraints region_constraints;
159159
for (auto &where_clause_item : alias.get_where_clause ().get_items ())
@@ -189,7 +189,7 @@ TypeCheckItem::visit (HIR::TupleStruct &struct_decl)
189189
std::to_string (idx), field_type,
190190
field.get_locus ());
191191
fields.push_back (ty_field);
192-
context->insert_type (field.get_mappings (), ty_field->get_field_type ());
192+
context->insert_implicit_type (field.get_mappings ().get_hirid (), ty_field->get_field_type ());
193193
idx++;
194194
}
195195

@@ -241,7 +241,8 @@ TypeCheckItem::visit (HIR::TupleStruct &struct_decl)
241241
context->get_lifetime_resolver ().get_num_bound_regions ()),
242242
region_constraints);
243243

244-
context->insert_type (struct_decl.get_mappings (), type);
244+
context->insert_implicit_type (struct_decl.get_mappings ().get_hirid (), type);
245+
245246
infered = type;
246247

247248
context->get_variance_analysis_ctx ().add_type_constraints (*type);
@@ -272,7 +273,7 @@ TypeCheckItem::visit (HIR::StructStruct &struct_decl)
272273
field.get_field_name ().as_string (),
273274
field_type, field.get_locus ());
274275
fields.push_back (ty_field);
275-
context->insert_type (field.get_mappings (), ty_field->get_field_type ());
276+
context->insert_implicit_type (field.get_mappings ().get_hirid (), ty_field->get_field_type ());
276277
}
277278

278279
auto path = CanonicalPath::create_empty ();
@@ -323,7 +324,7 @@ TypeCheckItem::visit (HIR::StructStruct &struct_decl)
323324
context->get_lifetime_resolver ().get_num_bound_regions ()),
324325
region_constraints);
325326

326-
context->insert_type (struct_decl.get_mappings (), type);
327+
context->insert_implicit_type (struct_decl.get_mappings ().get_hirid (), type);
327328
infered = type;
328329

329330
context->get_variance_analysis_ctx ().add_type_constraints (*type);
@@ -382,7 +383,7 @@ TypeCheckItem::visit (HIR::Enum &enum_decl)
382383
TyTy::ADTType::ADTKind::ENUM, std::move (variants),
383384
std::move (substitutions), repr);
384385

385-
context->insert_type (enum_decl.get_mappings (), type);
386+
context->insert_implicit_type (enum_decl.get_mappings ().get_hirid (), type);
386387
infered = type;
387388

388389
context->get_variance_analysis_ctx ().add_type_constraints (*type);
@@ -412,7 +413,7 @@ TypeCheckItem::visit (HIR::Union &union_decl)
412413
variant.get_field_name ().as_string (),
413414
variant_type, variant.get_locus ());
414415
fields.push_back (ty_variant);
415-
context->insert_type (variant.get_mappings (),
416+
context->insert_implicit_type (variant.get_mappings ().get_hirid (),
416417
ty_variant->get_field_type ());
417418
}
418419

@@ -453,7 +454,7 @@ TypeCheckItem::visit (HIR::Union &union_decl)
453454
TyTy::ADTType::ADTKind::UNION, std::move (variants),
454455
std::move (substitutions));
455456

456-
context->insert_type (union_decl.get_mappings (), type);
457+
context->insert_implicit_type (union_decl.get_mappings ().get_hirid (), type);
457458
infered = type;
458459

459460
context->get_variance_analysis_ctx ().add_type_constraints (*type);
@@ -471,7 +472,7 @@ TypeCheckItem::visit (HIR::StaticItem &var)
471472
TyTy::TyWithLocation (expr_type,
472473
var.get_expr ().get_locus ()),
473474
var.get_locus ());
474-
context->insert_type (var.get_mappings (), unified);
475+
context->insert_implicit_type (var.get_mappings ().get_hirid (), unified);
475476
infered = unified;
476477
}
477478

@@ -486,7 +487,7 @@ TypeCheckItem::visit (HIR::ConstantItem &constant)
486487
TyTy::TyWithLocation (type, constant.get_type ().get_locus ()),
487488
TyTy::TyWithLocation (expr_type, constant.get_expr ().get_locus ()),
488489
constant.get_locus ());
489-
context->insert_type (constant.get_mappings (), unified);
490+
context->insert_implicit_type (constant.get_mappings ().get_hirid (), unified);
490491
infered = unified;
491492
}
492493

@@ -585,7 +586,7 @@ TypeCheckItem::visit (HIR::Function &function)
585586
{
586587
// get the name as well required for later on
587588
auto param_tyty = TypeCheckType::Resolve (param.get_type ());
588-
context->insert_type (param.get_mappings (), param_tyty);
589+
context->insert_implicit_type (param.get_mappings ().get_hirid (), param_tyty);
589590
TypeCheckPattern::Resolve (param.get_param_name (), param_tyty);
590591
params.push_back (
591592
TyTy::FnParam (param.get_param_name ().clone_pattern (), param_tyty));
@@ -622,7 +623,7 @@ TypeCheckItem::visit (HIR::Function &function)
622623
context->get_lifetime_resolver ().get_num_bound_regions ()),
623624
region_constraints);
624625

625-
context->insert_type (function.get_mappings (), fn_type);
626+
context->insert_implicit_type (function.get_mappings ().get_hirid (), fn_type);
626627

627628
// need to get the return type from this
628629
TyTy::FnType *resolved_fn_type = fn_type;

gcc/rust/typecheck/rust-hir-type-check-pattern.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ TypeCheckPattern::Resolve (HIR::Pattern &pattern, TyTy::BaseType *parent)
4141
if (resolver.infered == nullptr)
4242
return new TyTy::ErrorType (pattern.get_mappings ().get_hirid ());
4343

44-
resolver.context->insert_type (pattern.get_mappings (), resolver.infered);
44+
resolver.context->insert_implicit_type (pattern.get_mappings ().get_hirid (), resolver.infered);
4545
return resolver.infered;
4646
}
4747

@@ -246,7 +246,7 @@ TypeCheckPattern::visit (HIR::TupleStructPattern &pattern)
246246
TyTy::BaseType *fty = field->get_field_type ();
247247

248248
// setup the type on this pattern type
249-
context->insert_type (pattern->get_mappings (), fty);
249+
context->insert_implicit_type (pattern->get_mappings ().get_hirid (), fty);
250250
TypeCheckPattern::Resolve (*pattern, fty);
251251
}
252252
}
@@ -357,7 +357,7 @@ TypeCheckPattern::visit (HIR::StructPattern &pattern)
357357

358358
// setup the type on this pattern
359359
TyTy::BaseType *fty = field->get_field_type ();
360-
context->insert_type (ident.get_mappings (), fty);
360+
context->insert_implicit_type (ident.get_mappings ().get_hirid (), fty);
361361
}
362362
break;
363363
}

gcc/rust/typecheck/rust-hir-type-check-stmt.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ TypeCheckStmt::visit (HIR::ConstantItem &constant)
6767
TyTy::TyWithLocation (type, constant.get_type ().get_locus ()),
6868
TyTy::TyWithLocation (expr_type, constant.get_expr ().get_locus ()),
6969
constant.get_locus ());
70-
context->insert_type (constant.get_mappings (), infered);
70+
context->insert_implicit_type (constant.get_mappings ().get_hirid (), infered);
7171
}
7272

7373
void

gcc/rust/typecheck/rust-hir-type-check-struct.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ TypeCheckStructExpr::resolve (HIR::StructExprStructFields &struct_expr)
131131
break;
132132
}
133133

134-
context->insert_type (field->get_mappings (), resolved_field_value_expr);
134+
context->insert_implicit_type (field->get_mappings ().get_hirid (), resolved_field_value_expr);
135135
}
136136

137137
// something failed setting up the fields

0 commit comments

Comments
 (0)