]> Cypherpunks repositories - gostls13.git/commitdiff
go/internal/gcimporter: fix ureader.go handling of local defined types
authorMatthew Dempsky <mdempsky@google.com>
Fri, 16 Sep 2022 21:27:01 +0000 (14:27 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Mon, 19 Sep 2022 18:47:11 +0000 (18:47 +0000)
In unified IR, local defined types are promoted to a global defined
type with a "vargen" suffix. These shouldn't actually be exposed to
go/types users, because they're only relevant within function bodies,
which go/types doesn't support importing.

Moreover, in the case of defined types that were declared within a
generic function, they can have ambient type parameters, which the
go/types importer doesn't know how to handle (because they shouldn't
be needed for that use case).

While here, prune the gcimporter_test.go skip list, because some of
the listed failures have actually been fixed and all of them are
specific to the Go 1.18 (nounified) frontend. They all work correctly
with GOEXPERIMENT=unified.

Fixes #55110.

Change-Id: I7dd8b86355d910dfed1d47edbad7695144c3f84d
Reviewed-on: https://go-review.googlesource.com/c/go/+/431495
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/go/internal/gcimporter/gcimporter_test.go
src/go/internal/gcimporter/support.go
src/go/internal/gcimporter/ureader.go

index 54fda8620817390a7fcb69bc5cba871252ac19fc..8c86bac54cd377ea8f13f765e31eb61783172fb0 100644 (file)
@@ -173,13 +173,14 @@ func TestImportTypeparamTests(t *testing.T) {
                t.Fatal(err)
        }
 
-       skip := map[string]string{
-               "equal.go":      "inconsistent embedded sorting", // TODO(rfindley): investigate this.
-               "nested.go":     "fails to compile",              // TODO(rfindley): investigate this.
-               "issue50417.go": "inconsistent interface member sorting",
-               "issue53419.go": "fails to compile",
-               "issue53477.go": "fails to compile",
-               "issue55101.go": "fails to compile",
+       var skip map[string]string
+       if !goexperiment.Unified {
+               // The Go 1.18 frontend still fails several cases.
+               skip = map[string]string{
+                       "equal.go":      "inconsistent embedded sorting", // TODO(rfindley): investigate this.
+                       "nested.go":     "fails to compile",              // TODO(rfindley): investigate this.
+                       "issue55101.go": "fails to compile",
+               }
        }
 
        for _, entry := range list {
index af3b6cbbcc0b12fd224e1fb77133eac0fd31f9b6..7ed8c9a4043d1cf3e22af4678e30667c1c1757b0 100644 (file)
@@ -167,3 +167,17 @@ type typeInfo struct {
        idx     pkgbits.Index
        derived bool
 }
+
+// See cmd/compile/internal/types.SplitVargenSuffix.
+func splitVargenSuffix(name string) (base, suffix string) {
+       i := len(name)
+       for i > 0 && name[i-1] >= '0' && name[i-1] <= '9' {
+               i--
+       }
+       const dot = "ยท"
+       if i >= len(dot) && name[i-len(dot):i] == dot {
+               i -= len(dot)
+               return name[:i], name[i:]
+       }
+       return name, ""
+}
index 53bb9bacb07ca249bc58933f982a6f41e5f391d4..ad8e9a43d91bb5f0abfaa14c6285ea3edef49bdc 100644 (file)
@@ -469,6 +469,11 @@ func (pr *pkgReader) objIdx(idx pkgbits.Index) (*types.Package, string) {
                return objPkg, objName
        }
 
+       // Ignore local types promoted to global scope (#55110).
+       if _, suffix := splitVargenSuffix(objName); suffix != "" {
+               return objPkg, objName
+       }
+
        if objPkg.Scope().Lookup(objName) == nil {
                dict := pr.objDictIdx(idx)