public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Ian Lance Taylor <iant@golang.org>
To: gofrontend-dev <gofrontend-dev@googlegroups.com>,
	gcc-patches <gcc-patches@gcc.gnu.org>
Subject: Re: Go patch committed: Move lowering pass after check types pass
Date: Thu, 18 Jan 2024 20:49:14 -0800	[thread overview]
Message-ID: <CAOyqgcXrh34QMJjequqs0r+YTkuiKgfzia66o_Pf31+YC3r9rg@mail.gmail.com> (raw)
In-Reply-To: <CAOyqgcUEoynrUfZpbd8RrSRi-x0pXVEiFZXiiHZHJGw+-xDnQg@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1760 bytes --]

On Mon, Dec 18, 2023 at 5:32 PM Ian Lance Taylor <iant@golang.org> wrote:
>
> This Go frontend patch moves the lowering pass after the type
> determination and the type checking passes.  This lets us simplify
> some of the code that determines the type of an expression, which
> previously had to work correctly both before and after type
> determination.
>
> I'm doing this to help with future generic support.  For example, with
> generics, we can see code like
>
>     func ident[T any](v T) T { return v }
>
>     func F() int32 {
>         s := int32(1)
>         return ident(s)
>     }
>
> Before this change, we would type check return statements in the
> lowering pass (see Return_statement::do_lower).  With a generic
> example like the above, that means we have to determine the type of s,
> and use that to infer the type arguments passed to ident, and use that
> to determine the result type of ident.  That is too much to do at
> lowering time.  Of course we can change the way that return statements
> work, but similar issues arise with index expressions, the types of
> closures for function literals, and probably other cases as well.
>
> Rather than try to deal with all those cases, we move the lowering
> pass after type checking.  This requires a bunch of changes, notably
> for determining constant types.  We have to add type checking for
> various constructs that formerly disappeared in the lowering pass. So
> it's a lot of shuffling.  Sorry for the size of the patch.
>
> Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.  Committed
> to mainline.

Sorry, I forgot to commit the changes to some of the test files.  I've
committed this patch to fix them.  This fixes PR 113447.

Ian

[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 2854 bytes --]

3d7820c58f9466a80916dfa50dcdfde457b4c597
diff --git a/gcc/testsuite/go.test/test/fixedbugs/issue20185.go b/gcc/testsuite/go.test/test/fixedbugs/issue20185.go
index 9065868d7f2..24d74f09126 100644
--- a/gcc/testsuite/go.test/test/fixedbugs/issue20185.go
+++ b/gcc/testsuite/go.test/test/fixedbugs/issue20185.go
@@ -10,7 +10,7 @@
 package p
 
 func F() {
-	switch t := nil.(type) { // ERROR "cannot type switch on non-interface value"
+	switch t := nil.(type) { // ERROR "cannot type switch on non-interface value|defined to nil type"
 	default:
 		_ = t
 	}
diff --git a/gcc/testsuite/go.test/test/fixedbugs/issue33386.go b/gcc/testsuite/go.test/test/fixedbugs/issue33386.go
index 7b2f565285e..c5073910a4c 100644
--- a/gcc/testsuite/go.test/test/fixedbugs/issue33386.go
+++ b/gcc/testsuite/go.test/test/fixedbugs/issue33386.go
@@ -18,7 +18,7 @@ func _() {
 
 func _() {
 	defer func() { // no error here about deferred function
-		1 +    // GCCGO_ERROR "value computed is not used"
+		1 +
 	}()            // ERROR "expecting expression|expected operand"
 }
 
diff --git a/gcc/testsuite/go.test/test/fixedbugs/issue4085a.go b/gcc/testsuite/go.test/test/fixedbugs/issue4085a.go
index 200290a081d..f457fcf2b12 100644
--- a/gcc/testsuite/go.test/test/fixedbugs/issue4085a.go
+++ b/gcc/testsuite/go.test/test/fixedbugs/issue4085a.go
@@ -10,9 +10,9 @@ type T []int
 
 func main() {
 	_ = make(T, -1)    // ERROR "negative"
-	_ = make(T, 0.5)   // ERROR "constant 0.5 truncated to integer|non-integer len argument"
+	_ = make(T, 0.5)   // ERROR "truncated to integer|non-integer len argument"
 	_ = make(T, 1.0)   // ok
-	_ = make(T, 1<<63) // ERROR "len argument too large"
+	_ = make(T, 1<<63) // ERROR "integer constant overflow|len argument too large"
 	_ = make(T, 0, -1) // ERROR "negative cap"
 	_ = make(T, 10, 0) // ERROR "len larger than cap"
 }
diff --git a/gcc/testsuite/go.test/test/shift1.go b/gcc/testsuite/go.test/test/shift1.go
index d6a6c38839f..3b1aa9e6900 100644
--- a/gcc/testsuite/go.test/test/shift1.go
+++ b/gcc/testsuite/go.test/test/shift1.go
@@ -189,12 +189,12 @@ func _() {
 	var m1 map[int]string
 	delete(m1, 1<<s)
 	delete(m1, 1.<<s)
-	delete(m1, 1.1<<s) // ERROR "truncated|shift of type float64"
+	delete(m1, 1.1<<s) // ERROR "truncated|shift of type float64|incompatible|non-integer"
 
 	var m2 map[float32]string
-	delete(m2, 1<<s)   // ERROR "invalid|cannot use 1 << s as type float32"
-	delete(m2, 1.<<s)  // ERROR "invalid|cannot use 1 << s as type float32"
-	delete(m2, 1.1<<s) // ERROR "invalid|cannot use 1.1 << s as type float32"
+	delete(m2, 1<<s)   // ERROR "invalid|cannot use 1 << s as type float32|incompatible"
+	delete(m2, 1.<<s)  // ERROR "invalid|cannot use 1 << s as type float32|incompatible"
+	delete(m2, 1.1<<s) // ERROR "invalid|cannot use 1.1 << s as type float32|incompatible"
 }
 
 // shifts of shifts

      reply	other threads:[~2024-01-19  4:49 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-19  1:32 Ian Lance Taylor
2024-01-19  4:49 ` Ian Lance Taylor [this message]

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=CAOyqgcXrh34QMJjequqs0r+YTkuiKgfzia66o_Pf31+YC3r9rg@mail.gmail.com \
    --to=iant@golang.org \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=gofrontend-dev@googlegroups.com \
    /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).