public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] gccrs: get rid of can_eq in CoerceionRules selection
@ 2023-03-20  7:23 Thomas Schwinge
  0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2023-03-20  7:23 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:85a5abeb3748ef0fc18973e9139d9a18b7809661

commit 85a5abeb3748ef0fc18973e9139d9a18b7809661
Author: Philip Herron <herron.philip@googlemail.com>
Date:   Mon Mar 13 14:08:07 2023 +0000

    gccrs: get rid of can_eq in CoerceionRules selection
    
    The can_eq interface is very inconsistent so this begins the journey to
    remove this and also address part of #1981
    
    gcc/rust/ChangeLog:
    
            * typecheck/rust-coercion.cc (TypeCoercionRules::select): use new unify_and interface
            * typecheck/rust-hir-dot-operator.cc (MethodResolver::try_hook): grab bounds behind refs
    
    Signed-off-by: Philip Herron <herron.philip@googlemail.com>

Diff:
---
 gcc/rust/typecheck/rust-coercion.cc         | 19 ++++++++++++-------
 gcc/rust/typecheck/rust-hir-dot-operator.cc | 15 +++++++++++++++
 2 files changed, 27 insertions(+), 7 deletions(-)

diff --git a/gcc/rust/typecheck/rust-coercion.cc b/gcc/rust/typecheck/rust-coercion.cc
index 9831e77cdd0..7b91edfc73b 100644
--- a/gcc/rust/typecheck/rust-coercion.cc
+++ b/gcc/rust/typecheck/rust-coercion.cc
@@ -16,7 +16,6 @@
 // along with GCC; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
-#include "rust-hir-type-check-base.h"
 #include "rust-coercion.h"
 #include "rust-type-util.h"
 
@@ -417,12 +416,18 @@ TypeCoercionRules::select (TyTy::BaseType &autoderefed)
   rust_debug (
     "autoderef type-coercion select autoderefed={%s} can_eq expected={%s}",
     autoderefed.debug_str ().c_str (), expected->debug_str ().c_str ());
-  if (expected->can_eq (&autoderefed, false))
-    {
-      try_result = CoercionResult{adjustments, autoderefed.clone ()};
-      return true;
-    }
-  return false;
+
+  TyTy::BaseType *result
+    = unify_site_and (autoderefed.get_ref (), TyTy::TyWithLocation (expected),
+		      TyTy::TyWithLocation (&autoderefed),
+		      Location () /* locus */, false /*emit_errors*/,
+		      false /*commit_if_ok*/, true /*infer*/, true /*cleanup*/);
+  bool ok = result->get_kind () != TyTy::TypeKind::ERROR;
+  if (!ok)
+    return false;
+
+  try_result = CoercionResult{adjustments, autoderefed.clone ()};
+  return true;
 }
 
 /// Coercing a mutable reference to an immutable works, while
diff --git a/gcc/rust/typecheck/rust-hir-dot-operator.cc b/gcc/rust/typecheck/rust-hir-dot-operator.cc
index 9997e74b6bf..bfba0c35520 100644
--- a/gcc/rust/typecheck/rust-hir-dot-operator.cc
+++ b/gcc/rust/typecheck/rust-hir-dot-operator.cc
@@ -44,8 +44,23 @@ MethodResolver::Probe (TyTy::BaseType *receiver,
 void
 MethodResolver::try_hook (const TyTy::BaseType &r)
 {
+  rust_debug ("MethodResolver::try_hook get_predicate_items: [%s]",
+	      r.debug_str ().c_str ());
   const auto &specified_bounds = r.get_specified_bounds ();
   predicate_items = get_predicate_items (segment_name, r, specified_bounds);
+
+  if (predicate_items.size () > 0)
+    return;
+
+  if (r.get_kind () == TyTy::TypeKind::REF)
+    {
+      const auto &ref = static_cast<const TyTy::ReferenceType &> (r);
+      const auto &element = ref.get_var_element_type ();
+      const auto &element_ty = *element.get_tyty ();
+      const auto &specified_bounds = element_ty.get_specified_bounds ();
+      predicate_items
+	= get_predicate_items (segment_name, element_ty, specified_bounds);
+    }
 }
 
 bool

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

only message in thread, other threads:[~2023-03-20  7:23 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-20  7:23 [gcc/devel/rust/master] gccrs: get rid of can_eq in CoerceionRules selection 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).