]> git.ipfire.org Git - people/ms/gcc.git/commitdiff
gccrs: autoderef unconstify so we can use in non const contexts
authorPhilip Herron <herron.philip@googlemail.com>
Mon, 27 Feb 2023 17:05:13 +0000 (17:05 +0000)
committerPhilip Herron <philip.herron@embecosm.com>
Tue, 28 Feb 2023 20:38:35 +0000 (20:38 +0000)
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

* backend/rust-compile-base.h: unconsify
* backend/rust-compile.cc (HIRCompileBase::coercion_site): likewise
(HIRCompileBase::coercion_site1): likewise
* typecheck/rust-autoderef.cc (Adjuster::try_deref_type): likewise
(Adjuster::try_raw_deref_type): likewise
(Adjuster::try_unsize_type): likewise
(AutoderefCycle::cycle): likewise
(AutoderefCycle::try_autoderefed): likewise
* typecheck/rust-autoderef.h: likewise
* typecheck/rust-coercion.cc (TypeCoercionRules::select): likewise
* typecheck/rust-coercion.h: likewise
* typecheck/rust-hir-dot-operator.cc (MethodResolver::Probe): likewise
(MethodResolver::select): likewise
* typecheck/rust-hir-dot-operator.h: likewise

gcc/rust/backend/rust-compile-base.h
gcc/rust/backend/rust-compile.cc
gcc/rust/typecheck/rust-autoderef.cc
gcc/rust/typecheck/rust-autoderef.h
gcc/rust/typecheck/rust-coercion.cc
gcc/rust/typecheck/rust-coercion.h
gcc/rust/typecheck/rust-hir-dot-operator.cc
gcc/rust/typecheck/rust-hir-dot-operator.h

index 4f039d2328ea6200dcccc95138336e32a00e5fcc..a8f8f2d50dd172411f0ae7475d2ddbcedb926a57 100644 (file)
@@ -40,11 +40,11 @@ protected:
 protected:
   Context *get_context () { return ctx; }
 
-  tree coercion_site (HirId id, tree rvalue, const TyTy::BaseType *actual,
-                     const TyTy::BaseType *expected, Location lvalue_locus,
+  tree coercion_site (HirId id, tree rvalue, TyTy::BaseType *actual,
+                     TyTy::BaseType *expected, Location lvalue_locus,
                      Location rvalue_locus);
-  tree coercion_site1 (tree rvalue, const TyTy::BaseType *actual,
-                      const TyTy::BaseType *expected, Location lvalue_locus,
+  tree coercion_site1 (tree rvalue, TyTy::BaseType *actual,
+                      TyTy::BaseType *expected, Location lvalue_locus,
                       Location rvalue_locus);
 
   tree coerce_to_dyn_object (tree compiled_ref, const TyTy::BaseType *actual,
index db08b3d595b4bf604621eaf01f14cc0bc5056a20..3217901085583fc1f06c064042816df0ec3c929f 100644 (file)
@@ -54,10 +54,9 @@ CompileCrate::go ()
 // Shared methods in compilation
 
 tree
-HIRCompileBase::coercion_site (HirId id, tree rvalue,
-                              const TyTy::BaseType *rval,
-                              const TyTy::BaseType *lval,
-                              Location lvalue_locus, Location rvalue_locus)
+HIRCompileBase::coercion_site (HirId id, tree rvalue, TyTy::BaseType *rval,
+                              TyTy::BaseType *lval, Location lvalue_locus,
+                              Location rvalue_locus)
 {
   std::vector<Resolver::Adjustment> *adjustments = nullptr;
   bool ok = ctx->get_tyctx ()->lookup_autoderef_mappings (id, &adjustments);
@@ -70,15 +69,15 @@ HIRCompileBase::coercion_site (HirId id, tree rvalue,
 }
 
 tree
-HIRCompileBase::coercion_site1 (tree rvalue, const TyTy::BaseType *rval,
-                               const TyTy::BaseType *lval,
-                               Location lvalue_locus, Location rvalue_locus)
+HIRCompileBase::coercion_site1 (tree rvalue, TyTy::BaseType *rval,
+                               TyTy::BaseType *lval, Location lvalue_locus,
+                               Location rvalue_locus)
 {
   if (rvalue == error_mark_node)
     return error_mark_node;
 
-  const TyTy::BaseType *actual = rval->destructure ();
-  const TyTy::BaseType *expected = lval->destructure ();
+  TyTy::BaseType *actual = rval->destructure ();
+  TyTy::BaseType *expected = lval->destructure ();
 
   if (expected->get_kind () == TyTy::TypeKind::REF)
     {
index 658ddd7c2e9c107b207c9d15c519f9a500e50ade..b2cddb3f6b06132aa868d9a76c573e40abe95f07 100644 (file)
@@ -26,7 +26,7 @@ namespace Resolver {
 
 static bool
 resolve_operator_overload_fn (
-  Analysis::RustLangItem::ItemType lang_item_type, const TyTy::BaseType *ty,
+  Analysis::RustLangItem::ItemType lang_item_type, TyTy::BaseType *ty,
   TyTy::FnType **resolved_fn, HIR::ImplItem **impl_item,
   Adjustment::AdjustmentType *requires_ref_adjustment);
 
@@ -40,7 +40,7 @@ Adjuster::adjust_type (const std::vector<Adjustment> &adjustments)
 }
 
 Adjustment
-Adjuster::try_deref_type (const TyTy::BaseType *ty,
+Adjuster::try_deref_type (TyTy::BaseType *ty,
                          Analysis::RustLangItem::ItemType deref_lang_item)
 {
   HIR::ImplItem *impl_item = nullptr;
@@ -85,7 +85,7 @@ Adjuster::try_deref_type (const TyTy::BaseType *ty,
 }
 
 Adjustment
-Adjuster::try_raw_deref_type (const TyTy::BaseType *ty)
+Adjuster::try_raw_deref_type (TyTy::BaseType *ty)
 {
   bool is_valid_type = ty->get_kind () == TyTy::TypeKind::REF;
   if (!is_valid_type)
@@ -99,7 +99,7 @@ Adjuster::try_raw_deref_type (const TyTy::BaseType *ty)
 }
 
 Adjustment
-Adjuster::try_unsize_type (const TyTy::BaseType *ty)
+Adjuster::try_unsize_type (TyTy::BaseType *ty)
 {
   bool is_valid_type = ty->get_kind () == TyTy::TypeKind::ARRAY;
   if (!is_valid_type)
@@ -121,7 +121,7 @@ Adjuster::try_unsize_type (const TyTy::BaseType *ty)
 
 static bool
 resolve_operator_overload_fn (
-  Analysis::RustLangItem::ItemType lang_item_type, const TyTy::BaseType *ty,
+  Analysis::RustLangItem::ItemType lang_item_type, TyTy::BaseType *ty,
   TyTy::FnType **resolved_fn, HIR::ImplItem **impl_item,
   Adjustment::AdjustmentType *requires_ref_adjustment)
 {
@@ -292,9 +292,9 @@ AutoderefCycle::try_hook (const TyTy::BaseType &)
 {}
 
 bool
-AutoderefCycle::cycle (const TyTy::BaseType *receiver)
+AutoderefCycle::cycle (TyTy::BaseType *receiver)
 {
-  const TyTy::BaseType *r = receiver;
+  TyTy::BaseType *r = receiver;
   while (true)
     {
       rust_debug ("autoderef try 1: {%s}", r->debug_str ().c_str ());
@@ -382,7 +382,7 @@ AutoderefCycle::cycle (const TyTy::BaseType *receiver)
 }
 
 bool
-AutoderefCycle::try_autoderefed (const TyTy::BaseType *r)
+AutoderefCycle::try_autoderefed (TyTy::BaseType *r)
 {
   try_hook (*r);
 
index 5f05c0489d1e75ed0779b810ca9fc44d121ecf66..1d5dacfc55dda0b9e3e9833940e7b1d3704597ed 100644 (file)
@@ -40,15 +40,15 @@ public:
   };
 
   // ctor for all adjustments except derefs
-  Adjustment (AdjustmentType type, const TyTy::BaseType *actual,
-             const TyTy::BaseType *expected)
+  Adjustment (AdjustmentType type, TyTy::BaseType *actual,
+             TyTy::BaseType *expected)
     : Adjustment (type, actual, expected, nullptr, nullptr,
                  AdjustmentType::ERROR)
   {}
 
   static Adjustment get_op_overload_deref_adjustment (
-    AdjustmentType type, const TyTy::BaseType *actual,
-    const TyTy::BaseType *expected, TyTy::FnType *fn, HIR::ImplItem *deref_item,
+    AdjustmentType type, TyTy::BaseType *actual, TyTy::BaseType *expected,
+    TyTy::FnType *fn, HIR::ImplItem *deref_item,
     Adjustment::AdjustmentType requires_ref_adjustment)
   {
     rust_assert (type == DEREF || type == DEREF_MUT);
@@ -58,8 +58,8 @@ public:
 
   AdjustmentType get_type () const { return type; }
 
-  const TyTy::BaseType *get_actual () const { return actual; }
-  const TyTy::BaseType *get_expected () const { return expected; }
+  TyTy::BaseType *get_actual () const { return actual; }
+  TyTy::BaseType *get_expected () const { return expected; }
 
   std::string as_string () const
   {
@@ -110,8 +110,8 @@ public:
   HIR::ImplItem *get_deref_hir_item () const { return deref_item; }
 
 private:
-  Adjustment (AdjustmentType type, const TyTy::BaseType *actual,
-             const TyTy::BaseType *expected, TyTy::FnType *deref_operator_fn,
+  Adjustment (AdjustmentType type, TyTy::BaseType *actual,
+             TyTy::BaseType *expected, TyTy::FnType *deref_operator_fn,
              HIR::ImplItem *deref_item,
              Adjustment::AdjustmentType requires_ref_adjustment)
     : type (type), actual (actual), expected (expected),
@@ -120,8 +120,8 @@ private:
   {}
 
   AdjustmentType type;
-  const TyTy::BaseType *actual;
-  const TyTy::BaseType *expected;
+  TyTy::BaseType *actual;
+  TyTy::BaseType *expected;
 
   // - only used for deref operator_overloads
   //
@@ -140,12 +140,12 @@ public:
   TyTy::BaseType *adjust_type (const std::vector<Adjustment> &adjustments);
 
   static Adjustment
-  try_deref_type (const TyTy::BaseType *ty,
+  try_deref_type (TyTy::BaseType *ty,
                  Analysis::RustLangItem::ItemType deref_lang_item);
 
-  static Adjustment try_raw_deref_type (const TyTy::BaseType *ty);
+  static Adjustment try_raw_deref_type (TyTy::BaseType *ty);
 
-  static Adjustment try_unsize_type (const TyTy::BaseType *ty);
+  static Adjustment try_unsize_type (TyTy::BaseType *ty);
 
 private:
   const TyTy::BaseType *base;
@@ -158,15 +158,15 @@ protected:
 
   virtual ~AutoderefCycle ();
 
-  virtual bool select (const TyTy::BaseType &autoderefed) = 0;
+  virtual bool select (TyTy::BaseType &autoderefed) = 0;
 
   // optional: this is a chance to hook in to grab predicate items on the raw
   // type
   virtual void try_hook (const TyTy::BaseType &);
 
-  virtual bool cycle (const TyTy::BaseType *receiver);
+  virtual bool cycle (TyTy::BaseType *receiver);
 
-  bool try_autoderefed (const TyTy::BaseType *r);
+  bool try_autoderefed (TyTy::BaseType *r);
 
   bool autoderef_flag;
   std::vector<Adjustment> adjustments;
index 7a3f51aa419e3d49f2dc1067f513408ec099ddae..c07ee733514ea30543d6302c673ac8d22ce34731 100644 (file)
@@ -373,7 +373,7 @@ TypeCoercionRules::coerce_unsized (TyTy::BaseType *source,
 }
 
 bool
-TypeCoercionRules::select (const TyTy::BaseType &autoderefed)
+TypeCoercionRules::select (TyTy::BaseType &autoderefed)
 {
   rust_debug (
     "autoderef type-coercion select autoderefed={%s} can_eq expected={%s}",
index 69442e5a260d09a1b12e207aa6b7d8fd5c40eef1..0a55b8598d8cf9c24e50e8ad21907d1232f0ae8c 100644 (file)
@@ -71,7 +71,7 @@ protected:
   TypeCoercionRules (TyTy::BaseType *expected, Location locus, bool emit_errors,
                     bool allow_autoderef);
 
-  bool select (const TyTy::BaseType &autoderefed) override;
+  bool select (TyTy::BaseType &autoderefed) override;
 
   bool do_coercion (TyTy::BaseType *receiver);
 
index 84fa8d4f08b6d0f8b4068b6fa9f6036c23a9d80e..4a291e13e5b73f7ecc78440f56abfa8b1689770f 100644 (file)
@@ -29,7 +29,7 @@ MethodResolver::MethodResolver (bool autoderef_flag,
 {}
 
 std::set<MethodCandidate>
-MethodResolver::Probe (const TyTy::BaseType *receiver,
+MethodResolver::Probe (TyTy::BaseType *receiver,
                       const HIR::PathIdentSegment &segment_name,
                       bool autoderef_flag)
 {
@@ -46,7 +46,7 @@ MethodResolver::try_hook (const TyTy::BaseType &r)
 }
 
 bool
-MethodResolver::select (const TyTy::BaseType &receiver)
+MethodResolver::select (TyTy::BaseType &receiver)
 {
   struct impl_item_candidate
   {
index e14baf3f87d0e8c1650064c6cfa4b34bed49fa6b..75927ff5ae23ccb10a9599572114afb24e3d7356 100644 (file)
@@ -54,8 +54,7 @@ public:
   };
 
   static std::set<MethodCandidate>
-  Probe (const TyTy::BaseType *receiver,
-        const HIR::PathIdentSegment &segment_name,
+  Probe (TyTy::BaseType *receiver, const HIR::PathIdentSegment &segment_name,
         bool autoderef_flag = false);
 
   static std::vector<predicate_candidate> get_predicate_items (
@@ -68,7 +67,7 @@ protected:
 
   void try_hook (const TyTy::BaseType &r) override;
 
-  bool select (const TyTy::BaseType &receiver) override;
+  bool select (TyTy::BaseType &receiver) override;
 
 private:
   // search