]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: support structural typing in unified IR
authorMatthew Dempsky <mdempsky@google.com>
Wed, 26 Jan 2022 21:26:45 +0000 (13:26 -0800)
committerMatthew Dempsky <mdempsky@google.com>
Thu, 27 Jan 2022 00:03:31 +0000 (00:03 +0000)
This CL updates unified IR to look at the structural type of a
composite literal type, rather than merely the underlying type, to
determine if it's a structure. This fixes a number of currently
failing regress test cases.

Updates #50833.

Change-Id: I11c040c77ec86c23e8ffefcf1ce1aed548687dc5
Reviewed-on: https://go-review.googlesource.com/c/go/+/381074
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
src/cmd/compile/internal/noder/writer.go
test/run.go

index 2bb0b4d5d750bb01388fe31eb32f9a9d4081e522..73f2df8e39a508cde2938e4cdf303a4fd78ec131 100644 (file)
@@ -1218,6 +1218,7 @@ func (w *writer) expr(expr syntax.Expr) {
                }
 
                obj := obj.(*types2.Var)
+               assert(!obj.IsField())
                assert(targs.Len() == 0)
 
                w.code(exprLocal)
@@ -1337,10 +1338,11 @@ func (w *writer) compLit(lit *syntax.CompositeLit) {
        w.typ(tv.Type)
 
        typ := tv.Type
+       // TODO(mdempsky): Use types2.StructuralType here too? See #50833.
        if ptr, ok := typ.Underlying().(*types2.Pointer); ok {
                typ = ptr.Elem()
        }
-       str, isStruct := typ.Underlying().(*types2.Struct)
+       str, isStruct := types2.StructuralType(typ).(*types2.Struct)
 
        w.len(len(lit.ElemList))
        for i, elem := range lit.ElemList {
index 0e35ed2c0fcd964058132e688db41214e83ba6ff..9ba421510ced9285e2029da8a00642c45dd13955 100644 (file)
@@ -2167,7 +2167,6 @@ var unifiedFailures = setOf(
 
        "fixedbugs/issue42284.go",  // prints "T(0) does not escape", but test expects "a.I(a.T(0)) does not escape"
        "fixedbugs/issue7921.go",   // prints "… escapes to heap", but test expects "string(…) escapes to heap"
-       "typeparam/issue48538.go",  // assertion failure, interprets struct key as closure variable
        "typeparam/issue47631.go",  // unified IR can handle local type declarations
        "fixedbugs/issue42058a.go", // unified IR doesn't report channel element too large
        "fixedbugs/issue42058b.go", // unified IR doesn't report channel element too large
@@ -2178,10 +2177,7 @@ var unifiedFailures = setOf(
        "typeparam/typeswitch2.go", // duplicate case failure due to stenciling
        "typeparam/typeswitch3.go", // duplicate case failure due to stenciling
        "typeparam/typeswitch4.go", // duplicate case failure due to stenciling
-       "typeparam/issue50417b.go", // Need to handle field access on a type param
        "typeparam/issue50552.go",  // gives missing method for instantiated type
-       "typeparam/absdiff2.go",    // wrong assertion about closure variables
-       "typeparam/absdiffimp2.go", // wrong assertion about closure variables
 )
 
 func setOf(keys ...string) map[string]bool {