public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] gccrs: Refactor handle_substitutions to take a reference
@ 2023-02-07 17:55 Thomas Schwinge
  0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2023-02-07 17:55 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:50856ddba4689710dd53865e96cc7da9885b7b51

commit 50856ddba4689710dd53865e96cc7da9885b7b51
Author: Philip Herron <herron.philip@googlemail.com>
Date:   Fri Jan 27 18:28:06 2023 +0000

    gccrs: Refactor handle_substitutions to take a reference
    
    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

Diff:
---
 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(-)

diff --git a/gcc/rust/typecheck/rust-tyty-bounds.cc b/gcc/rust/typecheck/rust-tyty-bounds.cc
index a307dd34c38..414111c7ba7 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 7465b6f3925..3a642b69b47 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 3dd97cef35b..900b64d1c4c 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;

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-02-07 17:55 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-07 17:55 [gcc/devel/rust/master] gccrs: Refactor handle_substitutions to take a reference Thomas Schwinge

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).