Skip to content

Commit 9bd2443

Browse files
committed
gccrs: Remove some const usage so we can get rid of more can_eq usage
I needed to remove som usage of const so we can get rid of can_eq in type bounds probe. This means we can use the types_compatable interface instead. Which is much better. gcc/rust/ChangeLog: * backend/rust-compile-base.h: remove const * backend/rust-compile-expr.cc: likewise * backend/rust-compile.cc (HIRCompileBase::coerce_to_dyn_object): likewise * typecheck/rust-hir-type-bounds.h: likewise * typecheck/rust-type-util.cc (lookup_associated_impl_block): likewise * typecheck/rust-type-util.h (lookup_associated_impl_block): likewise * typecheck/rust-tyty-bounds.cc (TypeBoundsProbe::TypeBoundsProbe): likewise (TypeBoundsProbe::Probe): likewise * typecheck/rust-tyty-cmp.h: likewise * typecheck/rust-tyty-subst.cc (SubstitutionRef::monomorphize): likewise * typecheck/rust-tyty.cc (BaseType::satisfies_bound): likewise (BaseType::bounds_compatible): likewise (VariantDef::clone): likewise (VariantDef::monomorphized_clone): likewise (OpaqueType::is_equal): likewise (DynamicObjectType::is_equal): likewise * typecheck/rust-tyty.h: likewise Signed-off-by: Philip Herron <[email protected]>
1 parent a8cf025 commit 9bd2443

11 files changed

+72
-36
lines changed

gcc/rust/backend/rust-compile-base.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class HIRCompileBase
5656
TyTy::BaseType *expected, location_t lvalue_locus,
5757
location_t rvalue_locus);
5858

59-
tree coerce_to_dyn_object (tree compiled_ref, const TyTy::BaseType *actual,
59+
tree coerce_to_dyn_object (tree compiled_ref, TyTy::BaseType *actual,
6060
const TyTy::DynamicObjectType *ty,
6161
location_t locus);
6262

gcc/rust/backend/rust-compile-expr.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2209,11 +2209,10 @@ HIRCompileBase::resolve_unsized_dyn_adjustment (
22092209
tree rvalue = expression;
22102210
location_t rvalue_locus = locus;
22112211

2212-
const TyTy::BaseType *actual = adjustment.get_actual ();
2213-
const TyTy::BaseType *expected = adjustment.get_expected ();
2212+
auto actual = adjustment.get_actual ();
2213+
auto expected = adjustment.get_expected ();
22142214

2215-
const TyTy::DynamicObjectType *dyn
2216-
= static_cast<const TyTy::DynamicObjectType *> (expected);
2215+
const auto dyn = static_cast<const TyTy::DynamicObjectType *> (expected);
22172216

22182217
rust_debug ("resolve_unsized_dyn_adjustment actual={%s} dyn={%s}",
22192218
actual->debug_str ().c_str (), dyn->debug_str ().c_str ());

gcc/rust/backend/rust-compile.cc

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,7 @@ HIRCompileBase::coercion_site1 (tree rvalue, TyTy::BaseType *rval,
183183
}
184184

185185
tree
186-
HIRCompileBase::coerce_to_dyn_object (tree compiled_ref,
187-
const TyTy::BaseType *actual,
186+
HIRCompileBase::coerce_to_dyn_object (tree compiled_ref, TyTy::BaseType *actual,
188187
const TyTy::DynamicObjectType *ty,
189188
location_t locus)
190189
{
@@ -201,9 +200,7 @@ HIRCompileBase::coerce_to_dyn_object (tree compiled_ref,
201200
// __trait_object_ptr
202201
// [list of function ptrs]
203202

204-
std::vector<std::pair<Resolver::TraitReference *, HIR::ImplBlock *>>
205-
probed_bounds_for_receiver = Resolver::TypeBoundsProbe::Probe (actual);
206-
203+
auto probed_bounds_for_receiver = Resolver::TypeBoundsProbe::Probe (actual);
207204
tree address_of_compiled_ref = null_pointer_node;
208205
if (!actual->is_unit ())
209206
address_of_compiled_ref = address_expression (compiled_ref, locus);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class TypeBoundsProbe : public TypeCheckBase
3030
{
3131
public:
3232
static std::vector<std::pair<TraitReference *, HIR::ImplBlock *>>
33-
Probe (const TyTy::BaseType *receiver);
33+
Probe (TyTy::BaseType *receiver);
3434

3535
static bool is_bound_satisfied_for_type (TyTy::BaseType *receiver,
3636
TraitReference *ref);
@@ -46,9 +46,9 @@ class TypeBoundsProbe : public TypeCheckBase
4646
void assemble_builtin_candidate (LangItem::Kind item);
4747

4848
private:
49-
TypeBoundsProbe (const TyTy::BaseType *receiver);
49+
TypeBoundsProbe (TyTy::BaseType *receiver);
5050

51-
const TyTy::BaseType *receiver;
51+
TyTy::BaseType *receiver;
5252
std::vector<std::pair<TraitReference *, HIR::ImplBlock *>> trait_references;
5353
};
5454

gcc/rust/typecheck/rust-type-util.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ cast_site (HirId id, TyTy::TyWithLocation from, TyTy::TyWithLocation to,
325325

326326
AssociatedImplTrait *
327327
lookup_associated_impl_block (const TyTy::TypeBoundPredicate &bound,
328-
const TyTy::BaseType *binding, bool *ambigious)
328+
TyTy::BaseType *binding, bool *ambigious)
329329
{
330330
auto context = TypeCheckContext::get ();
331331

gcc/rust/typecheck/rust-type-util.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ TyTy::BaseType *cast_site (HirId id, TyTy::TyWithLocation from,
5252

5353
AssociatedImplTrait *
5454
lookup_associated_impl_block (const TyTy::TypeBoundPredicate &bound,
55-
const TyTy::BaseType *binding,
55+
TyTy::BaseType *binding,
5656
bool *ambigious = nullptr);
5757

5858
} // namespace Resolver

gcc/rust/typecheck/rust-tyty-bounds.cc

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@
2626
namespace Rust {
2727
namespace Resolver {
2828

29-
TypeBoundsProbe::TypeBoundsProbe (const TyTy::BaseType *receiver)
29+
TypeBoundsProbe::TypeBoundsProbe (TyTy::BaseType *receiver)
3030
: TypeCheckBase (), receiver (receiver)
3131
{}
3232

3333
std::vector<std::pair<TraitReference *, HIR::ImplBlock *>>
34-
TypeBoundsProbe::Probe (const TyTy::BaseType *receiver)
34+
TypeBoundsProbe::Probe (TyTy::BaseType *receiver)
3535
{
3636
TypeBoundsProbe probe (receiver);
3737
probe.scan ();
@@ -75,9 +75,6 @@ TypeBoundsProbe::process_impl_block (
7575
HIR::Trait *t = TraitResolver::ResolveHirItem (impl->get_trait_ref ());
7676
if (t == nullptr)
7777
return true;
78-
// DefId trait_id = t->get_mappings ().get_defid ();
79-
// if (context->trait_query_in_progress (trait_id))
80-
// return true;
8178

8279
HirId impl_ty_id = impl->get_type ().get_mappings ().get_hirid ();
8380
TyTy::BaseType *impl_type = nullptr;

gcc/rust/typecheck/rust-tyty-cmp.h

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1595,8 +1595,24 @@ class DynamicCmp : public BaseCmp
15951595
return;
15961596
}
15971597

1598-
location_t ref_locus = mappings.lookup_location (type.get_ref ());
1599-
ok = base->bounds_compatible (type, ref_locus, false);
1598+
for (const auto &pred : base->get_specified_bounds ())
1599+
{
1600+
bool found = false;
1601+
for (const auto &opred : type.get_specified_bounds ())
1602+
{
1603+
found = pred.is_equal (opred);
1604+
if (found)
1605+
break;
1606+
}
1607+
1608+
if (!found)
1609+
{
1610+
ok = false;
1611+
break;
1612+
}
1613+
}
1614+
1615+
ok = true;
16001616
}
16011617

16021618
private:

gcc/rust/typecheck/rust-tyty-subst.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1056,7 +1056,7 @@ SubstitutionRef::monomorphize ()
10561056
if (!pty->can_resolve ())
10571057
continue;
10581058

1059-
const TyTy::BaseType *binding = pty->resolve ();
1059+
TyTy::BaseType *binding = pty->resolve ();
10601060
if (binding->get_kind () == TyTy::TypeKind::PARAM)
10611061
continue;
10621062

gcc/rust/typecheck/rust-tyty.cc

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,7 @@ BaseType::get_locus () const
295295

296296
// FIXME this is missing locus
297297
bool
298-
BaseType::satisfies_bound (const TypeBoundPredicate &predicate,
299-
bool emit_error) const
298+
BaseType::satisfies_bound (const TypeBoundPredicate &predicate, bool emit_error)
300299
{
301300
const Resolver::TraitReference *query = predicate.get ();
302301
for (const auto &bound : specified_bounds)
@@ -395,8 +394,7 @@ BaseType::satisfies_bound (const TypeBoundPredicate &predicate,
395394
}
396395

397396
bool
398-
BaseType::bounds_compatible (const BaseType &other, location_t locus,
399-
bool emit_error) const
397+
BaseType::bounds_compatible (BaseType &other, location_t locus, bool emit_error)
400398
{
401399
std::vector<std::reference_wrapper<const TypeBoundPredicate>>
402400
unsatisfied_bounds;
@@ -1704,7 +1702,7 @@ VariantDef::clone () const
17041702

17051703
auto &&discriminant_opt = has_discriminant ()
17061704
? tl::optional<std::unique_ptr<HIR::Expr>> (
1707-
get_discriminant ().clone_expr ())
1705+
get_discriminant ().clone_expr ())
17081706
: tl::nullopt;
17091707

17101708
return new VariantDef (id, defid, identifier, ident, type,
@@ -1720,7 +1718,7 @@ VariantDef::monomorphized_clone () const
17201718

17211719
auto discriminant_opt = has_discriminant ()
17221720
? tl::optional<std::unique_ptr<HIR::Expr>> (
1723-
get_discriminant ().clone_expr ())
1721+
get_discriminant ().clone_expr ())
17241722
: tl::nullopt;
17251723

17261724
return new VariantDef (id, defid, identifier, ident, type,
@@ -3817,7 +3815,24 @@ OpaqueType::is_equal (const BaseType &other) const
38173815
if (can_resolve () != other2.can_resolve ())
38183816
return false;
38193817

3820-
return bounds_compatible (other, UNDEF_LOCATION, false);
3818+
if (num_specified_bounds () != other.num_specified_bounds ())
3819+
return false;
3820+
3821+
for (const auto &pred : specified_bounds)
3822+
{
3823+
bool found = false;
3824+
for (const auto &opred : other.get_specified_bounds ())
3825+
{
3826+
found = pred.is_equal (opred);
3827+
if (found)
3828+
break;
3829+
}
3830+
3831+
if (!found)
3832+
return false;
3833+
}
3834+
3835+
return true;
38213836
}
38223837

38233838
// StrType
@@ -4268,7 +4283,21 @@ DynamicObjectType::is_equal (const BaseType &other) const
42684283
if (num_specified_bounds () != other.num_specified_bounds ())
42694284
return false;
42704285

4271-
return bounds_compatible (other, UNDEF_LOCATION, false);
4286+
for (const auto &pred : specified_bounds)
4287+
{
4288+
bool found = false;
4289+
for (const auto &opred : other.get_specified_bounds ())
4290+
{
4291+
found = pred.is_equal (opred);
4292+
if (found)
4293+
break;
4294+
}
4295+
4296+
if (!found)
4297+
return false;
4298+
}
4299+
4300+
return true;
42724301
}
42734302

42744303
const std::vector<

0 commit comments

Comments
 (0)