[dev.typeparams] test: add regress tests that fail(ed) with -G=3

This CL includes multiple test cases that exercise unique failures
with -G=3 mode that did not affect unified IR mode. Most of these were
found over a period of about 3 hours of manual experimentation.

Thanks to Cuong Manh Le for test cases 11 and 12.

Updates #46704.

Change-Id: Ia2fa619536732b121b6c929329065c85b9384511
Reviewed-on: https://go-review.googlesource.com/c/go/+/326169
Trust: Matthew Dempsky <mdempsky@google.com>
Trust: Dan Scales <danscales@google.com>
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
Matthew Dempsky 2021-06-08 11:57:11 -07:00
parent 49ade6b298
commit 5c42b6a953
29 changed files with 352 additions and 1 deletions

View file

@ -86,7 +86,7 @@ var (
// dirs are the directories to look for *.go files in.
// TODO(bradfitz): just use all directories?
dirs = []string{".", "ken", "chan", "interface", "syntax", "dwarf", "fixedbugs", "codegen", "runtime", "abi", "typeparam"}
dirs = []string{".", "ken", "chan", "interface", "syntax", "dwarf", "fixedbugs", "codegen", "runtime", "abi", "typeparam", "typeparam/mdempsky"}
// ratec controls the max number of tests running at a time.
ratec chan bool
@ -2203,6 +2203,19 @@ var g3Failures = setOf(
"fixedbugs/issue9691.go", // "cannot assign to int(.autotmp_4)" (probably irgen's fault)
"typeparam/nested.go", // -G=3 doesn't support function-local types with generics
"typeparam/mdempsky/1.go",
"typeparam/mdempsky/2.go",
"typeparam/mdempsky/3.go",
"typeparam/mdempsky/4.go",
"typeparam/mdempsky/5.go",
"typeparam/mdempsky/7.go",
"typeparam/mdempsky/8.go",
"typeparam/mdempsky/9.go",
"typeparam/mdempsky/11.go",
"typeparam/mdempsky/12.go",
"typeparam/mdempsky/13.go",
"typeparam/mdempsky/14.go",
)
var unifiedFailures = setOf(

View file

@ -0,0 +1,9 @@
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package a
type T[_ any] int
func F() { _ = new(T[int]) }

View file

@ -0,0 +1,9 @@
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import "./a"
func main() { a.F() }

View file

@ -0,0 +1,7 @@
// compiledir -G=3
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package ignored

View file

@ -0,0 +1,7 @@
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package a
type I[T any] interface{ M() T }

View file

@ -0,0 +1,17 @@
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import "./a"
var m = a.I[int].M
var never bool
func main() {
if never {
m(nil)
}
}

View file

@ -0,0 +1,7 @@
// rundir -G=3
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package ignored

View file

@ -0,0 +1,16 @@
// errorcheck
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Reported by Cuong Manh Le.
package p
type a struct{}
//go:notinheap
type b a
var _ = (*b)(new(a)) // ERROR "cannot convert"

View file

@ -0,0 +1,11 @@
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package a
type S[T any] struct {
F T
}
var X = S[int]{}

View file

@ -0,0 +1,13 @@
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"./a"
)
func main() {
_ = a.X
}

View file

@ -0,0 +1,9 @@
// rundir -G=3
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Reported by Cuong Manh Le.
package ignored

View file

@ -0,0 +1,38 @@
// run -gcflags=-G=3
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
type Mer interface{ M() }
func F[T Mer](expectPanic bool) {
defer func() {
err := recover()
if (err != nil) != expectPanic {
print("FAIL: (", err, " != nil) != ", expectPanic, "\n")
}
}()
var t T
T.M(t)
}
type MyMer int
func (MyMer) M() {}
func main() {
F[Mer](true)
F[struct{ Mer }](true)
F[*struct{ Mer }](true)
F[MyMer](false)
F[*MyMer](true)
F[struct{ MyMer }](false)
F[struct{ *MyMer }](true)
F[*struct{ MyMer }](true)
F[*struct{ *MyMer }](true)
}

View file

@ -0,0 +1,37 @@
// run -gcflags=-G=3
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
func Zero[T any]() (_ T) { return }
type T[X any] int
func (T[X]) M() {
var have interface{} = Zero[X]()
var want interface{} = Zero[MyInt]()
if have != want {
println("FAIL")
}
}
type I interface{ M() }
type MyInt int
type U = T[MyInt]
var x = U(0)
var i I = x
func main() {
x.M()
U.M(x)
(*U).M(&x)
i.M()
I.M(x)
}

View file

@ -0,0 +1,20 @@
// compile -G=3
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
type T[A, B, C any] int
func (T[A, B, C]) m(x int) {
if x <= 0 {
return
}
T[B, C, A](0).m(x - 1)
}
func main() {
T[int8, int16, int32](0).m(3)
}

View file

@ -0,0 +1,7 @@
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package a
func F[T interface{ chan int }](c T) {}

View file

@ -0,0 +1,9 @@
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package b
import "./a"
func g() { a.F(make(chan int)) }

View file

@ -0,0 +1,7 @@
// compiledir -G=3
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package ignored

View file

@ -0,0 +1,12 @@
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package a
func F[T any](T) {
Loop:
for {
break Loop
}
}

View file

@ -0,0 +1,9 @@
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package b
import "./a"
func f() { a.F(0) }

View file

@ -0,0 +1,7 @@
// compiledir -G=3
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package ignored

View file

@ -0,0 +1,15 @@
// compile -G=3
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package a
type X[T any] int
func (X[T]) F(T) {}
func x() {
X[interface{}](0).F(0)
}

View file

@ -0,0 +1,11 @@
// compile -G=3
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package a
type I[T any] interface{ M() T }
var _ = I[int].M

View file

@ -0,0 +1,9 @@
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package a
type I[T any] interface{ M() T }
var X I[int]

View file

@ -0,0 +1,9 @@
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package b
import "./a"
var _ = a.X

View file

@ -0,0 +1,7 @@
// compiledir -G=3
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package ignored

View file

@ -0,0 +1,7 @@
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package a
func F[T interface{ comparable }]() {}

View file

@ -0,0 +1,11 @@
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package b
import "./a"
func init() {
a.F[func()]() // ERROR "does not satisfy comparable"
}

View file

@ -0,0 +1,7 @@
// errorcheckdir -G=3
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package ignored

View file

@ -0,0 +1,11 @@
// compile -G=3
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package a
func f[V any]() []V { return []V{0: *new(V)} }
func g() { f[int]() }