]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Remove some const usage so we can get rid of more can_eq usage
authorPhilip Herron <herron.philip@googlemail.com>
Mon, 25 Aug 2025 10:34:25 +0000 (11:34 +0100)
committerArthur Cohen <arthur.cohen@embecosm.com>
Thu, 30 Oct 2025 19:58:54 +0000 (20:58 +0100)
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 <herron.philip@googlemail.com>
gcc/rust/backend/rust-compile-base.h
gcc/rust/backend/rust-compile-expr.cc
gcc/rust/backend/rust-compile.cc
gcc/rust/typecheck/rust-hir-type-bounds.h
gcc/rust/typecheck/rust-type-util.cc
gcc/rust/typecheck/rust-type-util.h
gcc/rust/typecheck/rust-tyty-bounds.cc
gcc/rust/typecheck/rust-tyty-cmp.h
gcc/rust/typecheck/rust-tyty-subst.cc
gcc/rust/typecheck/rust-tyty.cc
gcc/rust/typecheck/rust-tyty.h

index e9b85968fac39fcfdc4c14b8c564914ca2330fab..3bf26afef6561c1abe2697097b37552e176ea048 100644 (file)
@@ -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);
 
index d059eade2cafcb2c5f4bd19b44ad6e29c183c0cf..2bec52bfc4a87ae2b3f99a595176f3a6f2a447cd 100644 (file)
@@ -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 ());
index a3e047a2dab113c193fc2be081a88916ca5da271..40f16e490866924d3f0ba8e5cba2844690448b49 100644 (file)
@@ -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);
index 5384700e97fba214bfe3073e432110d03340ebf1..392ff20e66ce384abfe6d60416222b1437371745 100644 (file)
@@ -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;
 };
 
index 2d661669b3f217234331275498fe91356ddddfd2..83fffb3b47c2ca74323678356b99085172a8638d 100644 (file)
@@ -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 ();
 
index dd97f1e989ac9666a0d0866c2b4bf63d4e0858c3..cd09b3fb73a788af2c9411222f1b377efbba77aa 100644 (file)
@@ -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
index bb2e6d4d708f389a59d852fb0faf244966093d85..c3682c6b17537d61868a5d455f9778c320c624f4 100644 (file)
 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;
index c22dfdd7a2c1220f81717117f0f58247060f91e8..17f94a2e7e599167bc11a77a1dd46dc4a9e3ac5b 100644 (file)
@@ -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:
index 872d24318ed2229d5cb27a59faac40a63a0b95a6..c4582f68e431385cec5969f8effa6d3660660f3d 100644 (file)
@@ -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;
 
index 5e321f248c3731c1e65709109c75a4077f8b56d3..1803f9cd1effe8e47cc41ff1de1a5bfbd2045c38 100644 (file)
@@ -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<
index b90bc83e8bf3b682b5bd0b6330556dcb820db5a0..dfa67fe32fecd85562fd555608f94f80fa8d7da8 100644 (file)
@@ -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);