]> Cypherpunks repositories - gostls13.git/commitdiff
Revert "cmd/compile: restore test/nested.go test cases"
authorMatthew Dempsky <mdempsky@google.com>
Tue, 23 Aug 2022 18:55:12 +0000 (18:55 +0000)
committerGopher Robot <gobot@golang.org>
Tue, 23 Aug 2022 19:37:34 +0000 (19:37 +0000)
This reverts CL 424854.

Reason for revert: broke misc/cgo/stdio.TestTestRun on several builders.

Will re-land after CL 421879 is submitted.

Change-Id: I2548c70d33d7c178cc71c1d491cd81c22660348f
Reviewed-on: https://go-review.googlesource.com/c/go/+/425214
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Auto-Submit: Matthew Dempsky <mdempsky@google.com>

src/cmd/compile/internal/noder/writer.go
test/typeparam/nested.go

index 75ff000249f44d8dbda2e628bc44bc46d3424383..2c050b79bd7a755dfa2926deb3de16b1c7fc2652 100644 (file)
@@ -432,9 +432,8 @@ func (pw *pkgWriter) pkgIdx(pkg *types2.Package) pkgbits.Index {
 // @@@ Types
 
 var (
-       anyTypeName        = types2.Universe.Lookup("any").(*types2.TypeName)
-       comparableTypeName = types2.Universe.Lookup("comparable").(*types2.TypeName)
-       runeTypeName       = types2.Universe.Lookup("rune").(*types2.TypeName)
+       anyTypeName  = types2.Universe.Lookup("any").(*types2.TypeName)
+       runeTypeName = types2.Universe.Lookup("rune").(*types2.TypeName)
 )
 
 // typ writes a use of the given type into the bitstream.
@@ -486,7 +485,7 @@ func (pw *pkgWriter) typIdx(typ types2.Type, dict *writerDict) typeInfo {
                        w.Len(int(kind))
 
                default:
-                       // Handle "byte" and "rune" as references to their TypeNames.
+                       // Handle "byte" and "rune" as references to their TypeName.
                        obj := types2.Universe.Lookup(typ.Name())
                        assert(obj.Type() == typ)
 
@@ -544,7 +543,6 @@ func (pw *pkgWriter) typIdx(typ types2.Type, dict *writerDict) typeInfo {
                w.structType(typ)
 
        case *types2.Interface:
-               // Handle "any" as reference to its TypeName.
                if typ == anyTypeName.Type() {
                        w.Code(pkgbits.TypeNamed)
                        w.obj(anyTypeName, nil)
@@ -592,23 +590,6 @@ func (w *writer) unionType(typ *types2.Union) {
 }
 
 func (w *writer) interfaceType(typ *types2.Interface) {
-       // If typ has no embedded types but it's not a basic interface, then
-       // the natural description we write out below will fail to
-       // reconstruct it.
-       if typ.NumEmbeddeds() == 0 && !typ.IsMethodSet() {
-               // Currently, this can only happen for the underlying Interface of
-               // "comparable", which is needed to handle type declarations like
-               // "type C comparable".
-               assert(typ == comparableTypeName.Type().(*types2.Named).Underlying())
-
-               // Export as "interface{ comparable }".
-               w.Len(0)                         // NumExplicitMethods
-               w.Len(1)                         // NumEmbeddeds
-               w.Bool(false)                    // IsImplicit
-               w.typ(comparableTypeName.Type()) // EmbeddedType(0)
-               return
-       }
-
        w.Len(typ.NumExplicitMethods())
        w.Len(typ.NumEmbeddeds())
 
@@ -794,6 +775,9 @@ func (w *writer) doObj(wext *writer, obj types2.Object) pkgbits.CodeObj {
                return pkgbits.ObjFunc
 
        case *types2.TypeName:
+               decl, ok := w.p.typDecls[obj]
+               assert(ok)
+
                if obj.IsAlias() {
                        w.pos(obj)
                        w.typ(obj.Type())
@@ -806,7 +790,7 @@ func (w *writer) doObj(wext *writer, obj types2.Object) pkgbits.CodeObj {
                w.pos(obj)
                w.typeParamNames(named.TypeParams())
                wext.typeExt(obj)
-               w.typ(named.Underlying())
+               w.typExpr(decl.Type)
 
                w.Len(named.NumMethods())
                for i := 0; i < named.NumMethods(); i++ {
@@ -823,6 +807,16 @@ func (w *writer) doObj(wext *writer, obj types2.Object) pkgbits.CodeObj {
        }
 }
 
+// typExpr writes the type represented by the given expression.
+//
+// TODO(mdempsky): Document how this differs from exprType.
+func (w *writer) typExpr(expr syntax.Expr) {
+       tv, ok := w.p.info.Types[expr]
+       assert(ok)
+       assert(tv.IsType())
+       w.typ(tv.Type)
+}
+
 // objDict writes the dictionary needed for reading the given object.
 func (w *writer) objDict(obj types2.Object, dict *writerDict) {
        // TODO(mdempsky): Split objDict into multiple entries? reader.go
index cdb8bfb57424fbd24172778c7b02159268a742d6..068e32be1d5f03270372e8388e718d77ca018fb8 100644 (file)
@@ -104,11 +104,27 @@ func main() {
        F[V]()
        F[W]()
 
-       type X[A any] U[X[A]]
-
-       F[X[int]]()
-       F[X[Int]]()
-       F[X[GlobalInt]]()
+       // TODO(go.dev/issue/54512): Restore these tests. They currently
+       // cause problems for shaping with unified IR.
+       //
+       // For example, instantiating X[int] requires instantiating shape
+       // type X[shapify(int)] == X[go.shape.int]. In turn, this requires
+       // instantiating U[shapify(X[go.shape.int])]. But we're still in the
+       // process of constructing X[go.shape.int], so we don't yet know its
+       // underlying type.
+       //
+       // Notably, this is a consequence of unified IR writing out type
+       // declarations with a reference to the full RHS expression (i.e.,
+       // U[X[A]]) rather than its underlying type (i.e., int), which is
+       // necessary to support //go:notinheap. Once go.dev/issue/46731 is
+       // implemented and unified IR is updated, I expect this will just
+       // work.
+       //
+       // type X[A any] U[X[A]]
+       //
+       // F[X[int]]()
+       // F[X[Int]]()
+       // F[X[GlobalInt]]()
 
        for j, tj := range tests {
                for i, ti := range tests[:j+1] {