]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: skip exporting generic functions for -buildmode=plugin
authorMatthew Dempsky <mdempsky@google.com>
Tue, 17 May 2022 00:03:59 +0000 (17:03 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Tue, 17 May 2022 00:53:54 +0000 (00:53 +0000)
Generic functions require instantiation, which package plugin doesn't
support, and likely never will. So instead, we can just skip writing
out any generic functions, which avoids an ICE in the plugin
generation code.

This issue doesn't affect GOEXPERIMENT=unified, because it avoids
leaking any non-instantiated types/functions to the rest of the
compiler backend.

Fixes #52937.

Change-Id: Ie35529c5c241e46b77fcb5b8cca48bb99ce7bfcb
Reviewed-on: https://go-review.googlesource.com/c/go/+/406358
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>

src/cmd/compile/internal/reflectdata/reflect.go
test/run.go
test/typeparam/issue52937.go [new file with mode: 0644]

index 5b44b7098d55b746ff0c041014b758a679acbe6a..d9f270871244785a98401c3be3b6389f45005b1d 100644 (file)
@@ -1726,6 +1726,9 @@ func CollectPTabs() {
                if s.Pkg.Name != "main" {
                        continue
                }
+               if n.Type().HasTParam() {
+                       continue // skip generic functions (#52937)
+               }
                ptabs = append(ptabs, n)
        }
 }
index 00f869bc2baaf3485befab0e338687d6c9e0227a..7553302a766726b85fadcf8784d6aa001e861cee 100644 (file)
@@ -993,7 +993,10 @@ func (t *test) run() {
 
        case "build":
                // Build Go file.
-               _, err := runcmd(goTool(), "build", t.goGcflags(), "-o", "a.exe", long)
+               cmd := []string{goTool(), "build", t.goGcflags()}
+               cmd = append(cmd, flags...)
+               cmd = append(cmd, "-o", "a.exe", long)
+               _, err := runcmd(cmd...)
                if err != nil {
                        t.err = err
                }
diff --git a/test/typeparam/issue52937.go b/test/typeparam/issue52937.go
new file mode 100644 (file)
index 0000000..efcb69a
--- /dev/null
@@ -0,0 +1,14 @@
+// build -buildmode=plugin
+
+//go:build !js
+// +build !js
+
+// Copyright 2022 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 main()      {}
+func F[T any]()  {}
+func G[T any](T) {}