Skip to content

Commit 41dcb21

Browse files
committed
gccrs: Remove more calls to the old TyTy::BaseType::can_eq interface
This old can_eq interface was an old method to try and check if types can match up by taking into account generics but its not maintained properly and we already have a new wrapper Resolver::types_compatable (type, type, locus, emit_errors) which just calls unify_site_and infer with commit false. There are only a few places left to update. One minor downside is that i need to remove const in some places because the unify interface is non const. Ideally we would want to avoid writing a seperate const unify anyway so i think this is not ideal but fine for us. gcc/rust/ChangeLog: * typecheck/rust-autoderef.cc: remove useless assertion * typecheck/rust-coercion.cc (TypeCoercionRules::coerce_unsafe_ptr): refactor (TypeCoercionRules::coerce_borrowed_pointer): remove FIXME this is fine * typecheck/rust-hir-inherent-impl-overlap.h: use types_compatable * typecheck/rust-hir-path-probe.cc (PathProbeType::PathProbeType): remove const (PathProbeType::Probe): likewise (PathProbeImplTrait::PathProbeImplTrait): likewise (PathProbeImplTrait::Probe): likewise * typecheck/rust-hir-path-probe.h: likewise * typecheck/rust-hir-type-check-base.cc (walk_types_to_constrain): likewise * typecheck/rust-hir-type-check-base.h: likewise * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): use types_compatable * typecheck/rust-hir-type-check.h: remove const * typecheck/rust-typecheck-context.cc (TypeCheckContext::insert_associated_impl_mapping): likewise (TypeCheckContext::lookup_associated_impl_mapping_for_self): remove can_Eq * typecheck/rust-tyty-bounds.cc (TypeBoundPredicate::is_equal): likewise * typecheck/rust-tyty-subst.cc (SubstitutionArg::get_tyty): remove const version * typecheck/rust-tyty-subst.h: likewise * typecheck/rust-tyty.cc (BaseType::get_root): likewise * typecheck/rust-tyty.h: likewise gcc/testsuite/ChangeLog: * rust/compile/generics8.rs: extra error message Signed-off-by: Philip Herron <[email protected]>
1 parent f721b13 commit 41dcb21

16 files changed

+71
-79
lines changed

gcc/rust/typecheck/rust-autoderef.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,6 @@ resolve_operator_overload_fn (
247247
const TyTy::ADTType *adt = static_cast<const TyTy::ADTType *> (lhs);
248248

249249
auto s = fn->get_self_type ()->get_root ();
250-
rust_assert (s->can_eq (adt, false));
251250
rust_assert (s->get_kind () == TyTy::TypeKind::ADT);
252251
const TyTy::ADTType *self_adt
253252
= static_cast<const TyTy::ADTType *> (s);

gcc/rust/typecheck/rust-coercion.cc

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,9 @@ TypeCoercionRules::coerce_unsafe_ptr (TyTy::BaseType *receiver,
204204

205205
default:
206206
{
207-
// FIXME this can probably turn into a unify_and
208-
if (receiver->can_eq (expected, false))
207+
if (types_compatable (TyTy::TyWithLocation (receiver),
208+
TyTy::TyWithLocation (expected), UNKNOWN_LOCATION,
209+
false))
209210
return CoercionResult{{}, expected->clone ()};
210211

211212
return CoercionResult::get_error ();
@@ -280,9 +281,6 @@ TypeCoercionRules::coerce_borrowed_pointer (TyTy::BaseType *receiver,
280281

281282
default:
282283
{
283-
// FIXME
284-
// we might be able to replace this with a can_eq because we default
285-
// back to a final unity anyway
286284
rust_debug ("coerce_borrowed_pointer -- unify");
287285
TyTy::BaseType *result
288286
= unify_site_and (receiver->get_ref (),

gcc/rust/typecheck/rust-hir-inherent-impl-overlap.h

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -79,27 +79,29 @@ class OverlappingImplItemPass : public TypeCheckBase
7979
if (query == candidate)
8080
continue;
8181

82-
if (query->can_eq (candidate, false))
82+
if (!types_compatable (TyTy::TyWithLocation (query),
83+
TyTy::TyWithLocation (candidate),
84+
UNKNOWN_LOCATION, false))
85+
continue;
86+
87+
// we might be in the case that we have:
88+
//
89+
// *const T vs *const [T]
90+
//
91+
// so lets use an equality check when the
92+
// candidates are both generic to be sure we dont emit a false
93+
// positive
94+
95+
bool a = query->is_concrete ();
96+
bool b = candidate->is_concrete ();
97+
bool both_generic = !a && !b;
98+
if (both_generic)
8399
{
84-
// we might be in the case that we have:
85-
//
86-
// *const T vs *const [T]
87-
//
88-
// so lets use an equality check when the
89-
// candidates are both generic to be sure we dont emit a false
90-
// positive
91-
92-
bool a = query->is_concrete ();
93-
bool b = candidate->is_concrete ();
94-
bool both_generic = !a && !b;
95-
if (both_generic)
96-
{
97-
if (!query->is_equal (*candidate))
98-
continue;
99-
}
100-
101-
possible_collision (it->second, iy->second);
100+
if (!query->is_equal (*candidate))
101+
continue;
102102
}
103+
104+
possible_collision (it->second, iy->second);
103105
}
104106
}
105107
}

gcc/rust/typecheck/rust-hir-path-probe.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,15 @@ PathProbeCandidate::operator< (const PathProbeCandidate &c) const
137137

138138
// PathProbeType
139139

140-
PathProbeType::PathProbeType (const TyTy::BaseType *receiver,
140+
PathProbeType::PathProbeType (TyTy::BaseType *receiver,
141141
const HIR::PathIdentSegment &query,
142142
DefId specific_trait_id)
143143
: TypeCheckBase (), receiver (receiver), search (query),
144144
current_impl (nullptr), specific_trait_id (specific_trait_id)
145145
{}
146146

147147
std::set<PathProbeCandidate>
148-
PathProbeType::Probe (const TyTy::BaseType *receiver,
148+
PathProbeType::Probe (TyTy::BaseType *receiver,
149149
const HIR::PathIdentSegment &segment_name,
150150
bool probe_impls, bool probe_bounds,
151151
bool ignore_mandatory_trait_items,
@@ -443,15 +443,15 @@ PathProbeType::is_receiver_generic () const
443443

444444
// PathProbImplTrait
445445

446-
PathProbeImplTrait::PathProbeImplTrait (const TyTy::BaseType *receiver,
446+
PathProbeImplTrait::PathProbeImplTrait (TyTy::BaseType *receiver,
447447
const HIR::PathIdentSegment &query,
448448
const TraitReference *trait_reference)
449449
: PathProbeType (receiver, query, UNKNOWN_DEFID),
450450
trait_reference (trait_reference)
451451
{}
452452

453453
std::set<PathProbeCandidate>
454-
PathProbeImplTrait::Probe (const TyTy::BaseType *receiver,
454+
PathProbeImplTrait::Probe (TyTy::BaseType *receiver,
455455
const HIR::PathIdentSegment &segment_name,
456456
const TraitReference *trait_reference)
457457
{

gcc/rust/typecheck/rust-hir-path-probe.h

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,8 @@ class PathProbeType : public TypeCheckBase, public HIR::HIRImplVisitor
108108
{
109109
public:
110110
static std::set<PathProbeCandidate>
111-
Probe (const TyTy::BaseType *receiver,
112-
const HIR::PathIdentSegment &segment_name, bool probe_impls,
113-
bool probe_bounds, bool ignore_mandatory_trait_items,
111+
Probe (TyTy::BaseType *receiver, const HIR::PathIdentSegment &segment_name,
112+
bool probe_impls, bool probe_bounds, bool ignore_mandatory_trait_items,
114113
DefId specific_trait_id = UNKNOWN_DEFID);
115114

116115
void visit (HIR::TypeAlias &alias) override;
@@ -135,8 +134,8 @@ class PathProbeType : public TypeCheckBase, public HIR::HIRImplVisitor
135134
bool ignore_mandatory_trait_items);
136135

137136
protected:
138-
PathProbeType (const TyTy::BaseType *receiver,
139-
const HIR::PathIdentSegment &query, DefId specific_trait_id);
137+
PathProbeType (TyTy::BaseType *receiver, const HIR::PathIdentSegment &query,
138+
DefId specific_trait_id);
140139

141140
std::vector<std::pair<const TraitReference *, HIR::ImplBlock *>>
142141
union_bounds (
@@ -147,7 +146,7 @@ class PathProbeType : public TypeCheckBase, public HIR::HIRImplVisitor
147146

148147
bool is_receiver_generic () const;
149148

150-
const TyTy::BaseType *receiver;
149+
TyTy::BaseType *receiver;
151150
const HIR::PathIdentSegment &search;
152151
std::set<PathProbeCandidate> candidates;
153152
HIR::ImplBlock *current_impl;
@@ -178,12 +177,11 @@ class PathProbeImplTrait : public PathProbeType
178177
{
179178
public:
180179
static std::set<PathProbeCandidate>
181-
Probe (const TyTy::BaseType *receiver,
182-
const HIR::PathIdentSegment &segment_name,
180+
Probe (TyTy::BaseType *receiver, const HIR::PathIdentSegment &segment_name,
183181
const TraitReference *trait_reference);
184182

185183
private:
186-
PathProbeImplTrait (const TyTy::BaseType *receiver,
184+
PathProbeImplTrait (TyTy::BaseType *receiver,
187185
const HIR::PathIdentSegment &query,
188186
const TraitReference *trait_reference);
189187

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ walk_types_to_constrain (std::set<HirId> &constrained_symbols,
5252
{
5353
for (const auto &c : constraints.get_mappings ())
5454
{
55-
const TyTy::BaseType *arg = c.get_tyty ();
55+
auto arg = c.get_tyty ();
5656
if (arg != nullptr)
5757
{
58-
const TyTy::BaseType *p = arg->get_root ();
58+
const auto p = arg->get_root ();
5959
constrained_symbols.insert (p->get_ty_ref ());
6060
if (p->has_substitutions_defined ())
6161
{
@@ -71,7 +71,7 @@ TypeCheckBase::check_for_unconstrained (
7171
const std::vector<TyTy::SubstitutionParamMapping> &params_to_constrain,
7272
const TyTy::SubstitutionArgumentMappings &constraint_a,
7373
const TyTy::SubstitutionArgumentMappings &constraint_b,
74-
const TyTy::BaseType *reference)
74+
TyTy::BaseType *reference)
7575
{
7676
bool check_result = false;
7777
bool check_completed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class TypeCheckBase
5353
const std::vector<TyTy::SubstitutionParamMapping> &params_to_constrain,
5454
const TyTy::SubstitutionArgumentMappings &constraint_a,
5555
const TyTy::SubstitutionArgumentMappings &constraint_b,
56-
const TyTy::BaseType *reference);
56+
TyTy::BaseType *reference);
5757

5858
TyTy::BaseType *resolve_literal (const Analysis::NodeMapping &mappings,
5959
HIR::Literal &literal, location_t locus);

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,10 @@ TypeCheckExpr::visit (HIR::ArrayIndexExpr &expr)
10251025
bool ok = context->lookup_builtin ("usize", &size_ty);
10261026
rust_assert (ok);
10271027

1028-
bool maybe_simple_array_access = index_expr_ty->can_eq (size_ty, false);
1028+
bool maybe_simple_array_access
1029+
= types_compatable (TyTy::TyWithLocation (index_expr_ty),
1030+
TyTy::TyWithLocation (size_ty), expr.get_locus (),
1031+
false);
10291032
if (maybe_simple_array_access
10301033
&& direct_array_expr_ty->get_kind () == TyTy::TypeKind::ARRAY)
10311034
{

gcc/rust/typecheck/rust-hir-type-check.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,10 @@ class TypeCheckContext
249249
bool lookup_associated_type_mapping (HirId id, HirId *mapping);
250250

251251
void insert_associated_impl_mapping (HirId trait_id,
252-
const TyTy::BaseType *impl_type,
252+
TyTy::BaseType *impl_type,
253253
HirId impl_id);
254254
bool lookup_associated_impl_mapping_for_self (HirId trait_id,
255-
const TyTy::BaseType *self,
255+
TyTy::BaseType *self,
256256
HirId *mapping);
257257

258258
void insert_autoderef_mappings (HirId id,
@@ -325,7 +325,7 @@ class TypeCheckContext
325325
std::map<HirId, AssociatedImplTrait> associated_impl_traits;
326326

327327
// trait-id -> list of < self-tyty:impl-id>
328-
std::map<HirId, std::vector<std::pair<const TyTy::BaseType *, HirId>>>
328+
std::map<HirId, std::vector<std::pair<TyTy::BaseType *, HirId>>>
329329
associated_traits_to_impls;
330330

331331
std::map<HirId, HirId> associated_type_mappings;

gcc/rust/typecheck/rust-typecheck-context.cc

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,9 @@ TypeCheckContext::lookup_associated_type_mapping (HirId id, HirId *mapping)
300300
}
301301

302302
void
303-
TypeCheckContext::insert_associated_impl_mapping (
304-
HirId trait_id, const TyTy::BaseType *impl_type, HirId impl_id)
303+
TypeCheckContext::insert_associated_impl_mapping (HirId trait_id,
304+
TyTy::BaseType *impl_type,
305+
HirId impl_id)
305306
{
306307
auto it = associated_traits_to_impls.find (trait_id);
307308
if (it == associated_traits_to_impls.end ())
@@ -313,16 +314,19 @@ TypeCheckContext::insert_associated_impl_mapping (
313314
}
314315

315316
bool
316-
TypeCheckContext::lookup_associated_impl_mapping_for_self (
317-
HirId trait_id, const TyTy::BaseType *self, HirId *mapping)
317+
TypeCheckContext::lookup_associated_impl_mapping_for_self (HirId trait_id,
318+
TyTy::BaseType *self,
319+
HirId *mapping)
318320
{
319321
auto it = associated_traits_to_impls.find (trait_id);
320322
if (it == associated_traits_to_impls.end ())
321323
return false;
322324

323325
for (auto &item : it->second)
324326
{
325-
if (item.first->can_eq (self, false))
327+
if (types_compatable (TyTy::TyWithLocation (item.first),
328+
TyTy::TyWithLocation (self), UNKNOWN_LOCATION,
329+
false))
326330
{
327331
*mapping = item.second;
328332
return true;

0 commit comments

Comments
 (0)