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] gccrs: Allow infer vars on the lhs too
Date: Tue, 28 Feb 2023 22:37:14 +0000 (GMT)	[thread overview]
Message-ID: <20230228223714.B8BA6385841C@sourceware.org> (raw)

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

commit bd4556fb65c64396fc6a429bc03b58932dc3c263
Author: Philip Herron <herron.philip@googlemail.com>
Date:   Mon Feb 27 13:34:30 2023 +0000

    gccrs: Allow infer vars on the lhs too
    
    We should allow implicit inference on the expected side too not just the
    receiver.
    
    Signed-off-by: Philip Herron <herron.philip@googlemail.com>
    
    gcc/rust/ChangeLog:
    
            * typecheck/rust-unify.cc (UnifyRules::go): allow lhs infer vars

Diff:
---
 gcc/rust/typecheck/rust-unify.cc | 58 +++++++++++++++++++++++++++++-----------
 1 file changed, 42 insertions(+), 16 deletions(-)

diff --git a/gcc/rust/typecheck/rust-unify.cc b/gcc/rust/typecheck/rust-unify.cc
index 37ef71ec22e..70210aacdcd 100644
--- a/gcc/rust/typecheck/rust-unify.cc
+++ b/gcc/rust/typecheck/rust-unify.cc
@@ -149,26 +149,52 @@ UnifyRules::go ()
 	}
     }
 
-  // inject inference vars if required
-  bool got_param = rtype->get_kind () == TyTy::TypeKind::PARAM;
-  bool lhs_is_infer_var = ltype->get_kind () == TyTy::TypeKind::INFER;
-  bool expected_is_concrete = ltype->is_concrete () && !lhs_is_infer_var;
-  bool needs_infer = expected_is_concrete && got_param;
-  if (infer_flag && needs_infer)
+  if (infer_flag)
     {
-      TyTy::ParamType *p = static_cast<TyTy::ParamType *> (rtype);
-      TyTy::TyVar iv = TyTy::TyVar::get_implicit_infer_var (rhs.get_locus ());
-      rust_assert (iv.get_tyty ()->get_kind () == TyTy::TypeKind::INFER);
-      TyTy::InferType *i = static_cast<TyTy::InferType *> (iv.get_tyty ());
+      bool rgot_param = rtype->get_kind () == TyTy::TypeKind::PARAM;
+      bool lhs_is_infer_var = ltype->get_kind () == TyTy::TypeKind::INFER;
+      bool expected_is_concrete = ltype->is_concrete () && !lhs_is_infer_var;
+      bool rneeds_infer = expected_is_concrete && rgot_param;
 
-      infers.push_back ({p->get_ref (), p->get_ty_ref (), p, i});
+      bool lgot_param = ltype->get_kind () == TyTy::TypeKind::PARAM;
+      bool rhs_is_infer_var = rtype->get_kind () == TyTy::TypeKind::INFER;
+      bool receiver_is_concrete = rtype->is_concrete () && !rhs_is_infer_var;
+      bool lneeds_infer = receiver_is_concrete && lgot_param;
 
-      // FIXME
-      // this is hacky to set the implicit param lets make this a function
-      p->set_ty_ref (i->get_ref ());
+      if (rneeds_infer)
+	{
+	  TyTy::ParamType *p = static_cast<TyTy::ParamType *> (rtype);
+	  TyTy::TyVar iv
+	    = TyTy::TyVar::get_implicit_infer_var (rhs.get_locus ());
+	  rust_assert (iv.get_tyty ()->get_kind () == TyTy::TypeKind::INFER);
+	  TyTy::InferType *i = static_cast<TyTy::InferType *> (iv.get_tyty ());
+
+	  infers.push_back ({p->get_ref (), p->get_ty_ref (), p, i});
+
+	  // FIXME
+	  // this is hacky to set the implicit param lets make this a function
+	  p->set_ty_ref (i->get_ref ());
+
+	  // set the rtype now to the new inference var
+	  rtype = i;
+	}
+      else if (lneeds_infer)
+	{
+	  TyTy::ParamType *p = static_cast<TyTy::ParamType *> (ltype);
+	  TyTy::TyVar iv
+	    = TyTy::TyVar::get_implicit_infer_var (lhs.get_locus ());
+	  rust_assert (iv.get_tyty ()->get_kind () == TyTy::TypeKind::INFER);
+	  TyTy::InferType *i = static_cast<TyTy::InferType *> (iv.get_tyty ());
+
+	  infers.push_back ({p->get_ref (), p->get_ty_ref (), p, i});
 
-      // set the rtype now to the new inference var
-      rtype = i;
+	  // FIXME
+	  // this is hacky to set the implicit param lets make this a function
+	  p->set_ty_ref (i->get_ref ());
+
+	  // set the rtype now to the new inference var
+	  ltype = i;
+	}
     }
 
   switch (ltype->get_kind ())

                 reply	other threads:[~2023-02-28 22:37 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=20230228223714.B8BA6385841C@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).