From: Philip Herron <[email protected]>

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]>
---
 gcc/rust/backend/rust-compile-base.h      |  2 +-
 gcc/rust/backend/rust-compile-expr.cc     |  7 ++--
 gcc/rust/backend/rust-compile.cc          |  7 +---
 gcc/rust/typecheck/rust-hir-type-bounds.h |  6 +--
 gcc/rust/typecheck/rust-type-util.cc      |  2 +-
 gcc/rust/typecheck/rust-type-util.h       |  2 +-
 gcc/rust/typecheck/rust-tyty-bounds.cc    |  7 +---
 gcc/rust/typecheck/rust-tyty-cmp.h        | 20 +++++++++-
 gcc/rust/typecheck/rust-tyty-subst.cc     |  2 +-
 gcc/rust/typecheck/rust-tyty.cc           | 45 +++++++++++++++++++----
 gcc/rust/typecheck/rust-tyty.h            |  8 ++--
 11 files changed, 72 insertions(+), 36 deletions(-)

diff --git a/gcc/rust/backend/rust-compile-base.h 
b/gcc/rust/backend/rust-compile-base.h
index e9b85968fac..3bf26afef65 100644
--- a/gcc/rust/backend/rust-compile-base.h
+++ b/gcc/rust/backend/rust-compile-base.h
@@ -56,7 +56,7 @@ protected:
                       TyTy::BaseType *expected, location_t lvalue_locus,
                       location_t rvalue_locus);
 
-  tree coerce_to_dyn_object (tree compiled_ref, const TyTy::BaseType *actual,
+  tree coerce_to_dyn_object (tree compiled_ref, TyTy::BaseType *actual,
                             const TyTy::DynamicObjectType *ty,
                             location_t locus);
 
diff --git a/gcc/rust/backend/rust-compile-expr.cc 
b/gcc/rust/backend/rust-compile-expr.cc
index d059eade2ca..2bec52bfc4a 100644
--- a/gcc/rust/backend/rust-compile-expr.cc
+++ b/gcc/rust/backend/rust-compile-expr.cc
@@ -2209,11 +2209,10 @@ HIRCompileBase::resolve_unsized_dyn_adjustment (
   tree rvalue = expression;
   location_t rvalue_locus = locus;
 
-  const TyTy::BaseType *actual = adjustment.get_actual ();
-  const TyTy::BaseType *expected = adjustment.get_expected ();
+  auto actual = adjustment.get_actual ();
+  auto expected = adjustment.get_expected ();
 
-  const TyTy::DynamicObjectType *dyn
-    = static_cast<const TyTy::DynamicObjectType *> (expected);
+  const auto dyn = static_cast<const TyTy::DynamicObjectType *> (expected);
 
   rust_debug ("resolve_unsized_dyn_adjustment actual={%s} dyn={%s}",
              actual->debug_str ().c_str (), dyn->debug_str ().c_str ());
diff --git a/gcc/rust/backend/rust-compile.cc b/gcc/rust/backend/rust-compile.cc
index a3e047a2dab..40f16e49086 100644
--- a/gcc/rust/backend/rust-compile.cc
+++ b/gcc/rust/backend/rust-compile.cc
@@ -183,8 +183,7 @@ HIRCompileBase::coercion_site1 (tree rvalue, TyTy::BaseType 
*rval,
 }
 
 tree
-HIRCompileBase::coerce_to_dyn_object (tree compiled_ref,
-                                     const TyTy::BaseType *actual,
+HIRCompileBase::coerce_to_dyn_object (tree compiled_ref, TyTy::BaseType 
*actual,
                                      const TyTy::DynamicObjectType *ty,
                                      location_t locus)
 {
@@ -201,9 +200,7 @@ HIRCompileBase::coerce_to_dyn_object (tree compiled_ref,
   // __trait_object_ptr
   // [list of function ptrs]
 
-  std::vector<std::pair<Resolver::TraitReference *, HIR::ImplBlock *>>
-    probed_bounds_for_receiver = Resolver::TypeBoundsProbe::Probe (actual);
-
+  auto probed_bounds_for_receiver = Resolver::TypeBoundsProbe::Probe (actual);
   tree address_of_compiled_ref = null_pointer_node;
   if (!actual->is_unit ())
     address_of_compiled_ref = address_expression (compiled_ref, locus);
diff --git a/gcc/rust/typecheck/rust-hir-type-bounds.h 
b/gcc/rust/typecheck/rust-hir-type-bounds.h
index 5384700e97f..392ff20e66c 100644
--- a/gcc/rust/typecheck/rust-hir-type-bounds.h
+++ b/gcc/rust/typecheck/rust-hir-type-bounds.h
@@ -30,7 +30,7 @@ class TypeBoundsProbe : public TypeCheckBase
 {
 public:
   static std::vector<std::pair<TraitReference *, HIR::ImplBlock *>>
-  Probe (const TyTy::BaseType *receiver);
+  Probe (TyTy::BaseType *receiver);
 
   static bool is_bound_satisfied_for_type (TyTy::BaseType *receiver,
                                           TraitReference *ref);
@@ -46,9 +46,9 @@ private:
   void assemble_builtin_candidate (LangItem::Kind item);
 
 private:
-  TypeBoundsProbe (const TyTy::BaseType *receiver);
+  TypeBoundsProbe (TyTy::BaseType *receiver);
 
-  const TyTy::BaseType *receiver;
+  TyTy::BaseType *receiver;
   std::vector<std::pair<TraitReference *, HIR::ImplBlock *>> trait_references;
 };
 
diff --git a/gcc/rust/typecheck/rust-type-util.cc 
b/gcc/rust/typecheck/rust-type-util.cc
index 2d661669b3f..83fffb3b47c 100644
--- a/gcc/rust/typecheck/rust-type-util.cc
+++ b/gcc/rust/typecheck/rust-type-util.cc
@@ -325,7 +325,7 @@ cast_site (HirId id, TyTy::TyWithLocation from, 
TyTy::TyWithLocation to,
 
 AssociatedImplTrait *
 lookup_associated_impl_block (const TyTy::TypeBoundPredicate &bound,
-                             const TyTy::BaseType *binding, bool *ambigious)
+                             TyTy::BaseType *binding, bool *ambigious)
 {
   auto context = TypeCheckContext::get ();
 
diff --git a/gcc/rust/typecheck/rust-type-util.h 
b/gcc/rust/typecheck/rust-type-util.h
index dd97f1e989a..cd09b3fb73a 100644
--- a/gcc/rust/typecheck/rust-type-util.h
+++ b/gcc/rust/typecheck/rust-type-util.h
@@ -52,7 +52,7 @@ TyTy::BaseType *cast_site (HirId id, TyTy::TyWithLocation 
from,
 
 AssociatedImplTrait *
 lookup_associated_impl_block (const TyTy::TypeBoundPredicate &bound,
-                             const TyTy::BaseType *binding,
+                             TyTy::BaseType *binding,
                              bool *ambigious = nullptr);
 
 } // namespace Resolver
diff --git a/gcc/rust/typecheck/rust-tyty-bounds.cc 
b/gcc/rust/typecheck/rust-tyty-bounds.cc
index bb2e6d4d708..c3682c6b175 100644
--- a/gcc/rust/typecheck/rust-tyty-bounds.cc
+++ b/gcc/rust/typecheck/rust-tyty-bounds.cc
@@ -26,12 +26,12 @@
 namespace Rust {
 namespace Resolver {
 
-TypeBoundsProbe::TypeBoundsProbe (const TyTy::BaseType *receiver)
+TypeBoundsProbe::TypeBoundsProbe (TyTy::BaseType *receiver)
   : TypeCheckBase (), receiver (receiver)
 {}
 
 std::vector<std::pair<TraitReference *, HIR::ImplBlock *>>
-TypeBoundsProbe::Probe (const TyTy::BaseType *receiver)
+TypeBoundsProbe::Probe (TyTy::BaseType *receiver)
 {
   TypeBoundsProbe probe (receiver);
   probe.scan ();
@@ -75,9 +75,6 @@ TypeBoundsProbe::process_impl_block (
   HIR::Trait *t = TraitResolver::ResolveHirItem (impl->get_trait_ref ());
   if (t == nullptr)
     return true;
-  // DefId trait_id = t->get_mappings ().get_defid ();
-  // if (context->trait_query_in_progress (trait_id))
-  //   return true;
 
   HirId impl_ty_id = impl->get_type ().get_mappings ().get_hirid ();
   TyTy::BaseType *impl_type = nullptr;
diff --git a/gcc/rust/typecheck/rust-tyty-cmp.h 
b/gcc/rust/typecheck/rust-tyty-cmp.h
index c22dfdd7a2c..17f94a2e7e5 100644
--- a/gcc/rust/typecheck/rust-tyty-cmp.h
+++ b/gcc/rust/typecheck/rust-tyty-cmp.h
@@ -1595,8 +1595,24 @@ public:
        return;
       }
 
-    location_t ref_locus = mappings.lookup_location (type.get_ref ());
-    ok = base->bounds_compatible (type, ref_locus, false);
+    for (const auto &pred : base->get_specified_bounds ())
+      {
+       bool found = false;
+       for (const auto &opred : type.get_specified_bounds ())
+         {
+           found = pred.is_equal (opred);
+           if (found)
+             break;
+         }
+
+       if (!found)
+         {
+           ok = false;
+           break;
+         }
+      }
+
+    ok = true;
   }
 
 private:
diff --git a/gcc/rust/typecheck/rust-tyty-subst.cc 
b/gcc/rust/typecheck/rust-tyty-subst.cc
index 872d24318ed..c4582f68e43 100644
--- a/gcc/rust/typecheck/rust-tyty-subst.cc
+++ b/gcc/rust/typecheck/rust-tyty-subst.cc
@@ -1056,7 +1056,7 @@ SubstitutionRef::monomorphize ()
       if (!pty->can_resolve ())
        continue;
 
-      const TyTy::BaseType *binding = pty->resolve ();
+      TyTy::BaseType *binding = pty->resolve ();
       if (binding->get_kind () == TyTy::TypeKind::PARAM)
        continue;
 
diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc
index 5e321f248c3..1803f9cd1ef 100644
--- a/gcc/rust/typecheck/rust-tyty.cc
+++ b/gcc/rust/typecheck/rust-tyty.cc
@@ -295,8 +295,7 @@ BaseType::get_locus () const
 
 // FIXME this is missing locus
 bool
-BaseType::satisfies_bound (const TypeBoundPredicate &predicate,
-                          bool emit_error) const
+BaseType::satisfies_bound (const TypeBoundPredicate &predicate, bool 
emit_error)
 {
   const Resolver::TraitReference *query = predicate.get ();
   for (const auto &bound : specified_bounds)
@@ -395,8 +394,7 @@ BaseType::satisfies_bound (const TypeBoundPredicate 
&predicate,
 }
 
 bool
-BaseType::bounds_compatible (const BaseType &other, location_t locus,
-                            bool emit_error) const
+BaseType::bounds_compatible (BaseType &other, location_t locus, bool 
emit_error)
 {
   std::vector<std::reference_wrapper<const TypeBoundPredicate>>
     unsatisfied_bounds;
@@ -1704,7 +1702,7 @@ VariantDef::clone () const
 
   auto &&discriminant_opt = has_discriminant ()
                              ? tl::optional<std::unique_ptr<HIR::Expr>> (
-                               get_discriminant ().clone_expr ())
+                                 get_discriminant ().clone_expr ())
                              : tl::nullopt;
 
   return new VariantDef (id, defid, identifier, ident, type,
@@ -1720,7 +1718,7 @@ VariantDef::monomorphized_clone () const
 
   auto discriminant_opt = has_discriminant ()
                            ? tl::optional<std::unique_ptr<HIR::Expr>> (
-                             get_discriminant ().clone_expr ())
+                               get_discriminant ().clone_expr ())
                            : tl::nullopt;
 
   return new VariantDef (id, defid, identifier, ident, type,
@@ -3817,7 +3815,24 @@ OpaqueType::is_equal (const BaseType &other) const
   if (can_resolve () != other2.can_resolve ())
     return false;
 
-  return bounds_compatible (other, UNDEF_LOCATION, false);
+  if (num_specified_bounds () != other.num_specified_bounds ())
+    return false;
+
+  for (const auto &pred : specified_bounds)
+    {
+      bool found = false;
+      for (const auto &opred : other.get_specified_bounds ())
+       {
+         found = pred.is_equal (opred);
+         if (found)
+           break;
+       }
+
+      if (!found)
+       return false;
+    }
+
+  return true;
 }
 
 // StrType
@@ -4268,7 +4283,21 @@ DynamicObjectType::is_equal (const BaseType &other) const
   if (num_specified_bounds () != other.num_specified_bounds ())
     return false;
 
-  return bounds_compatible (other, UNDEF_LOCATION, false);
+  for (const auto &pred : specified_bounds)
+    {
+      bool found = false;
+      for (const auto &opred : other.get_specified_bounds ())
+       {
+         found = pred.is_equal (opred);
+         if (found)
+           break;
+       }
+
+      if (!found)
+       return false;
+    }
+
+  return true;
 }
 
 const std::vector<
diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h
index b90bc83e8bf..dfa67fe32fe 100644
--- a/gcc/rust/typecheck/rust-tyty.h
+++ b/gcc/rust/typecheck/rust-tyty.h
@@ -128,11 +128,9 @@ public:
   //     2. (For functions) have the same signature
   virtual bool is_equal (const BaseType &other) const;
 
-  bool satisfies_bound (const TypeBoundPredicate &predicate,
-                       bool emit_error) const;
+  bool satisfies_bound (const TypeBoundPredicate &predicate, bool emit_error);
 
-  bool bounds_compatible (const BaseType &other, location_t locus,
-                         bool emit_error) const;
+  bool bounds_compatible (BaseType &other, location_t locus, bool emit_error);
 
   void inherit_bounds (const BaseType &other);
 
@@ -589,7 +587,7 @@ public:
 
   TypeBoundPredicate (const TypeBoundPredicate &other);
 
-  virtual ~TypeBoundPredicate (){};
+  virtual ~TypeBoundPredicate () {};
 
   TypeBoundPredicate &operator= (const TypeBoundPredicate &other);
 
-- 
2.50.1

Reply via email to