Skip to content

Commit 395d362

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 <[email protected]>
1 parent bee59d6 commit 395d362

18 files changed

+98
-99
lines changed

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,8 @@ 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 (
223+
generic_param->get_mappings ().get_hirid (), param_type);
223224
substitutions.push_back (
224225
TyTy::SubstitutionParamMapping (typaram, param_type));
225226

@@ -361,7 +362,7 @@ TraitItemReference::resolve_item (HIR::TraitItemType &type)
361362
= new TyTy::PlaceholderType (type.get_name ().as_string (),
362363
type.get_mappings ().get_defid (),
363364
type.get_mappings ().get_hirid ());
364-
context->insert_type (type.get_mappings (), ty);
365+
context->insert_implicit_type (type.get_mappings ().get_hirid (), ty);
365366
}
366367

367368
void

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

+7-5
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,8 @@ 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 (),
267+
expected_ty);
267268

268269
Analysis::NodeMapping array_mapping (crate_num, UNKNOWN_NODEID,
269270
mappings.get_next_hir_id (
@@ -274,7 +275,7 @@ TypeCheckBase::resolve_literal (const Analysis::NodeMapping &expr_mappings,
274275
= new TyTy::ArrayType (array_mapping.get_hirid (), locus,
275276
*literal_capacity,
276277
TyTy::TyVar (u8->get_ref ()));
277-
context->insert_type (array_mapping, array);
278+
context->insert_implicit_type (array_mapping.get_hirid (), array);
278279

279280
infered = new TyTy::ReferenceType (expr_mappings.get_hirid (),
280281
TyTy::TyVar (array->get_ref ()),
@@ -401,14 +402,15 @@ TypeCheckBase::resolve_generic_params (
401402
param.get_locus ());
402403
}
403404

404-
context->insert_type (generic_param->get_mappings (),
405-
specified_type);
405+
context->insert_implicit_type (
406+
generic_param->get_mappings ().get_hirid (), specified_type);
406407
}
407408
break;
408409

409410
case HIR::GenericParam::GenericKind::TYPE: {
410411
auto param_type = TypeResolveGenericParam::Resolve (*generic_param);
411-
context->insert_type (generic_param->get_mappings (), param_type);
412+
context->insert_implicit_type (
413+
generic_param->get_mappings ().get_hirid (), param_type);
412414

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

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

+9-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,8 @@ 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 (),
121+
expected_ty);
121122

122123
unify_site (item.get_mappings ().get_hirid (),
123124
TyTy::TyWithLocation (expected_ty),
@@ -166,7 +167,8 @@ TypeCheckEnumItem::visit (HIR::EnumItemTuple &item)
166167
std::to_string (idx), field_type,
167168
field.get_locus ());
168169
fields.push_back (ty_field);
169-
context->insert_type (field.get_mappings (), ty_field->get_field_type ());
170+
context->insert_implicit_type (field.get_mappings ().get_hirid (),
171+
ty_field->get_field_type ());
170172
idx++;
171173
}
172174

@@ -183,7 +185,7 @@ TypeCheckEnumItem::visit (HIR::EnumItemTuple &item)
183185
TyTy::BaseType *isize = nullptr;
184186
bool ok = context->lookup_builtin ("isize", &isize);
185187
rust_assert (ok);
186-
context->insert_type (mapping, isize);
188+
context->insert_implicit_type (mapping.get_hirid (), isize);
187189

188190
tl::optional<CanonicalPath> canonical_path;
189191

@@ -227,7 +229,8 @@ TypeCheckEnumItem::visit (HIR::EnumItemStruct &item)
227229
field.get_field_name ().as_string (),
228230
field_type, field.get_locus ());
229231
fields.push_back (ty_field);
230-
context->insert_type (field.get_mappings (), ty_field->get_field_type ());
232+
context->insert_implicit_type (field.get_mappings ().get_hirid (),
233+
ty_field->get_field_type ());
231234
}
232235

233236
Analysis::NodeMapping mapping (item.get_mappings ().get_crate_num (),
@@ -243,7 +246,7 @@ TypeCheckEnumItem::visit (HIR::EnumItemStruct &item)
243246
TyTy::BaseType *isize = nullptr;
244247
bool ok = context->lookup_builtin ("isize", &isize);
245248
rust_assert (ok);
246-
context->insert_type (mapping, isize);
249+
context->insert_implicit_type (mapping.get_hirid (), isize);
247250

248251
tl::optional<CanonicalPath> canonical_path;
249252

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

+8-5
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ 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 (),
55+
resolver.infered);
5556

5657
return resolver.infered;
5758
}
@@ -1007,8 +1008,9 @@ TypeCheckExpr::visit (HIR::ArrayExpr &expr)
10071008
TyTy::BaseType *expected_ty = nullptr;
10081009
bool ok = context->lookup_builtin ("usize", &expected_ty);
10091010
rust_assert (ok);
1010-
context->insert_type (elems.get_num_copies_expr ().get_mappings (),
1011-
expected_ty);
1011+
context->insert_implicit_type (
1012+
elems.get_num_copies_expr ().get_mappings ().get_hirid (),
1013+
expected_ty);
10121014

10131015
unify_site (expr.get_mappings ().get_hirid (),
10141016
TyTy::TyWithLocation (expected_ty),
@@ -1056,7 +1058,7 @@ TypeCheckExpr::visit (HIR::ArrayExpr &expr)
10561058
TyTy::BaseType *expected_ty = nullptr;
10571059
bool ok = context->lookup_builtin ("usize", &expected_ty);
10581060
rust_assert (ok);
1059-
context->insert_type (mapping, expected_ty);
1061+
context->insert_implicit_type (mapping.get_hirid (), expected_ty);
10601062
}
10611063
break;
10621064
}
@@ -1314,7 +1316,8 @@ TypeCheckExpr::visit (HIR::MethodCallExpr &expr)
13141316
}
13151317

13161318
// store the expected fntype
1317-
context->insert_type (expr.get_method_name ().get_mappings (), lookup);
1319+
context->insert_implicit_type (
1320+
expr.get_method_name ().get_mappings ().get_hirid (), lookup);
13181321

13191322
if (flag_name_resolution_2_0)
13201323
{

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

+17-11
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ 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 (),
65+
actual_type);
6566
resolved = actual_type;
6667
}
6768

@@ -91,8 +92,8 @@ TypeCheckTopLevelExternItem::visit (HIR::ExternalFunctionItem &function)
9192
case HIR::GenericParam::GenericKind::TYPE: {
9293
auto param_type
9394
= TypeResolveGenericParam::Resolve (*generic_param);
94-
context->insert_type (generic_param->get_mappings (),
95-
param_type);
95+
context->insert_implicit_type (
96+
generic_param->get_mappings ().get_hirid (), param_type);
9697

9798
substitutions.push_back (TyTy::SubstitutionParamMapping (
9899
static_cast<HIR::TypeParam &> (*generic_param), param_type));
@@ -149,7 +150,8 @@ TypeCheckTopLevelExternItem::visit (HIR::ExternalFunctionItem &function)
149150

150151
params.push_back (TyTy::FnParam (std::move (param_pattern), param_tyty));
151152

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

154156
// FIXME do we need error checking for patterns here?
155157
// see https://github.com/Rust-GCC/gccrs/issues/995
@@ -181,7 +183,7 @@ TypeCheckTopLevelExternItem::visit (HIR::ExternalFunctionItem &function)
181183
context->get_lifetime_resolver ().get_num_bound_regions ()),
182184
region_constraints);
183185

184-
context->insert_type (function.get_mappings (), fnType);
186+
context->insert_implicit_type (function.get_mappings ().get_hirid (), fnType);
185187
resolved = fnType;
186188
}
187189

@@ -450,7 +452,8 @@ TypeCheckImplItem::visit (HIR::Function &function)
450452
}
451453
}
452454

453-
context->insert_type (self_param.get_mappings (), self_type);
455+
context->insert_implicit_type (self_param.get_mappings ().get_hirid (),
456+
self_type);
454457
params.push_back (TyTy::FnParam (std::move (self_pattern), self_type));
455458
}
456459

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

462-
context->insert_type (param.get_mappings (), param_tyty);
465+
context->insert_implicit_type (param.get_mappings ().get_hirid (),
466+
param_tyty);
463467
TypeCheckPattern::Resolve (param.get_param_name (), param_tyty);
464468

465469
params.push_back (
@@ -496,7 +500,7 @@ TypeCheckImplItem::visit (HIR::Function &function)
496500
context->get_lifetime_resolver ().get_num_bound_regions ()),
497501
region_constraints);
498502

499-
context->insert_type (function.get_mappings (), fnType);
503+
context->insert_implicit_type (function.get_mappings ().get_hirid (), fnType);
500504
result = fnType;
501505

502506
// need to get the return type from this
@@ -530,7 +534,8 @@ TypeCheckImplItem::visit (HIR::ConstantItem &constant)
530534
TyTy::TyWithLocation (type, constant.get_type ().get_locus ()),
531535
TyTy::TyWithLocation (expr_type, constant.get_expr ().get_locus ()),
532536
constant.get_locus ());
533-
context->insert_type (constant.get_mappings (), unified);
537+
context->insert_implicit_type (constant.get_mappings ().get_hirid (),
538+
unified);
534539
result = unified;
535540
}
536541

@@ -545,7 +550,8 @@ TypeCheckImplItem::visit (HIR::TypeAlias &alias)
545550
TyTy::BaseType *actual_type
546551
= TypeCheckType::Resolve (alias.get_type_aliased ());
547552

548-
context->insert_type (alias.get_mappings (), actual_type);
553+
context->insert_implicit_type (alias.get_mappings ().get_hirid (),
554+
actual_type);
549555
result = actual_type;
550556
TyTy::RegionConstraints region_constraints;
551557
for (auto &where_clause_item : alias.get_where_clause ().get_items ())
@@ -688,7 +694,7 @@ TypeCheckImplItemWithTrait::visit (HIR::TypeAlias &type)
688694
raw_trait_item->get_mappings ().get_defid (),
689695
substitutions);
690696

691-
context->insert_type (type.get_mappings (), projection);
697+
context->insert_implicit_type (type.get_mappings ().get_hirid (), projection);
692698
raw_trait_item->associated_type_set (projection);
693699
}
694700

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

+22-13
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ 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 (),
157+
actual_type);
157158

158159
TyTy::RegionConstraints region_constraints;
159160
for (auto &where_clause_item : alias.get_where_clause ().get_items ())
@@ -189,7 +190,8 @@ TypeCheckItem::visit (HIR::TupleStruct &struct_decl)
189190
std::to_string (idx), field_type,
190191
field.get_locus ());
191192
fields.push_back (ty_field);
192-
context->insert_type (field.get_mappings (), ty_field->get_field_type ());
193+
context->insert_implicit_type (field.get_mappings ().get_hirid (),
194+
ty_field->get_field_type ());
193195
idx++;
194196
}
195197

@@ -241,7 +243,9 @@ TypeCheckItem::visit (HIR::TupleStruct &struct_decl)
241243
context->get_lifetime_resolver ().get_num_bound_regions ()),
242244
region_constraints);
243245

244-
context->insert_type (struct_decl.get_mappings (), type);
246+
context->insert_implicit_type (struct_decl.get_mappings ().get_hirid (),
247+
type);
248+
245249
infered = type;
246250

247251
context->get_variance_analysis_ctx ().add_type_constraints (*type);
@@ -272,7 +276,8 @@ TypeCheckItem::visit (HIR::StructStruct &struct_decl)
272276
field.get_field_name ().as_string (),
273277
field_type, field.get_locus ());
274278
fields.push_back (ty_field);
275-
context->insert_type (field.get_mappings (), ty_field->get_field_type ());
279+
context->insert_implicit_type (field.get_mappings ().get_hirid (),
280+
ty_field->get_field_type ());
276281
}
277282

278283
auto path = CanonicalPath::create_empty ();
@@ -323,7 +328,8 @@ TypeCheckItem::visit (HIR::StructStruct &struct_decl)
323328
context->get_lifetime_resolver ().get_num_bound_regions ()),
324329
region_constraints);
325330

326-
context->insert_type (struct_decl.get_mappings (), type);
331+
context->insert_implicit_type (struct_decl.get_mappings ().get_hirid (),
332+
type);
327333
infered = type;
328334

329335
context->get_variance_analysis_ctx ().add_type_constraints (*type);
@@ -382,7 +388,7 @@ TypeCheckItem::visit (HIR::Enum &enum_decl)
382388
TyTy::ADTType::ADTKind::ENUM, std::move (variants),
383389
std::move (substitutions), repr);
384390

385-
context->insert_type (enum_decl.get_mappings (), type);
391+
context->insert_implicit_type (enum_decl.get_mappings ().get_hirid (), type);
386392
infered = type;
387393

388394
context->get_variance_analysis_ctx ().add_type_constraints (*type);
@@ -412,8 +418,8 @@ TypeCheckItem::visit (HIR::Union &union_decl)
412418
variant.get_field_name ().as_string (),
413419
variant_type, variant.get_locus ());
414420
fields.push_back (ty_variant);
415-
context->insert_type (variant.get_mappings (),
416-
ty_variant->get_field_type ());
421+
context->insert_implicit_type (variant.get_mappings ().get_hirid (),
422+
ty_variant->get_field_type ());
417423
}
418424

419425
// get the path
@@ -453,7 +459,7 @@ TypeCheckItem::visit (HIR::Union &union_decl)
453459
TyTy::ADTType::ADTKind::UNION, std::move (variants),
454460
std::move (substitutions));
455461

456-
context->insert_type (union_decl.get_mappings (), type);
462+
context->insert_implicit_type (union_decl.get_mappings ().get_hirid (), type);
457463
infered = type;
458464

459465
context->get_variance_analysis_ctx ().add_type_constraints (*type);
@@ -471,7 +477,7 @@ TypeCheckItem::visit (HIR::StaticItem &var)
471477
TyTy::TyWithLocation (expr_type,
472478
var.get_expr ().get_locus ()),
473479
var.get_locus ());
474-
context->insert_type (var.get_mappings (), unified);
480+
context->insert_implicit_type (var.get_mappings ().get_hirid (), unified);
475481
infered = unified;
476482
}
477483

@@ -486,7 +492,8 @@ TypeCheckItem::visit (HIR::ConstantItem &constant)
486492
TyTy::TyWithLocation (type, constant.get_type ().get_locus ()),
487493
TyTy::TyWithLocation (expr_type, constant.get_expr ().get_locus ()),
488494
constant.get_locus ());
489-
context->insert_type (constant.get_mappings (), unified);
495+
context->insert_implicit_type (constant.get_mappings ().get_hirid (),
496+
unified);
490497
infered = unified;
491498
}
492499

@@ -585,7 +592,8 @@ TypeCheckItem::visit (HIR::Function &function)
585592
{
586593
// get the name as well required for later on
587594
auto param_tyty = TypeCheckType::Resolve (param.get_type ());
588-
context->insert_type (param.get_mappings (), param_tyty);
595+
context->insert_implicit_type (param.get_mappings ().get_hirid (),
596+
param_tyty);
589597
TypeCheckPattern::Resolve (param.get_param_name (), param_tyty);
590598
params.push_back (
591599
TyTy::FnParam (param.get_param_name ().clone_pattern (), param_tyty));
@@ -622,7 +630,8 @@ TypeCheckItem::visit (HIR::Function &function)
622630
context->get_lifetime_resolver ().get_num_bound_regions ()),
623631
region_constraints);
624632

625-
context->insert_type (function.get_mappings (), fn_type);
633+
context->insert_implicit_type (function.get_mappings ().get_hirid (),
634+
fn_type);
626635

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

0 commit comments

Comments
 (0)