public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Thomas Schwinge <tschwinge@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc/devel/rust/master] Support type resolution on super traits on dyn objects
Date: Fri, 14 Oct 2022 12:45:53 +0000 (GMT)	[thread overview]
Message-ID: <20221014124553.477A13858C83@sourceware.org> (raw)

https://gcc.gnu.org/g:32e45c4076c6eed1a632498844c4f1189b4576d1

commit 32e45c4076c6eed1a632498844c4f1189b4576d1
Author: Philip Herron <philip.herron@embecosm.com>
Date:   Thu Oct 6 14:46:17 2022 +0100

    Support type resolution on super traits on dyn objects
    
    When checking if specified bounds satisfy other bounds we must lookup the
    super traits. To finish the support for super traits we need to redo the
    computation of method addresses to support super traits.
    
    Addresses #914

Diff:
---
 gcc/rust/backend/rust-compile.cc        |  2 ++
 gcc/rust/typecheck/rust-hir-trait-ref.h | 24 ++++++++++++++++++++++
 gcc/rust/typecheck/rust-tyty.cc         | 35 +++++++++++----------------------
 3 files changed, 37 insertions(+), 24 deletions(-)

diff --git a/gcc/rust/backend/rust-compile.cc b/gcc/rust/backend/rust-compile.cc
index 0ccb98d9e12..0c72a167a70 100644
--- a/gcc/rust/backend/rust-compile.cc
+++ b/gcc/rust/backend/rust-compile.cc
@@ -247,6 +247,8 @@ HIRCompileBase::compute_address_for_trait_item (
   // Algo:
   // check if there is an impl-item for this trait-item-ref first
   // else assert that the trait-item-ref has an implementation
+  //
+  // FIXME this does not support super traits
 
   TyTy::TypeBoundPredicateItem predicate_item
     = predicate->lookup_associated_item (ref->get_identifier ());
diff --git a/gcc/rust/typecheck/rust-hir-trait-ref.h b/gcc/rust/typecheck/rust-hir-trait-ref.h
index 0f4883d6ba3..d0814f60eaf 100644
--- a/gcc/rust/typecheck/rust-hir-trait-ref.h
+++ b/gcc/rust/typecheck/rust-hir-trait-ref.h
@@ -380,6 +380,16 @@ public:
     return item_refs;
   }
 
+  void get_trait_items_and_supers (
+    std::vector<const TraitItemReference *> &result) const
+  {
+    for (const auto &item : item_refs)
+      result.push_back (&item);
+
+    for (const auto &super_trait : super_traits)
+      super_trait->get_trait_items_and_supers (result);
+  }
+
   void on_resolved ()
   {
     for (auto &item : item_refs)
@@ -451,6 +461,20 @@ public:
     return trait_substs;
   }
 
+  bool satisfies_bound (const TraitReference &reference) const
+  {
+    if (is_equal (reference))
+      return true;
+
+    for (const auto &super_trait : super_traits)
+      {
+	if (super_trait->satisfies_bound (reference))
+	  return true;
+      }
+
+    return false;
+  }
+
 private:
   const HIR::Trait *hir_trait_ref;
   std::vector<TraitItemReference> item_refs;
diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc
index b9a93186208..65b9f816004 100644
--- a/gcc/rust/typecheck/rust-tyty.cc
+++ b/gcc/rust/typecheck/rust-tyty.cc
@@ -136,22 +136,18 @@ bool
 BaseType::satisfies_bound (const TypeBoundPredicate &predicate) const
 {
   const Resolver::TraitReference *query = predicate.get ();
-  for (auto &bound : specified_bounds)
+  for (const auto &bound : specified_bounds)
     {
       const Resolver::TraitReference *item = bound.get ();
-      bool found = item->get_mappings ().get_defid ()
-		   == query->get_mappings ().get_defid ();
-      if (found)
+      if (item->satisfies_bound (*query))
 	return true;
     }
 
   auto probed = Resolver::TypeBoundsProbe::Probe (this);
-  for (auto &b : probed)
+  for (const auto &b : probed)
     {
       const Resolver::TraitReference *bound = b.first;
-      bool found = bound->get_mappings ().get_defid ()
-		   == query->get_mappings ().get_defid ();
-      if (found)
+      if (bound->satisfies_bound (*query))
 	return true;
     }
 
@@ -191,7 +187,6 @@ BaseType::bounds_compatible (const BaseType &other, Location locus,
 	  rust_error_at (r,
 			 "bounds not satisfied for %s %<%s%> is not satisfied",
 			 other.get_name ().c_str (), missing_preds.c_str ());
-	  // rust_assert (!emit_error);
 	}
     }
 
@@ -2956,23 +2951,15 @@ DynamicObjectType::get_object_items () const
   for (auto &bound : get_specified_bounds ())
     {
       const Resolver::TraitReference *trait = bound.get ();
-      for (auto &item : trait->get_trait_items ())
-	{
-	  if (item.get_trait_item_type ()
-		== Resolver::TraitItemReference::TraitItemType::FN
-	      && item.is_object_safe ())
-	    items.push_back ({&item, &bound});
-	}
+      std::vector<const Resolver::TraitItemReference *> trait_items;
+      trait->get_trait_items_and_supers (trait_items);
 
-      for (auto &super_trait : trait->get_super_traits ())
+      for (auto &item : trait_items)
 	{
-	  for (auto &item : super_trait->get_trait_items ())
-	    {
-	      if (item.get_trait_item_type ()
-		    == Resolver::TraitItemReference::TraitItemType::FN
-		  && item.is_object_safe ())
-		items.push_back ({&item, &bound});
-	    }
+	  if (item->get_trait_item_type ()
+		== Resolver::TraitItemReference::TraitItemType::FN
+	      && item->is_object_safe ())
+	    items.push_back ({item, &bound});
 	}
     }
   return items;

                 reply	other threads:[~2022-10-14 12:45 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221014124553.477A13858C83@sourceware.org \
    --to=tschwinge@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).