public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] Unify generic substitutions on unit-structs
@ 2022-08-09 20:39 Thomas Schwinge
  0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2022-08-09 20:39 UTC (permalink / raw)
  To: gcc-cvs

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

commit b9840366b6e4f2bba8f3c67a4ee805d9f4f3c1c5
Author: Philip Herron <philip.herron@embecosm.com>
Date:   Mon Aug 8 17:07:42 2022 +0100

    Unify generic substitutions on unit-structs
    
    When we have generic unit-structs there are no fields to unify the generic.
    This adds a case to ensure we iterate and check these. We might end up
    making it always do this for all structs always.
    
    Addresses #1447

Diff:
---
 gcc/rust/typecheck/rust-tyty-coercion.h | 22 ++++++++++++++++++++++
 gcc/rust/typecheck/rust-tyty-rules.h    | 22 ++++++++++++++++++++++
 2 files changed, 44 insertions(+)

diff --git a/gcc/rust/typecheck/rust-tyty-coercion.h b/gcc/rust/typecheck/rust-tyty-coercion.h
index 34267b30838..ed1636593c5 100644
--- a/gcc/rust/typecheck/rust-tyty-coercion.h
+++ b/gcc/rust/typecheck/rust-tyty-coercion.h
@@ -1130,6 +1130,28 @@ public:
 	  }
       }
 
+    // generic args for the unit-struct case
+    if (type.is_unit () && base->is_unit ())
+      {
+	rust_assert (type.get_num_substitutions ()
+		     == base->get_num_substitutions ());
+
+	for (size_t i = 0; i < type.get_num_substitutions (); i++)
+	  {
+	    auto &a = base->get_substs ().at (i);
+	    auto &b = type.get_substs ().at (i);
+
+	    auto pa = a.get_param_ty ();
+	    auto pb = b.get_param_ty ();
+
+	    auto res = pa->unify (pb);
+	    if (res->get_kind () == TyTy::TypeKind::ERROR)
+	      {
+		return;
+	      }
+	  }
+      }
+
     resolved = type.clone ();
   }
 
diff --git a/gcc/rust/typecheck/rust-tyty-rules.h b/gcc/rust/typecheck/rust-tyty-rules.h
index ad2d4b79b00..77d912a5921 100644
--- a/gcc/rust/typecheck/rust-tyty-rules.h
+++ b/gcc/rust/typecheck/rust-tyty-rules.h
@@ -1128,6 +1128,28 @@ public:
 	  }
       }
 
+    // generic args for the unit-struct case
+    if (type.is_unit () && base->is_unit ())
+      {
+	rust_assert (type.get_num_substitutions ()
+		     == base->get_num_substitutions ());
+
+	for (size_t i = 0; i < type.get_num_substitutions (); i++)
+	  {
+	    auto &a = base->get_substs ().at (i);
+	    auto &b = type.get_substs ().at (i);
+
+	    auto pa = a.get_param_ty ();
+	    auto pb = b.get_param_ty ();
+
+	    auto res = pa->unify (pb);
+	    if (res->get_kind () == TyTy::TypeKind::ERROR)
+	      {
+		return;
+	      }
+	  }
+      }
+
     resolved = type.clone ();
   }


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

only message in thread, other threads:[~2022-08-09 20:39 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-09 20:39 [gcc/devel/rust/master] Unify generic substitutions on unit-structs 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).