]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/typecheck: record whether an interface is implicit
authorRobert Findley <rfindley@google.com>
Tue, 19 Oct 2021 22:40:27 +0000 (18:40 -0400)
committerRobert Findley <rfindley@google.com>
Mon, 25 Oct 2021 17:18:40 +0000 (17:18 +0000)
In preparation for capturing the implicit interface bit in export data,
thread through the IsImplicit property from types2 into typecheck.

Change-Id: I9b46fe73de102935a127e6ececaacd76738b557e
Reviewed-on: https://go-review.googlesource.com/c/go/+/357109
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
src/cmd/compile/internal/noder/reader.go
src/cmd/compile/internal/noder/stencil.go
src/cmd/compile/internal/noder/types.go
src/cmd/compile/internal/test/abiutils_test.go
src/cmd/compile/internal/typecheck/iimport.go
src/cmd/compile/internal/typecheck/subr.go
src/cmd/compile/internal/typecheck/type.go
src/cmd/compile/internal/types/sizeof_test.go
src/cmd/compile/internal/types/type.go
src/cmd/compile/internal/types/universe.go

index 48f4368113d2c68699ff042b3521ae2f73a4f0cf..0bc9135999e0f050935e0c1558516d5a2ed19190 100644 (file)
@@ -466,7 +466,7 @@ func (r *reader) interfaceType() *types.Type {
        if len(fields) == 0 {
                return types.Types[types.TINTER] // empty interface
        }
-       return types.NewInterface(tpkg, fields)
+       return types.NewInterface(tpkg, fields, false)
 }
 
 func (r *reader) structType() *types.Type {
index 592de7017ff2b2c4643595d9728decfe72a4497e..474a05973aa09941ce48a1a3026e40c9b6e67e3f 100644 (file)
@@ -881,7 +881,7 @@ func (subst *subster) checkDictionary(name *ir.Name, targs []*types.Type) (code
                cond := ir.NewBinaryExpr(pos, ir.ONE, want, got)
                typed(types.Types[types.TBOOL], cond)
                panicArg := ir.NewNilExpr(pos)
-               typed(types.NewInterface(types.LocalPkg, nil), panicArg)
+               typed(types.NewInterface(types.LocalPkg, nil, false), panicArg)
                then := ir.NewUnaryExpr(pos, ir.OPANIC, panicArg)
                then.SetTypecheck(1)
                x := ir.NewIfStmt(pos, cond, []ir.Node{then}, nil)
index 1a7cef4aa3e84ca149fa55d7c4e44f9abf8a1d36..f035e0da9787dc79d0d0a7540d2b2ec64556449b 100644 (file)
@@ -213,7 +213,7 @@ func (g *irgen) typ0(typ types2.Type) *types.Type {
                        methods[i] = types.NewField(g.pos(m), g.selector(m), mtyp)
                }
 
-               return types.NewInterface(g.tpkg(typ), append(embeddeds, methods...))
+               return types.NewInterface(g.tpkg(typ), append(embeddeds, methods...), typ.IsImplicit())
 
        case *types2.TypeParam:
                // Save the name of the type parameter in the sym of the type.
index f26cb89c6dd047dcc26b1a52500cfe86882ef6fd..12b4a0c361360564e9d7bab8a45bbe6045577828 100644 (file)
@@ -313,7 +313,7 @@ func TestABIUtilsInterfaces(t *testing.T) {
        fldt := mkFuncType(types.FakeRecvType(), []*types.Type{},
                []*types.Type{types.Types[types.TSTRING]})
        field := types.NewField(src.NoXPos, typecheck.Lookup("F"), fldt)
-       nei := types.NewInterface(types.LocalPkg, []*types.Field{field})
+       nei := types.NewInterface(types.LocalPkg, []*types.Field{field}, false)
        i16 := types.Types[types.TINT16]
        tb := types.Types[types.TBOOL]
        s1 := mkstruct([]*types.Type{i16, i16, tb})
index cb1e56bf51dbedb7aa3ad7710050dd91ae2216ee..fcfadc146c5513dbbc7e8c3c1d54d93b4e624493 100644 (file)
@@ -815,7 +815,7 @@ func (r *importReader) typ1() *types.Type {
                        return types.Types[types.TINTER]
                }
 
-               t := types.NewInterface(r.currPkg, append(embeddeds, methods...))
+               t := types.NewInterface(r.currPkg, append(embeddeds, methods...), false)
 
                // Ensure we expand the interface in the frontend (#25055).
                types.CheckSize(t)
index b4d53025250383c7cd4669520a3b755d0c098db9..9ebd8f1423aef3a105d9b83e5e108a3fd37d613f 100644 (file)
@@ -1369,7 +1369,7 @@ func (ts *Tsubster) tinter(t *types.Type, force bool) *types.Type {
                        // For an empty interface, we need to return a new type,
                        // since it may now be fully instantiated (HasTParam
                        // becomes false).
-                       return types.NewInterface(t.Pkg(), nil)
+                       return types.NewInterface(t.Pkg(), nil, false)
                }
                return t
        }
@@ -1390,7 +1390,7 @@ func (ts *Tsubster) tinter(t *types.Type, force bool) *types.Type {
                }
        }
        if newfields != nil {
-               return types.NewInterface(t.Pkg(), newfields)
+               return types.NewInterface(t.Pkg(), newfields, false)
        }
        return t
 }
index af694c2d94a30fb4a5bf1a74e3afd1a48fddfaa8..c4c1ef58cadb103a91c1a0e79d3c1aa6acd4cbda 100644 (file)
@@ -108,7 +108,7 @@ func tcInterfaceType(n *ir.InterfaceType) ir.Node {
        methods := tcFields(n.Methods, nil)
        base.Pos = lno
 
-       n.SetOTYPE(types.NewInterface(types.LocalPkg, methods))
+       n.SetOTYPE(types.NewInterface(types.LocalPkg, methods, false))
        return n
 }
 
index 7349e52a73e8499e9cc5e0fa48fe48c6125aa3f5..d37c1730581c38be38a36d8e067d66deac34b94d 100644 (file)
@@ -26,7 +26,7 @@ func TestSizeof(t *testing.T) {
                {Forward{}, 20, 32},
                {Func{}, 28, 48},
                {Struct{}, 16, 32},
-               {Interface{}, 4, 8},
+               {Interface{}, 8, 16},
                {Chan{}, 8, 16},
                {Array{}, 12, 16},
                {FuncArgs{}, 4, 8},
index 392c54ba790f6bae8adc3fa0b73acc12ad231b37..ec17fe8704aac526cea6fd8e060bff4d768371d1 100644 (file)
@@ -417,7 +417,8 @@ func (t *Type) StructType() *Struct {
 
 // Interface contains Type fields specific to interface types.
 type Interface struct {
-       pkg *Pkg
+       pkg      *Pkg
+       implicit bool
 }
 
 // Typeparam contains Type fields specific to typeparam types.
@@ -1820,7 +1821,7 @@ func newBasic(kind Kind, obj Object) *Type {
 
 // NewInterface returns a new interface for the given methods and
 // embedded types. Embedded types are specified as fields with no Sym.
-func NewInterface(pkg *Pkg, methods []*Field) *Type {
+func NewInterface(pkg *Pkg, methods []*Field, implicit bool) *Type {
        t := newType(TINTER)
        t.SetInterface(methods)
        for _, f := range methods {
@@ -1838,6 +1839,7 @@ func NewInterface(pkg *Pkg, methods []*Field) *Type {
                t.SetBroke(true)
        }
        t.extra.(*Interface).pkg = pkg
+       t.extra.(*Interface).implicit = implicit
        return t
 }
 
@@ -1875,6 +1877,13 @@ func (t *Type) Bound() *Type {
        return t.extra.(*Typeparam).bound
 }
 
+// IsImplicit reports whether an interface is implicit (i.e. elided from a type
+// parameter constraint).
+func (t *Type) IsImplicit() bool {
+       t.wantEtype(TINTER)
+       return t.extra.(*Interface).implicit
+}
+
 // NewUnion returns a new union with the specified set of terms (types). If
 // tildes[i] is true, then terms[i] represents ~T, rather than just T.
 func NewUnion(terms []*Type, tildes []bool) *Type {
index 8fa4b7cd20eebc3e36b55b50f1ae475f9e149783..d5239eb10cb893e32e966293572c46fc8165325f 100644 (file)
@@ -58,7 +58,7 @@ func InitTypes(defTypeName func(sym *Sym, typ *Type) Object) {
        }
 
        Types[TANY] = newType(TANY)
-       Types[TINTER] = NewInterface(LocalPkg, nil)
+       Types[TINTER] = NewInterface(LocalPkg, nil, false)
 
        defBasic := func(kind Kind, pkg *Pkg, name string) *Type {
                typ := newType(kind)
@@ -111,7 +111,7 @@ func InitTypes(defTypeName func(sym *Sym, typ *Type) Object) {
        if base.Flag.G > 0 {
                DeferCheckSize()
                AnyType = defBasic(TFORW, BuiltinPkg, "any")
-               AnyType.SetUnderlying(NewInterface(NoPkg, []*Field{}))
+               AnyType.SetUnderlying(NewInterface(NoPkg, []*Field{}, false))
                ResumeCheckSize()
        }
 
@@ -145,11 +145,11 @@ func makeErrorInterface() *Type {
                NewField(src.NoXPos, nil, Types[TSTRING]),
        })
        method := NewField(src.NoXPos, LocalPkg.Lookup("Error"), sig)
-       return NewInterface(NoPkg, []*Field{method})
+       return NewInterface(NoPkg, []*Field{method}, false)
 }
 
 func makeComparableInterface() *Type {
        sig := NewSignature(NoPkg, FakeRecv(), nil, nil, nil)
        method := NewField(src.NoXPos, LocalPkg.Lookup("=="), sig)
-       return NewInterface(NoPkg, []*Field{method})
+       return NewInterface(NoPkg, []*Field{method}, false)
 }