public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] Add new as_name interface for Dynamic types
@ 2022-06-08 12:41 Thomas Schwinge
  0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2022-06-08 12:41 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:d6fb62465635d67a420285c361d74b41c556e9dc

commit d6fb62465635d67a420285c361d74b41c556e9dc
Author: Philip Herron <philip.herron@embecosm.com>
Date:   Sat Apr 30 13:44:16 2022 +0100

    Add new as_name interface for Dynamic types
    
    The Gimple names of our dyn trait objects were looking like:
    
      const struct dyn [HIR Trait: FnLike->[C: 0 Nid: 31 Hid: 38 Lid: 13] [(FN call ), ]<Self, &isize, &isize>] & const f
    
    This is a horrible name but useful for debugging this patch fixes this so
    we have a seperate naming for generating the type. So now it looks like:
    
      const struct dyn [FnLike<Self, &isize, &isize>] & const f

Diff:
---
 gcc/rust/typecheck/rust-tyty-bounds.cc | 20 ++++++++++++++++++++
 gcc/rust/typecheck/rust-tyty.cc        |  3 +--
 gcc/rust/typecheck/rust-tyty.h         |  4 ++++
 3 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/gcc/rust/typecheck/rust-tyty-bounds.cc b/gcc/rust/typecheck/rust-tyty-bounds.cc
index bda7a7f47a6..7a1562ab544 100644
--- a/gcc/rust/typecheck/rust-tyty-bounds.cc
+++ b/gcc/rust/typecheck/rust-tyty-bounds.cc
@@ -215,6 +215,12 @@ TypeBoundPredicate::as_string () const
   return get ()->as_string () + subst_as_string ();
 }
 
+std::string
+TypeBoundPredicate::as_name () const
+{
+  return get ()->get_name () + subst_as_string ();
+}
+
 const Resolver::TraitReference *
 TypeBoundPredicate::get () const
 {
@@ -432,6 +438,20 @@ TypeBoundsMappings::bounds_as_string () const
   return "bounds:[" + raw_bounds_as_string () + "]";
 }
 
+std::string
+TypeBoundsMappings::raw_bounds_as_name () const
+{
+  std::string buf;
+  for (size_t i = 0; i < specified_bounds.size (); i++)
+    {
+      const TypeBoundPredicate &b = specified_bounds.at (i);
+      bool has_next = (i + 1) < specified_bounds.size ();
+      buf += b.as_name () + (has_next ? " + " : "");
+    }
+
+  return buf;
+}
+
 void
 TypeBoundsMappings::add_bound (TypeBoundPredicate predicate)
 {
diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc
index 6fc395c572b..fcbf9986d7d 100644
--- a/gcc/rust/typecheck/rust-tyty.cc
+++ b/gcc/rust/typecheck/rust-tyty.cc
@@ -2867,8 +2867,7 @@ DynamicObjectType::clone () const
 std::string
 DynamicObjectType::get_name () const
 {
-  std::string bounds = "[" + raw_bounds_as_string () + "]";
-  return "dyn " + bounds;
+  return "dyn [" + raw_bounds_as_name () + "]";
 }
 
 bool
diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h
index e2f1aa49c8b..b00237c1c27 100644
--- a/gcc/rust/typecheck/rust-tyty.h
+++ b/gcc/rust/typecheck/rust-tyty.h
@@ -124,6 +124,8 @@ public:
 
   std::string bounds_as_string () const;
 
+  std::string raw_bounds_as_name () const;
+
 protected:
   void add_bound (TypeBoundPredicate predicate);
 
@@ -1019,6 +1021,8 @@ public:
 
   std::string as_string () const;
 
+  std::string as_name () const;
+
   const Resolver::TraitReference *get () const;
 
   Location get_locus () const { return locus; }


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

only message in thread, other threads:[~2022-06-08 12:41 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:41 [gcc/devel/rust/master] Add new as_name interface for Dynamic types 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).