]> git.ipfire.org Git - thirdparty/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)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 17:19:00 +0000 (18:19 +0100)
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 557be83b8c48f67ff72656ac58fe5a9a293a7984..ffcfe7b094ff6317f37fdc289f8cad57ee5d7a1b 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 4399a8ab7272ea369f2575dc88f6fa95334bb107..96c7458fe760883ff3ebfb1c9227b58e5f4b19db 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 0b8ebac036245272ee8733a82789b845ed2cb516..b85be70a89d47a20f17c1eafe10e1004ffbd6cc5 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 fec01ead2e7d1a2b74259e83cbda8fcf8b38712f..0c00c5a82cd8955c68ff70a9714d16bc1fa039df 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 e35765fbd322d225a2a8918116a1416e5537ac9f..698a12818c944a67a53d760585309daf98fb6db6 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 2cb1d82e01b78952246dbf81881e2af0a7d9f0ec..68901c1bc600c6b99c03383699e3459e9b48e08e 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 e18730d47db2316592af16bbfc2173e46d27bef4..4c9c9168c74a44f695d527efcdda7b705750933f 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 3d07a9501fe26604c270bb71092ae217598339a2..643608b3cb769a5128b2251ac6278b5a0fc7f1fb 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