public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Go patch committed: Move lowering pass after check types pass
@ 2023-12-19  1:32 Ian Lance Taylor
  2024-01-19  4:49 ` Ian Lance Taylor
  0 siblings, 1 reply; 2+ messages in thread
From: Ian Lance Taylor @ 2023-12-19  1:32 UTC (permalink / raw)
  To: gofrontend-dev, gcc-patches

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

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.

Ian

[-- Attachment #2: patch.txt.bz2 --]
[-- Type: application/x-bzip, Size: 46117 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Go patch committed: Move lowering pass after check types pass
  2023-12-19  1:32 Go patch committed: Move lowering pass after check types pass Ian Lance Taylor
@ 2024-01-19  4:49 ` Ian Lance Taylor
  0 siblings, 0 replies; 2+ messages in thread
From: Ian Lance Taylor @ 2024-01-19  4:49 UTC (permalink / raw)
  To: gofrontend-dev, gcc-patches

[-- 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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-01-19  4:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-19  1:32 Go patch committed: Move lowering pass after check types pass Ian Lance Taylor
2024-01-19  4:49 ` Ian Lance Taylor

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).