public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] Handle generic Slices and Arrays
@ 2022-06-08 12:17 Thomas Schwinge
  0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2022-06-08 12:17 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:894e9d29adadc13e9841f43df32a07939480846d

commit 894e9d29adadc13e9841f43df32a07939480846d
Author: Philip Herron <philip.herron@embecosm.com>
Date:   Thu Mar 10 16:17:52 2022 +0000

    Handle generic Slices and Arrays
    
    Slices and Arrays are covariant types which means they can contain elements
    which bind generics such as ADT or FnTypes. This means substitutions can be
    recursive and this gives the typechecker a chance to handle this recursion
    on these types.

Diff:
---
 gcc/rust/typecheck/rust-substitution-mapper.h | 12 ++++++++--
 gcc/rust/typecheck/rust-tyty.cc               | 32 +++++++++++++++++++++++++++
 gcc/rust/typecheck/rust-tyty.h                |  4 ++++
 3 files changed, 46 insertions(+), 2 deletions(-)

diff --git a/gcc/rust/typecheck/rust-substitution-mapper.h b/gcc/rust/typecheck/rust-substitution-mapper.h
index 0d48bd2532c..5f1781635cc 100644
--- a/gcc/rust/typecheck/rust-substitution-mapper.h
+++ b/gcc/rust/typecheck/rust-substitution-mapper.h
@@ -221,11 +221,19 @@ public:
     resolved = type.handle_substitions (mappings);
   }
 
+  void visit (TyTy::ArrayType &type) override
+  {
+    resolved = type.handle_substitions (mappings);
+  }
+
+  void visit (TyTy::SliceType &type) override
+  {
+    resolved = type.handle_substitions (mappings);
+  }
+
   // nothing to do for these
   void visit (TyTy::InferType &) override { gcc_unreachable (); }
   void visit (TyTy::FnPtr &) override { gcc_unreachable (); }
-  void visit (TyTy::ArrayType &) override { gcc_unreachable (); }
-  void visit (TyTy::SliceType &) override { gcc_unreachable (); }
   void visit (TyTy::BoolType &) override { gcc_unreachable (); }
   void visit (TyTy::IntType &) override { gcc_unreachable (); }
   void visit (TyTy::UintType &) override { gcc_unreachable (); }
diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc
index 0a296445d59..8d5cc5e511a 100644
--- a/gcc/rust/typecheck/rust-tyty.cc
+++ b/gcc/rust/typecheck/rust-tyty.cc
@@ -1508,6 +1508,22 @@ ArrayType::clone () const
 			element_type, get_combined_refs ());
 }
 
+ArrayType *
+ArrayType::handle_substitions (SubstitutionArgumentMappings mappings)
+{
+  auto mappings_table = Analysis::Mappings::get ();
+
+  ArrayType *ref = static_cast<ArrayType *> (clone ());
+  ref->set_ty_ref (mappings_table->get_next_hir_id ());
+
+  // might be &T or &ADT so this needs to be recursive
+  auto base = ref->get_element_type ();
+  BaseType *concrete = Resolver::SubstMapperInternal::Resolve (base, mappings);
+  ref->element_type = TyVar (concrete->get_ty_ref ());
+
+  return ref;
+}
+
 void
 SliceType::accept_vis (TyVisitor &vis)
 {
@@ -1581,6 +1597,22 @@ SliceType::clone () const
 			get_combined_refs ());
 }
 
+SliceType *
+SliceType::handle_substitions (SubstitutionArgumentMappings mappings)
+{
+  auto mappings_table = Analysis::Mappings::get ();
+
+  SliceType *ref = static_cast<SliceType *> (clone ());
+  ref->set_ty_ref (mappings_table->get_next_hir_id ());
+
+  // might be &T or &ADT so this needs to be recursive
+  auto base = ref->get_element_type ();
+  BaseType *concrete = Resolver::SubstMapperInternal::Resolve (base, mappings);
+  ref->element_type = TyVar (concrete->get_ty_ref ());
+
+  return ref;
+}
+
 void
 BoolType::accept_vis (TyVisitor &vis)
 {
diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h
index bf4110baf76..82262abab09 100644
--- a/gcc/rust/typecheck/rust-tyty.h
+++ b/gcc/rust/typecheck/rust-tyty.h
@@ -1665,6 +1665,8 @@ public:
 
   HIR::Expr &get_capacity_expr () const { return capacity_expr; }
 
+  ArrayType *handle_substitions (SubstitutionArgumentMappings mappings);
+
 private:
   TyVar element_type;
   HIR::Expr &capacity_expr;
@@ -1710,6 +1712,8 @@ public:
     return get_element_type ()->is_concrete ();
   }
 
+  SliceType *handle_substitions (SubstitutionArgumentMappings mappings);
+
 private:
   TyVar element_type;
 };


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

only message in thread, other threads:[~2022-06-08 12:17 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-08 12:17 [gcc/devel/rust/master] Handle generic Slices and Arrays 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).