[committed,46/88] gccrs: Refactor handle_substitutions to take a reference

Message ID 20230405140411.3016563-47-arthur.cohen@embecosm.com
State Accepted
Headers
Series [committed,01/88] gccrs: fatal_error_flag: Fix typo in error message |

Checks

Context Check Description
snail/gcc-patch-check success Github commit url

Commit Message

Arthur Cohen April 5, 2023, 2:03 p.m. UTC
  From: Philip Herron <herron.philip@googlemail.com>

This patch changes the recusive substitution code to take a reference
instead of a copy. This is important as the callback field is going to be
made non-copyable in a future patch and this pipeline is for recursive
substitutions so its ok to reuse the same mappings here.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>

gcc/rust/ChangeLog:

	* typecheck/rust-tyty-bounds.cc: refactor to take a reference
	* typecheck/rust-tyty-subst.cc: likewise
	(SubstitutionRef::get_substitution_arguments): likewise
	(SubstitutionRef::infer_substitions): likewise
	* typecheck/rust-tyty-subst.h: likewise
	* typecheck/rust-tyty.cc (ADTType::handle_substitions): likewise
	(TupleType::handle_substitions): likewise
	(FnType::handle_substitions): likewise
	(ClosureType::handle_substitions): likewise
	(ArrayType::handle_substitions): likewise
	(SliceType::handle_substitions): likewise
	(ReferenceType::handle_substitions): likewise
	(PointerType::handle_substitions): likewise
	(ParamType::handle_substitions): likewise
	(ProjectionType::handle_substitions): likewise
	* typecheck/rust-tyty.h: likewise
---
 gcc/rust/typecheck/rust-tyty-bounds.cc |  2 +-
 gcc/rust/typecheck/rust-tyty-subst.cc  | 10 ++++++++--
 gcc/rust/typecheck/rust-tyty-subst.h   |  5 +++--
 gcc/rust/typecheck/rust-tyty.cc        | 21 +++++++++++----------
 gcc/rust/typecheck/rust-tyty.h         | 22 +++++++++++-----------
 5 files changed, 34 insertions(+), 26 deletions(-)
  

Patch

diff --git a/gcc/rust/typecheck/rust-tyty-bounds.cc b/gcc/rust/typecheck/rust-tyty-bounds.cc
index e7eb9a760f5..b14e0c68e5a 100644
--- a/gcc/rust/typecheck/rust-tyty-bounds.cc
+++ b/gcc/rust/typecheck/rust-tyty-bounds.cc
@@ -444,7 +444,7 @@  TypeBoundPredicate::is_error () const
 
 BaseType *
 TypeBoundPredicate::handle_substitions (
-  SubstitutionArgumentMappings subst_mappings)
+  SubstitutionArgumentMappings &subst_mappings)
 {
   for (auto &sub : get_substs ())
     {
diff --git a/gcc/rust/typecheck/rust-tyty-subst.cc b/gcc/rust/typecheck/rust-tyty-subst.cc
index aceed29ff03..a5d738744fc 100644
--- a/gcc/rust/typecheck/rust-tyty-subst.cc
+++ b/gcc/rust/typecheck/rust-tyty-subst.cc
@@ -488,7 +488,13 @@  SubstitutionRef::was_substituted () const
   return !needs_substitution ();
 }
 
-SubstitutionArgumentMappings
+SubstitutionArgumentMappings &
+SubstitutionRef::get_substitution_arguments ()
+{
+  return used_arguments;
+}
+
+const SubstitutionArgumentMappings &
 SubstitutionRef::get_substitution_arguments () const
 {
   return used_arguments;
@@ -697,7 +703,7 @@  SubstitutionRef::infer_substitions (Location locus)
   SubstitutionArgumentMappings infer_arguments (std::move (args),
 						{} /* binding_arguments */,
 						locus);
-  return handle_substitions (std::move (infer_arguments));
+  return handle_substitions (infer_arguments);
 }
 
 SubstitutionArgumentMappings
diff --git a/gcc/rust/typecheck/rust-tyty-subst.h b/gcc/rust/typecheck/rust-tyty-subst.h
index 4d09a3013e7..039eb36589e 100644
--- a/gcc/rust/typecheck/rust-tyty-subst.h
+++ b/gcc/rust/typecheck/rust-tyty-subst.h
@@ -199,7 +199,8 @@  public:
 
   bool was_substituted () const;
 
-  SubstitutionArgumentMappings get_substitution_arguments () const;
+  SubstitutionArgumentMappings &get_substitution_arguments ();
+  const SubstitutionArgumentMappings &get_substitution_arguments () const;
 
   // this is the count of type params that are not substituted fuly
   size_t num_required_substitutions () const;
@@ -301,7 +302,7 @@  public:
   bool monomorphize ();
 
   // TODO comment
-  virtual BaseType *handle_substitions (SubstitutionArgumentMappings mappings)
+  virtual BaseType *handle_substitions (SubstitutionArgumentMappings &mappings)
     = 0;
 
   SubstitutionArgumentMappings get_used_arguments () const;
diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc
index 4c324c66c16..a3271eb0d1a 100644
--- a/gcc/rust/typecheck/rust-tyty.cc
+++ b/gcc/rust/typecheck/rust-tyty.cc
@@ -1148,7 +1148,7 @@  handle_substitions (SubstitutionArgumentMappings &subst_mappings,
 }
 
 ADTType *
-ADTType::handle_substitions (SubstitutionArgumentMappings subst_mappings)
+ADTType::handle_substitions (SubstitutionArgumentMappings &subst_mappings)
 {
   ADTType *adt = static_cast<ADTType *> (clone ());
   adt->set_ty_ref (mappings->get_next_hir_id ());
@@ -1333,7 +1333,7 @@  TupleType::monomorphized_clone () const
 }
 
 TupleType *
-TupleType::handle_substitions (SubstitutionArgumentMappings mappings)
+TupleType::handle_substitions (SubstitutionArgumentMappings &mappings)
 {
   auto mappings_table = Analysis::Mappings::get ();
 
@@ -1474,7 +1474,7 @@  FnType::monomorphized_clone () const
 }
 
 FnType *
-FnType::handle_substitions (SubstitutionArgumentMappings subst_mappings)
+FnType::handle_substitions (SubstitutionArgumentMappings &subst_mappings)
 {
   FnType *fn = static_cast<FnType *> (clone ());
   fn->set_ty_ref (mappings->get_next_hir_id ());
@@ -1742,7 +1742,7 @@  ClosureType::monomorphized_clone () const
 }
 
 ClosureType *
-ClosureType::handle_substitions (SubstitutionArgumentMappings mappings)
+ClosureType::handle_substitions (SubstitutionArgumentMappings &mappings)
 {
   gcc_unreachable ();
   return nullptr;
@@ -1862,7 +1862,7 @@  ArrayType::monomorphized_clone () const
 }
 
 ArrayType *
-ArrayType::handle_substitions (SubstitutionArgumentMappings mappings)
+ArrayType::handle_substitions (SubstitutionArgumentMappings &mappings)
 {
   auto mappings_table = Analysis::Mappings::get ();
 
@@ -1945,7 +1945,7 @@  SliceType::monomorphized_clone () const
 }
 
 SliceType *
-SliceType::handle_substitions (SubstitutionArgumentMappings mappings)
+SliceType::handle_substitions (SubstitutionArgumentMappings &mappings)
 {
   auto mappings_table = Analysis::Mappings::get ();
 
@@ -2704,7 +2704,7 @@  ReferenceType::monomorphized_clone () const
 }
 
 ReferenceType *
-ReferenceType::handle_substitions (SubstitutionArgumentMappings mappings)
+ReferenceType::handle_substitions (SubstitutionArgumentMappings &mappings)
 {
   auto mappings_table = Analysis::Mappings::get ();
 
@@ -2870,7 +2870,7 @@  PointerType::monomorphized_clone () const
 }
 
 PointerType *
-PointerType::handle_substitions (SubstitutionArgumentMappings mappings)
+PointerType::handle_substitions (SubstitutionArgumentMappings &mappings)
 {
   auto mappings_table = Analysis::Mappings::get ();
 
@@ -3047,7 +3047,7 @@  ParamType::is_equal (const BaseType &other) const
 }
 
 ParamType *
-ParamType::handle_substitions (SubstitutionArgumentMappings subst_mappings)
+ParamType::handle_substitions (SubstitutionArgumentMappings &subst_mappings)
 {
   SubstitutionArg arg = SubstitutionArg::error ();
   bool ok = subst_mappings.get_argument_for_symbol (this, &arg);
@@ -3492,7 +3492,8 @@  ProjectionType::monomorphized_clone () const
 }
 
 ProjectionType *
-ProjectionType::handle_substitions (SubstitutionArgumentMappings subst_mappings)
+ProjectionType::handle_substitions (
+  SubstitutionArgumentMappings &subst_mappings)
 {
   // // do we really need to substitute this?
   // if (base->needs_generic_substitutions () || base->contains_type_parameters
diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h
index 85b3a3b7abc..1cf7131c1cb 100644
--- a/gcc/rust/typecheck/rust-tyty.h
+++ b/gcc/rust/typecheck/rust-tyty.h
@@ -304,7 +304,7 @@  public:
 
   bool is_concrete () const override final;
 
-  ParamType *handle_substitions (SubstitutionArgumentMappings mappings);
+  ParamType *handle_substitions (SubstitutionArgumentMappings &mappings);
 
 private:
   std::string symbol;
@@ -379,7 +379,7 @@  public:
 
   std::string get_name () const override final;
 
-  TupleType *handle_substitions (SubstitutionArgumentMappings mappings);
+  TupleType *handle_substitions (SubstitutionArgumentMappings &mappings);
 
 private:
   std::vector<TyVar> fields;
@@ -427,7 +427,7 @@  public:
 
   // WARNING THIS WILL ALWAYS RETURN NULLPTR
   BaseType *
-  handle_substitions (SubstitutionArgumentMappings mappings) override final;
+  handle_substitions (SubstitutionArgumentMappings &mappings) override final;
 
   bool is_error () const;
 
@@ -682,7 +682,7 @@  public:
   }
 
   ADTType *
-  handle_substitions (SubstitutionArgumentMappings mappings) override final;
+  handle_substitions (SubstitutionArgumentMappings &mappings) override final;
 
 private:
   std::string identifier;
@@ -815,7 +815,7 @@  public:
   }
 
   FnType *
-  handle_substitions (SubstitutionArgumentMappings mappings) override final;
+  handle_substitions (SubstitutionArgumentMappings &mappings) override final;
 
   ABI get_abi () const { return abi; }
 
@@ -965,7 +965,7 @@  public:
   }
 
   ClosureType *
-  handle_substitions (SubstitutionArgumentMappings mappings) override final;
+  handle_substitions (SubstitutionArgumentMappings &mappings) override final;
 
   TyTy::TupleType &get_parameters () const { return *parameters; }
   TyTy::BaseType &get_result_type () const { return *result_type.get_tyty (); }
@@ -1024,7 +1024,7 @@  public:
 
   HIR::Expr &get_capacity_expr () const { return capacity_expr; }
 
-  ArrayType *handle_substitions (SubstitutionArgumentMappings mappings);
+  ArrayType *handle_substitions (SubstitutionArgumentMappings &mappings);
 
 private:
   TyVar element_type;
@@ -1070,7 +1070,7 @@  public:
     return get_element_type ()->is_concrete ();
   }
 
-  SliceType *handle_substitions (SubstitutionArgumentMappings mappings);
+  SliceType *handle_substitions (SubstitutionArgumentMappings &mappings);
 
 private:
   TyVar element_type;
@@ -1321,7 +1321,7 @@  public:
 
   bool is_concrete () const override final;
 
-  ReferenceType *handle_substitions (SubstitutionArgumentMappings mappings);
+  ReferenceType *handle_substitions (SubstitutionArgumentMappings &mappings);
 
   Mutability mutability () const;
 
@@ -1364,7 +1364,7 @@  public:
 
   bool is_concrete () const override final;
 
-  PointerType *handle_substitions (SubstitutionArgumentMappings mappings);
+  PointerType *handle_substitions (SubstitutionArgumentMappings &mappings);
 
   Mutability mutability () const;
   bool is_mutable () const;
@@ -1500,7 +1500,7 @@  public:
   bool is_concrete () const override final;
 
   ProjectionType *
-  handle_substitions (SubstitutionArgumentMappings mappings) override final;
+  handle_substitions (SubstitutionArgumentMappings &mappings) override final;
 
 private:
   BaseType *base;