]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.typeparams] cmd/compile: fix unified IR support for //go:nointerface
authorMatthew Dempsky <mdempsky@google.com>
Fri, 2 Jul 2021 23:59:01 +0000 (16:59 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Mon, 26 Jul 2021 18:43:12 +0000 (18:43 +0000)
This CL changes fixedbugs/issue30862.go into a "runindir" test so that
it can use '-goexperiment fieldtrack' and test that //go:nointerface
works with cmd/compile. In particular, this revealed that -G=3 and
unified IR did not handle it correctly.

This CL also fixes unified IR's support for //go:nointerface and adds
a test that checks that //go:nointerface, promoted methods, and
generics all interact as expected.

Updates #47045.

Change-Id: Ib8acff8ae18bf124520d00c98e8915699cba2abd
Reviewed-on: https://go-review.googlesource.com/c/go/+/332611
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
src/cmd/compile/internal/noder/reader.go
test/fixedbugs/issue30862.dir/a/a.go [moved from test/fixedbugs/issue30862.dir/a.go with 100% similarity]
test/fixedbugs/issue30862.dir/b/b.go [moved from test/fixedbugs/issue30862.dir/b.go with 95% similarity]
test/fixedbugs/issue30862.dir/main.go
test/fixedbugs/issue30862.go
test/run.go
test/typeparam/mdempsky/15.go [new file with mode: 0644]

index 44d1c4f28be5903f43262ab3fdfa60e20b753443..516bf8f1f748ad5c112384c600d412d04460b9cd 100644 (file)
@@ -750,13 +750,12 @@ func (r *reader) method() *types.Field {
        name.Func = ir.NewFunc(r.pos())
        name.Func.Nname = name
 
-       // TODO(mdempsky): Make sure we're handling //go:nointerface
-       // correctly. I don't think this is exercised within the Go repo.
-
        r.ext.funcExt(name)
 
        meth := types.NewField(name.Func.Pos(), sym, typ)
        meth.Nname = name
+       meth.SetNointerface(name.Func.Pragma&ir.Nointerface != 0)
+
        return meth
 }
 
similarity index 95%
rename from test/fixedbugs/issue30862.dir/b.go
rename to test/fixedbugs/issue30862.dir/b/b.go
index 3e501bb8dcbdc7c853f614fba5b360d50d87c044..230221d5036248af1c1c80415a675cc55f8ee16e 100644 (file)
@@ -4,7 +4,7 @@
 
 package b
 
-import "./a"
+import "issue30862.dir/a"
 
 type EmbedImported struct {
        a.NoitfStruct
index 80db0e13a84753fda986ebfc40c0bd3bdcda44d4..1489c5a34255fbb01b93700bd1150d90de93920a 100644 (file)
@@ -8,7 +8,7 @@ import (
        "fmt"
        "os"
 
-       "./b"
+       "issue30862.dir/b"
 )
 
 // Test case for issue 30862.
index ba122cc3c8b805b931660d3c39c36db48ddb2e9c..acac71e2ccabd4d85c16b9e38265f93f03af0652 100644 (file)
@@ -1,4 +1,4 @@
-// rundir
+// runindir -goexperiment fieldtrack
 
 // Copyright 2019 The Go Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style
@@ -9,6 +9,4 @@
 // is set when building it, whereas gccgo has field tracking
 // enabled by default (hence the build tag below).
 
-// +build gccgo
-
 package ignored
index 1e7fab4359d022ec6d050573739b4772a52c3fa1..2e72d55b7610d722e1e0706e91197c6638fc2f06 100644 (file)
@@ -2180,12 +2180,14 @@ var types2Failures32Bit = setOf(
 var g3Failures = setOf(
        "writebarrier.go", // correct diagnostics, but different lines (probably irgen's fault)
 
+       "fixedbugs/issue30862.go", // -G=3 doesn't handle //go:nointerface
+
+       "typeparam/cons.go",   // causes an unreachable method
        "typeparam/nested.go", // -G=3 doesn't support function-local types with generics
 
        "typeparam/mdempsky/4.go",  // -G=3 can't export functions with labeled breaks in loops
        "typeparam/mdempsky/13.go", // problem with interface as as a type arg.
-
-       "typeparam/cons.go", // causes an unreachable method
+       "typeparam/mdempsky/15.go", // ICE in (*irgen).buildClosure
 )
 
 var unifiedFailures = setOf(
diff --git a/test/typeparam/mdempsky/15.go b/test/typeparam/mdempsky/15.go
new file mode 100644 (file)
index 0000000..4899fc7
--- /dev/null
@@ -0,0 +1,69 @@
+// run -goexperiment fieldtrack -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.
+
+// Test that generics, promoted methods, and //go:nointerface
+// interoperate as expected.
+
+package main
+
+import (
+       "reflect"
+)
+
+func TypeString[T any]() string {
+       return reflect.TypeOf(new(T)).Elem().String()
+}
+
+func Test[T, Bad, Good any]() {
+       switch interface{}(new(T)).(type) {
+       case Bad:
+               println("FAIL:", TypeString[T](), "matched", TypeString[Bad]())
+       case Good:
+               // ok
+       default:
+               println("FAIL:", TypeString[T](), "did not match", TypeString[Good]())
+       }
+}
+
+func TestE[T any]() { Test[T, interface{ EBad() }, interface{ EGood() }]() }
+func TestX[T any]() { Test[T, interface{ XBad() }, interface{ XGood() }]() }
+
+type E struct{}
+
+//go:nointerface
+func (E) EBad()  {}
+func (E) EGood() {}
+
+type X[T any] struct{ E }
+
+//go:nointerface
+func (X[T]) XBad()  {}
+func (X[T]) XGood() {}
+
+type W struct{ X[int] }
+
+func main() {
+       _ = E.EGood
+       _ = E.EBad
+
+       TestE[E]()
+
+       _ = X[int].EGood
+       _ = X[int].EBad
+       _ = X[int].XGood
+       _ = X[int].XBad
+
+       TestE[X[int]]()
+       TestX[X[int]]()
+
+       _ = W.EGood
+       _ = W.EBad
+       _ = W.XGood
+       _ = W.XBad
+
+       TestE[W]()
+       TestX[W]()
+}