cmd/compile/internal/types: remove unneeded functionality
This CL removes a handful of features that were only needed for the
pre-unified frontends.
In particular, Type.Pkg was a hack for iexport so that
go/types.Var.Pkg could be precisely populated for struct fields and
signature parameters by gcimporter, but it's no longer necessary with
the unified export data format because we now write export data
directly from types2-supplied type descriptors.
Several other features (e.g., OrigType, implicit interfaces, type
parameters on signatures) are no longer relevant to the unified
frontend, because it only uses types1 to represent instantiated
generic types.
Updates #57410.
Change-Id: I84fd1da5e0b65d2ab91d244a7bb593821ee916e7
Reviewed-on: https://go-review.googlesource.com/c/go/+/458622
Reviewed-by: Keith Randall <khr@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
diff --git a/src/cmd/compile/internal/abi/abiutils.go b/src/cmd/compile/internal/abi/abiutils.go
index a88f8c4..9fc0bc4 100644
--- a/src/cmd/compile/internal/abi/abiutils.go
+++ b/src/cmd/compile/internal/abi/abiutils.go
@@ -717,19 +717,19 @@
nxp := src.NoXPos
bp := types.NewPtr(types.Types[types.TUINT8])
it := types.Types[types.TINT]
- synthSlice = types.NewStruct(types.NoPkg, []*types.Field{
+ synthSlice = types.NewStruct([]*types.Field{
types.NewField(nxp, fname("ptr"), bp),
types.NewField(nxp, fname("len"), it),
types.NewField(nxp, fname("cap"), it),
})
types.CalcStructSize(synthSlice)
- synthString = types.NewStruct(types.NoPkg, []*types.Field{
+ synthString = types.NewStruct([]*types.Field{
types.NewField(nxp, fname("data"), bp),
types.NewField(nxp, fname("len"), it),
})
types.CalcStructSize(synthString)
unsp := types.Types[types.TUNSAFEPTR]
- synthIface = types.NewStruct(types.NoPkg, []*types.Field{
+ synthIface = types.NewStruct([]*types.Field{
types.NewField(nxp, fname("f1"), unsp),
types.NewField(nxp, fname("f2"), unsp),
})
diff --git a/src/cmd/compile/internal/compare/compare_test.go b/src/cmd/compile/internal/compare/compare_test.go
index db34657..c65537f 100644
--- a/src/cmd/compile/internal/compare/compare_test.go
+++ b/src/cmd/compile/internal/compare/compare_test.go
@@ -53,11 +53,11 @@
}{
{"struct without fields", 0, 0,
func() *types.Type {
- return types.NewStruct(types.NewPkg("main", ""), []*types.Field{})
+ return types.NewStruct([]*types.Field{})
}},
{"struct with 1 byte field", 1, 1,
func() *types.Type {
- parent := types.NewStruct(types.NewPkg("main", ""), []*types.Field{})
+ parent := types.NewStruct([]*types.Field{})
fields := []*types.Field{
newByteField(parent, 0),
}
@@ -67,7 +67,7 @@
},
{"struct with 8 byte fields", 1, 8,
func() *types.Type {
- parent := types.NewStruct(types.NewPkg("main", ""), []*types.Field{})
+ parent := types.NewStruct([]*types.Field{})
fields := make([]*types.Field, 8)
for i := range fields {
fields[i] = newByteField(parent, int64(i))
@@ -78,7 +78,7 @@
},
{"struct with 16 byte fields", 2, 16,
func() *types.Type {
- parent := types.NewStruct(types.NewPkg("main", ""), []*types.Field{})
+ parent := types.NewStruct([]*types.Field{})
fields := make([]*types.Field, 16)
for i := range fields {
fields[i] = newByteField(parent, int64(i))
@@ -89,7 +89,7 @@
},
{"struct with 32 byte fields", 4, 32,
func() *types.Type {
- parent := types.NewStruct(types.NewPkg("main", ""), []*types.Field{})
+ parent := types.NewStruct([]*types.Field{})
fields := make([]*types.Field, 32)
for i := range fields {
fields[i] = newByteField(parent, int64(i))
@@ -100,7 +100,7 @@
},
{"struct with 2 int32 fields", 1, 2,
func() *types.Type {
- parent := types.NewStruct(types.NewPkg("main", ""), []*types.Field{})
+ parent := types.NewStruct([]*types.Field{})
fields := make([]*types.Field, 2)
for i := range fields {
fields[i] = newField(parent, int64(i*4), types.TINT32)
@@ -111,7 +111,7 @@
},
{"struct with 2 int32 fields and 1 int64", 2, 3,
func() *types.Type {
- parent := types.NewStruct(types.NewPkg("main", ""), []*types.Field{})
+ parent := types.NewStruct([]*types.Field{})
fields := make([]*types.Field, 3)
fields[0] = newField(parent, int64(0), types.TINT32)
fields[1] = newField(parent, int64(4), types.TINT32)
@@ -122,7 +122,7 @@
},
{"struct with 1 int field and 1 string", 3, 3,
func() *types.Type {
- parent := types.NewStruct(types.NewPkg("main", ""), []*types.Field{})
+ parent := types.NewStruct([]*types.Field{})
fields := make([]*types.Field, 2)
fields[0] = newField(parent, int64(0), types.TINT64)
fields[1] = newField(parent, int64(8), types.TSTRING)
@@ -132,7 +132,7 @@
},
{"struct with 2 strings", 4, 4,
func() *types.Type {
- parent := types.NewStruct(types.NewPkg("main", ""), []*types.Field{})
+ parent := types.NewStruct([]*types.Field{})
fields := make([]*types.Field, 2)
fields[0] = newField(parent, int64(0), types.TSTRING)
fields[1] = newField(parent, int64(8), types.TSTRING)
@@ -142,7 +142,7 @@
},
{"struct with 1 large byte array field", 26, 101,
func() *types.Type {
- parent := types.NewStruct(types.NewPkg("main", ""), []*types.Field{})
+ parent := types.NewStruct([]*types.Field{})
fields := []*types.Field{
newArrayField(parent, 0, 101, types.TUINT16),
}
@@ -152,7 +152,7 @@
},
{"struct with string array field", 4, 4,
func() *types.Type {
- parent := types.NewStruct(types.NewPkg("main", ""), []*types.Field{})
+ parent := types.NewStruct([]*types.Field{})
fields := []*types.Field{
newArrayField(parent, 0, 2, types.TSTRING),
}
diff --git a/src/cmd/compile/internal/escape/call.go b/src/cmd/compile/internal/escape/call.go
index e223552..94bc887 100644
--- a/src/cmd/compile/internal/escape/call.go
+++ b/src/cmd/compile/internal/escape/call.go
@@ -244,7 +244,7 @@
// Create a new no-argument function that we'll hand off to defer.
fn := ir.NewClosureFunc(n.Pos(), true)
fn.SetWrapper(true)
- fn.Nname.SetType(types.NewSignature(types.LocalPkg, nil, nil, nil, nil))
+ fn.Nname.SetType(types.NewSignature(nil, nil, nil))
fn.Body = []ir.Node{call}
if call, ok := call.(*ir.CallExpr); ok && call.Op() == ir.OCALLFUNC {
// If the callee is a named function, link to the original callee.
diff --git a/src/cmd/compile/internal/noder/reader.go b/src/cmd/compile/internal/noder/reader.go
index ac6d2fa9..8a8ed86 100644
--- a/src/cmd/compile/internal/noder/reader.go
+++ b/src/cmd/compile/internal/noder/reader.go
@@ -506,7 +506,7 @@
case pkgbits.TypePointer:
return types.NewPtr(r.typ())
case pkgbits.TypeSignature:
- return r.signature(types.LocalPkg, nil)
+ return r.signature(nil)
case pkgbits.TypeSlice:
return types.NewSlice(r.typ())
case pkgbits.TypeStruct:
@@ -549,8 +549,6 @@
}
func (r *reader) interfaceType() *types.Type {
- tpkg := types.LocalPkg // TODO(mdempsky): Remove after iexport is gone.
-
nmethods, nembeddeds := r.Len(), r.Len()
implicit := nmethods == 0 && nembeddeds == 1 && r.Bool()
assert(!implicit) // implicit interfaces only appear in constraints
@@ -560,9 +558,8 @@
for i := range methods {
pos := r.pos()
- pkg, sym := r.selector()
- tpkg = pkg
- mtyp := r.signature(pkg, types.FakeRecv())
+ _, sym := r.selector()
+ mtyp := r.signature(types.FakeRecv())
methods[i] = types.NewField(pos, sym, mtyp)
}
for i := range embeddeds {
@@ -572,16 +569,14 @@
if len(fields) == 0 {
return types.Types[types.TINTER] // empty interface
}
- return types.NewInterface(tpkg, fields, false)
+ return types.NewInterface(fields)
}
func (r *reader) structType() *types.Type {
- tpkg := types.LocalPkg // TODO(mdempsky): Remove after iexport is gone.
fields := make([]*types.Field, r.Len())
for i := range fields {
pos := r.pos()
- pkg, sym := r.selector()
- tpkg = pkg
+ _, sym := r.selector()
ftyp := r.typ()
tag := r.String()
embedded := r.Bool()
@@ -593,26 +588,26 @@
}
fields[i] = f
}
- return types.NewStruct(tpkg, fields)
+ return types.NewStruct(fields)
}
-func (r *reader) signature(tpkg *types.Pkg, recv *types.Field) *types.Type {
+func (r *reader) signature(recv *types.Field) *types.Type {
r.Sync(pkgbits.SyncSignature)
- params := r.params(&tpkg)
- results := r.params(&tpkg)
+ params := r.params()
+ results := r.params()
if r.Bool() { // variadic
params[len(params)-1].SetIsDDD(true)
}
- return types.NewSignature(tpkg, recv, nil, params, results)
+ return types.NewSignature(recv, params, results)
}
-func (r *reader) params(tpkg **types.Pkg) []*types.Field {
+func (r *reader) params() []*types.Field {
r.Sync(pkgbits.SyncParams)
fields := make([]*types.Field, r.Len())
for i := range fields {
- *tpkg, fields[i] = r.param()
+ _, fields[i] = r.param()
}
return fields
}
@@ -742,7 +737,7 @@
sym = Renameinit()
}
name := do(ir.ONAME, true)
- setType(name, r.signature(sym.Pkg, nil))
+ setType(name, r.signature(nil))
name.Func = ir.NewFunc(r.pos())
name.Func.Nname = name
@@ -981,10 +976,10 @@
func (r *reader) method(rext *reader) *types.Field {
r.Sync(pkgbits.SyncMethod)
pos := r.pos()
- pkg, sym := r.selector()
+ _, sym := r.selector()
r.typeParamNames()
_, recv := r.param()
- typ := r.signature(pkg, recv)
+ typ := r.signature(recv)
name := ir.NewNameAt(pos, ir.MethodSym(recv.Type, sym))
setType(name, typ)
@@ -2581,7 +2576,7 @@
params, results := syntheticSig(fun.Type())
params = params[len(captured)-1:] // skip curried parameters
- typ := types.NewSignature(types.NoPkg, nil, nil, params, results)
+ typ := types.NewSignature(nil, params, results)
addBody := func(pos src.XPos, r *reader, captured []ir.Node) {
recvs, params := r.syntheticArgs(pos)
@@ -2619,7 +2614,7 @@
params = append(params[:1], params[2:]...)
}
- typ := types.NewSignature(types.NoPkg, nil, nil, params, results)
+ typ := types.NewSignature(nil, params, results)
addBody := func(pos src.XPos, r *reader, captured []ir.Node) {
recvs, args := r.syntheticArgs(pos)
@@ -3073,7 +3068,7 @@
// allocation of the closure is credited (#49171).
r.suppressInlPos++
pos := r.pos()
- xtype2 := r.signature(types.LocalPkg, nil)
+ xtype2 := r.signature(nil)
r.suppressInlPos--
fn := ir.NewClosureFunc(pos, r.curfn != nil)
@@ -3926,7 +3921,7 @@
params := clone(sig.Params().FieldSlice())
results := clone(sig.Results().FieldSlice())
- return types.NewSignature(types.NoPkg, recv, nil, params, results)
+ return types.NewSignature(recv, params, results)
}
func addTailCall(pos src.XPos, fn *ir.Func, recv ir.Node, method *types.Field) {
@@ -3994,5 +3989,5 @@
results[i] = types.NewField(result.Pos, result.Sym, result.Type)
}
- return types.NewSignature(types.LocalPkg, recv, nil, params, results)
+ return types.NewSignature(recv, params, results)
}
diff --git a/src/cmd/compile/internal/pkginit/init.go b/src/cmd/compile/internal/pkginit/init.go
index 57593fd..9d4c435 100644
--- a/src/cmd/compile/internal/pkginit/init.go
+++ b/src/cmd/compile/internal/pkginit/init.go
@@ -116,7 +116,7 @@
// runtime.asanregisterglobals(unsafe.Pointer(&globals[0]), ni)
asanf := typecheck.NewName(ir.Pkgs.Runtime.Lookup("asanregisterglobals"))
ir.MarkFunc(asanf)
- asanf.SetType(types.NewSignature(types.NoPkg, nil, nil, []*types.Field{
+ asanf.SetType(types.NewSignature(nil, []*types.Field{
types.NewField(base.Pos, nil, types.Types[types.TUNSAFEPTR]),
types.NewField(base.Pos, nil, types.Types[types.TUINTPTR]),
}, nil))
diff --git a/src/cmd/compile/internal/pkginit/initAsanGlobals.go b/src/cmd/compile/internal/pkginit/initAsanGlobals.go
index 63aa361..464787a 100644
--- a/src/cmd/compile/internal/pkginit/initAsanGlobals.go
+++ b/src/cmd/compile/internal/pkginit/initAsanGlobals.go
@@ -161,7 +161,7 @@
fname := typecheck.Lookup
nxp := src.NoXPos
nfield := types.NewField
- asanGlobal := types.NewStruct(types.NoPkg, []*types.Field{
+ asanGlobal := types.NewStruct([]*types.Field{
nfield(nxp, fname("beg"), up),
nfield(nxp, fname("size"), up),
nfield(nxp, fname("sizeWithRedzone"), up),
@@ -173,14 +173,14 @@
})
types.CalcSize(asanGlobal)
- asanLocation := types.NewStruct(types.NoPkg, []*types.Field{
+ asanLocation := types.NewStruct([]*types.Field{
nfield(nxp, fname("filename"), up),
nfield(nxp, fname("line"), i32),
nfield(nxp, fname("column"), i32),
})
types.CalcSize(asanLocation)
- defString := types.NewStruct(types.NoPkg, []*types.Field{
+ defString := types.NewStruct([]*types.Field{
types.NewField(nxp, fname("data"), up),
types.NewField(nxp, fname("len"), up),
})
diff --git a/src/cmd/compile/internal/reflectdata/alg.go b/src/cmd/compile/internal/reflectdata/alg.go
index 8f0c4e8..2f2f986 100644
--- a/src/cmd/compile/internal/reflectdata/alg.go
+++ b/src/cmd/compile/internal/reflectdata/alg.go
@@ -268,7 +268,7 @@
// TODO(austin): This creates an ir.Name with a nil Func.
n := typecheck.NewName(sym)
ir.MarkFunc(n)
- n.SetType(types.NewSignature(types.NoPkg, nil, nil, []*types.Field{
+ n.SetType(types.NewSignature(nil, []*types.Field{
types.NewField(base.Pos, nil, types.NewPtr(t)),
types.NewField(base.Pos, nil, types.Types[types.TUINTPTR]),
}, []*types.Field{
@@ -583,7 +583,7 @@
// TODO(austin): This creates an ir.Name with a nil Func.
n := typecheck.NewName(sym)
ir.MarkFunc(n)
- n.SetType(types.NewSignature(types.NoPkg, nil, nil, []*types.Field{
+ n.SetType(types.NewSignature(nil, []*types.Field{
types.NewField(base.Pos, nil, types.NewPtr(t)),
types.NewField(base.Pos, nil, types.Types[types.TUINTPTR]),
types.NewField(base.Pos, nil, types.Types[types.TUINTPTR]),
diff --git a/src/cmd/compile/internal/reflectdata/reflect.go b/src/cmd/compile/internal/reflectdata/reflect.go
index 9d71bf6..afc3ee4 100644
--- a/src/cmd/compile/internal/reflectdata/reflect.go
+++ b/src/cmd/compile/internal/reflectdata/reflect.go
@@ -140,7 +140,7 @@
field = append(field, overflow)
// link up fields
- bucket := types.NewStruct(types.NoPkg, field[:])
+ bucket := types.NewStruct(field[:])
bucket.SetNoalg(true)
types.CalcSize(bucket)
@@ -234,7 +234,7 @@
makefield("extra", types.Types[types.TUNSAFEPTR]),
}
- hmap := types.NewStruct(types.NoPkg, fields)
+ hmap := types.NewStruct(fields)
hmap.SetNoalg(true)
types.CalcSize(hmap)
@@ -297,7 +297,7 @@
}
// build iterator struct holding the above fields
- hiter := types.NewStruct(types.NoPkg, fields)
+ hiter := types.NewStruct(fields)
hiter.SetNoalg(true)
types.CalcSize(hiter)
if hiter.Size() != int64(12*types.PtrSize) {
@@ -1402,7 +1402,7 @@
if typ.Sym() == nil && typ.Kind() == types.TFUNC {
f := typ.FuncType()
// func(error) string
- if f.Receiver.NumFields() == 0 && f.TParams.NumFields() == 0 &&
+ if f.Receiver.NumFields() == 0 &&
f.Params.NumFields() == 1 && f.Results.NumFields() == 1 &&
f.Params.FieldType(0) == types.ErrorType &&
f.Results.FieldType(0) == types.Types[types.TSTRING] {
@@ -1451,7 +1451,7 @@
// emit type for func(error) string,
// which is the type of an auto-generated wrapper.
- writeType(types.NewPtr(types.NewSignature(types.NoPkg, nil, nil, []*types.Field{
+ writeType(types.NewPtr(types.NewSignature(nil, []*types.Field{
types.NewField(base.Pos, nil, types.ErrorType),
}, []*types.Field{
types.NewField(base.Pos, nil, types.Types[types.TSTRING]),
diff --git a/src/cmd/compile/internal/ssagen/ssa.go b/src/cmd/compile/internal/ssagen/ssa.go
index 4b6b28f..654db8f 100644
--- a/src/cmd/compile/internal/ssagen/ssa.go
+++ b/src/cmd/compile/internal/ssagen/ssa.go
@@ -7947,7 +7947,7 @@
}
// build struct holding the above fields
- s := types.NewStruct(types.NoPkg, fields)
+ s := types.NewStruct(fields)
s.SetNoalg(true)
types.CalcStructSize(s)
return s
diff --git a/src/cmd/compile/internal/test/abiutils_test.go b/src/cmd/compile/internal/test/abiutils_test.go
index 3f8ee3d..8ed7622 100644
--- a/src/cmd/compile/internal/test/abiutils_test.go
+++ b/src/cmd/compile/internal/test/abiutils_test.go
@@ -313,7 +313,7 @@
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}, false)
+ nei := types.NewInterface([]*types.Field{field})
i16 := types.Types[types.TINT16]
tb := types.Types[types.TBOOL]
s1 := mkstruct([]*types.Type{i16, i16, tb})
diff --git a/src/cmd/compile/internal/test/abiutilsaux_test.go b/src/cmd/compile/internal/test/abiutilsaux_test.go
index b9456331..07b8eb7 100644
--- a/src/cmd/compile/internal/test/abiutilsaux_test.go
+++ b/src/cmd/compile/internal/test/abiutilsaux_test.go
@@ -39,7 +39,7 @@
f := types.NewField(src.NoXPos, nil, t)
fields[k] = f
}
- s := types.NewStruct(types.LocalPkg, fields)
+ s := types.NewStruct(fields)
return s
}
@@ -57,7 +57,7 @@
if rcvr != nil {
rf = mkParamResultField(rcvr, q, ir.PPARAM)
}
- return types.NewSignature(types.LocalPkg, rf, nil, inf, outf)
+ return types.NewSignature(rf, inf, outf)
}
type expectedDump struct {
diff --git a/src/cmd/compile/internal/typecheck/builtin.go b/src/cmd/compile/internal/typecheck/builtin.go
index 7de24ad..6aa5e39 100644
--- a/src/cmd/compile/internal/typecheck/builtin.go
+++ b/src/cmd/compile/internal/typecheck/builtin.go
@@ -11,7 +11,7 @@
//
//go:noinline
func newSig(params, results []*types.Field) *types.Type {
- return types.NewSignature(types.NoPkg, nil, nil, params, results)
+ return types.NewSignature(nil, params, results)
}
func params(tlist ...*types.Type) []*types.Field {
@@ -340,7 +340,7 @@
typs[102] = types.NewChan(typs[2], types.Csend)
typs[103] = newSig(params(typs[102], typs[3]), nil)
typs[104] = types.NewArray(typs[0], 3)
- typs[105] = types.NewStruct(types.NoPkg, []*types.Field{types.NewField(src.NoXPos, Lookup("enabled"), typs[6]), types.NewField(src.NoXPos, Lookup("pad"), typs[104]), types.NewField(src.NoXPos, Lookup("needed"), typs[6]), types.NewField(src.NoXPos, Lookup("cgo"), typs[6]), types.NewField(src.NoXPos, Lookup("alignme"), typs[24])})
+ typs[105] = types.NewStruct([]*types.Field{types.NewField(src.NoXPos, Lookup("enabled"), typs[6]), types.NewField(src.NoXPos, Lookup("pad"), typs[104]), types.NewField(src.NoXPos, Lookup("needed"), typs[6]), types.NewField(src.NoXPos, Lookup("cgo"), typs[6]), types.NewField(src.NoXPos, Lookup("alignme"), typs[24])})
typs[106] = newSig(params(typs[1], typs[3], typs[3]), nil)
typs[107] = newSig(params(typs[1], typs[3]), nil)
typs[108] = newSig(params(typs[1], typs[3], typs[15], typs[3], typs[15]), params(typs[15]))
diff --git a/src/cmd/compile/internal/typecheck/dcl.go b/src/cmd/compile/internal/typecheck/dcl.go
index 5d69506..5ea1593 100644
--- a/src/cmd/compile/internal/typecheck/dcl.go
+++ b/src/cmd/compile/internal/typecheck/dcl.go
@@ -29,7 +29,7 @@
recv1 = declareParam(ir.PPARAM, -1, recv)
}
- typ := types.NewSignature(types.LocalPkg, recv1, nil, declareParams(ir.PPARAM, params), declareParams(ir.PPARAMOUT, results))
+ typ := types.NewSignature(recv1, declareParams(ir.PPARAM, params), declareParams(ir.PPARAMOUT, results))
checkdupfields("argument", typ.Recvs().FieldSlice(), typ.Params().FieldSlice(), typ.Results().FieldSlice())
fn.Nname.SetType(typ)
fn.Nname.SetTypecheck(1)
@@ -328,5 +328,5 @@
results[i] = types.NewField(base.Pos, nil, t.Type)
}
- return types.NewSignature(types.LocalPkg, nil, nil, params, results)
+ return types.NewSignature(nil, params, results)
}
diff --git a/src/cmd/compile/internal/typecheck/func.go b/src/cmd/compile/internal/typecheck/func.go
index 5f7537e..bc27f20 100644
--- a/src/cmd/compile/internal/typecheck/func.go
+++ b/src/cmd/compile/internal/typecheck/func.go
@@ -120,7 +120,7 @@
}
fields = append(fields, types.NewField(base.Pos, v.Sym(), typ))
}
- typ := types.NewStruct(types.NoPkg, fields)
+ typ := types.NewStruct(fields)
typ.SetNoalg(true)
return typ
}
@@ -129,7 +129,7 @@
// needed in the closure for a OMETHVALUE node. The address of a variable of
// the returned type can be cast to a func.
func MethodValueType(n *ir.SelectorExpr) *types.Type {
- t := types.NewStruct(types.NoPkg, []*types.Field{
+ t := types.NewStruct([]*types.Field{
types.NewField(base.Pos, Lookup("F"), types.Types[types.TUINTPTR]),
types.NewField(base.Pos, Lookup("R"), n.X.Type()),
})
diff --git a/src/cmd/compile/internal/typecheck/mkbuiltin.go b/src/cmd/compile/internal/typecheck/mkbuiltin.go
index 0ac3e47..28afac5 100644
--- a/src/cmd/compile/internal/typecheck/mkbuiltin.go
+++ b/src/cmd/compile/internal/typecheck/mkbuiltin.go
@@ -44,7 +44,7 @@
// Not inlining this function removes a significant chunk of init code.
//go:noinline
func newSig(params, results []*types.Field) *types.Type {
- return types.NewSignature(types.NoPkg, nil, nil, params, results)
+ return types.NewSignature(nil, params, results)
}
func params(tlist ...*types.Type) []*types.Field {
@@ -201,7 +201,7 @@
case *ast.StarExpr:
return fmt.Sprintf("types.NewPtr(%s)", i.subtype(t.X))
case *ast.StructType:
- return fmt.Sprintf("types.NewStruct(types.NoPkg, %s)", i.fields(t.Fields, true))
+ return fmt.Sprintf("types.NewStruct(%s)", i.fields(t.Fields, true))
default:
log.Fatalf("unhandled type: %#v", t)
diff --git a/src/cmd/compile/internal/types/fmt.go b/src/cmd/compile/internal/types/fmt.go
index 108283c..0016fb9 100644
--- a/src/cmd/compile/internal/types/fmt.go
+++ b/src/cmd/compile/internal/types/fmt.go
@@ -488,9 +488,6 @@
}
b.WriteString("func")
}
- if t.NumTParams() > 0 {
- tconv2(b, t.TParams(), 0, mode, visited)
- }
tconv2(b, t.Params(), 0, mode, visited)
switch t.NumResults() {
diff --git a/src/cmd/compile/internal/types/sizeof_test.go b/src/cmd/compile/internal/types/sizeof_test.go
index e834266..76ccbd5 100644
--- a/src/cmd/compile/internal/types/sizeof_test.go
+++ b/src/cmd/compile/internal/types/sizeof_test.go
@@ -21,12 +21,12 @@
_64bit uintptr // size on 64bit platforms
}{
{Sym{}, 32, 64},
- {Type{}, 60, 104},
+ {Type{}, 56, 96},
{Map{}, 20, 40},
{Forward{}, 20, 32},
- {Func{}, 28, 48},
- {Struct{}, 16, 32},
- {Interface{}, 8, 16},
+ {Func{}, 20, 32},
+ {Struct{}, 12, 24},
+ {Interface{}, 0, 0},
{Chan{}, 8, 16},
{Array{}, 12, 16},
{FuncArgs{}, 4, 8},
diff --git a/src/cmd/compile/internal/types/type.go b/src/cmd/compile/internal/types/type.go
index 5e4c1b9..ed7054e 100644
--- a/src/cmd/compile/internal/types/type.go
+++ b/src/cmd/compile/internal/types/type.go
@@ -189,11 +189,6 @@
// instantiated from a generic type, and is otherwise set to nil.
// TODO(danscales): choose a better name.
rparams *[]*Type
-
- // For an instantiated generic type, the base generic type.
- // This backpointer is useful, because the base type is the type that has
- // the method bodies.
- origType *Type
}
func (*Type) CanBeAnSSAAux() {}
@@ -234,11 +229,6 @@
return nil
}
-// OrigType returns the original generic type that t is an
-// instantiation of, if any.
-func (t *Type) OrigType() *Type { return t.origType }
-func (t *Type) SetOrigType(orig *Type) { t.origType = orig }
-
// Underlying returns the underlying type of type t.
func (t *Type) Underlying() *Type { return t.underlying }
@@ -279,34 +269,6 @@
return len(t.RParams()) > 0
}
-// NoPkg is a nil *Pkg value for clarity.
-// It's intended for use when constructing types that aren't exported
-// and thus don't need to be associated with any package.
-var NoPkg *Pkg = nil
-
-// Pkg returns the package that t appeared in.
-//
-// Pkg is only defined for function, struct, and interface types
-// (i.e., types with named elements). This information isn't used by
-// cmd/compile itself, but we need to track it because it's exposed by
-// the go/types API.
-//
-// Deprecated: Pkg exists only for iexport, which will go away after
-// Go 1.20. It should not be used by other code.
-func (t *Type) Pkg() *Pkg {
- switch t.kind {
- case TFUNC:
- return t.extra.(*Func).pkg
- case TSTRUCT:
- return t.extra.(*Struct).pkg
- case TINTER:
- return t.extra.(*Interface).pkg
- default:
- base.Fatalf("Pkg: unexpected kind: %v", t)
- return nil
- }
-}
-
// Map contains Type fields specific to maps.
type Map struct {
Key *Type // Key type
@@ -340,9 +302,6 @@
Receiver *Type // function receiver
Results *Type // function results
Params *Type // function params
- TParams *Type // type params of receiver (if method) or function
-
- pkg *Pkg
// Argwid is the total width of the function receiver, params, and results.
// It gets calculated via a temporary TFUNCARGS type.
@@ -359,7 +318,6 @@
// StructType contains Type fields specific to struct types.
type Struct struct {
fields Fields
- pkg *Pkg
// Maps have three associated internal structs (see struct MapType).
// Map links such structs back to their map type.
@@ -387,8 +345,6 @@
// Interface contains Type fields specific to interface types.
type Interface struct {
- pkg *Pkg
- implicit bool
}
// Ptr contains Type fields specific to pointer types.
@@ -859,12 +815,10 @@
}
func (t *Type) Recvs() *Type { return t.FuncType().Receiver }
-func (t *Type) TParams() *Type { return t.FuncType().TParams }
func (t *Type) Params() *Type { return t.FuncType().Params }
func (t *Type) Results() *Type { return t.FuncType().Results }
func (t *Type) NumRecvs() int { return t.FuncType().Receiver.NumFields() }
-func (t *Type) NumTParams() int { return t.FuncType().TParams.NumFields() }
func (t *Type) NumParams() int { return t.FuncType().Params.NumFields() }
func (t *Type) NumResults() int { return t.FuncType().Results.NumFields() }
@@ -1732,7 +1686,7 @@
// 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, implicit bool) *Type {
+func NewInterface(methods []*Field) *Type {
t := newType(TINTER)
t.SetInterface(methods)
for _, f := range methods {
@@ -1742,24 +1696,9 @@
break
}
}
- t.extra.(*Interface).pkg = pkg
- t.extra.(*Interface).implicit = implicit
return t
}
-// 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
-}
-
-// MarkImplicit marks the interface as implicit.
-func (t *Type) MarkImplicit() {
- t.wantEtype(TINTER)
- t.extra.(*Interface).implicit = true
-}
-
const BOGUS_FUNARG_OFFSET = -1000000000
func unzeroFieldOffsets(f []*Field) {
@@ -1769,8 +1708,8 @@
}
// NewSignature returns a new function type for the given receiver,
-// parameters, results, and type parameters, any of which may be nil.
-func NewSignature(pkg *Pkg, recv *Field, tparams, params, results []*Field) *Type {
+// parameters, and results, any of which may be nil.
+func NewSignature(recv *Field, params, results []*Field) *Type {
var recvs []*Field
if recv != nil {
recvs = []*Field{recv}
@@ -1780,7 +1719,7 @@
ft := t.FuncType()
funargs := func(fields []*Field, funarg Funarg) *Type {
- s := NewStruct(NoPkg, fields)
+ s := NewStruct(fields)
s.StructType().Funarg = funarg
return s
}
@@ -1791,11 +1730,8 @@
unzeroFieldOffsets(params)
unzeroFieldOffsets(results)
ft.Receiver = funargs(recvs, FunargRcvr)
- // TODO(danscales): just use nil here (save memory) if no tparams
- ft.TParams = funargs(tparams, FunargTparams)
ft.Params = funargs(params, FunargParams)
ft.Results = funargs(results, FunargResults)
- ft.pkg = pkg
if fieldsHasShape(recvs) || fieldsHasShape(params) || fieldsHasShape(results) {
t.SetHasShape(true)
}
@@ -1804,10 +1740,9 @@
}
// NewStruct returns a new struct with the given fields.
-func NewStruct(pkg *Pkg, fields []*Field) *Type {
+func NewStruct(fields []*Field) *Type {
t := newType(TSTRUCT)
t.SetFields(fields)
- t.extra.(*Struct).pkg = pkg
if fieldsHasShape(fields) {
t.SetHasShape(true)
}
diff --git a/src/cmd/compile/internal/types/universe.go b/src/cmd/compile/internal/types/universe.go
index 4733110..d1800f2 100644
--- a/src/cmd/compile/internal/types/universe.go
+++ b/src/cmd/compile/internal/types/universe.go
@@ -58,7 +58,7 @@
}
Types[TANY] = newType(TANY) // note: an old placeholder type, NOT the new builtin 'any' alias for interface{}
- Types[TINTER] = NewInterface(LocalPkg, nil, false)
+ Types[TINTER] = NewInterface(nil)
CheckSize(Types[TINTER])
defBasic := func(kind Kind, pkg *Pkg, name string) *Type {
@@ -111,7 +111,7 @@
// any type (interface)
DeferCheckSize()
AnyType = defBasic(TFORW, BuiltinPkg, "any")
- AnyType.SetUnderlying(NewInterface(BuiltinPkg, []*Field{}, false))
+ AnyType.SetUnderlying(NewInterface(nil))
ResumeCheckSize()
Types[TUNSAFEPTR] = defBasic(TUNSAFEPTR, UnsafePkg, "Pointer")
@@ -140,15 +140,15 @@
}
func makeErrorInterface() *Type {
- sig := NewSignature(NoPkg, FakeRecv(), nil, nil, []*Field{
+ sig := NewSignature(FakeRecv(), nil, []*Field{
NewField(src.NoXPos, nil, Types[TSTRING]),
})
method := NewField(src.NoXPos, LocalPkg.Lookup("Error"), sig)
- return NewInterface(NoPkg, []*Field{method}, false)
+ return NewInterface([]*Field{method})
}
// makeComparableInterface makes the predefined "comparable" interface in the
// built-in package. It has a unique name, but no methods.
func makeComparableInterface() *Type {
- return NewInterface(NoPkg, nil, false)
+ return NewInterface(nil)
}
diff --git a/src/cmd/compile/internal/walk/closure.go b/src/cmd/compile/internal/walk/closure.go
index 42750c2..1fa3ac0 100644
--- a/src/cmd/compile/internal/walk/closure.go
+++ b/src/cmd/compile/internal/walk/closure.go
@@ -68,7 +68,7 @@
// Create new function type with parameters prepended, and
// then update type and declarations.
- typ = types.NewSignature(typ.Pkg(), nil, nil, append(params, typ.Params().FieldSlice()...), typ.Results().FieldSlice())
+ typ = types.NewSignature(nil, append(params, typ.Params().FieldSlice()...), typ.Results().FieldSlice())
f.SetType(typ)
clofn.Dcl = append(decls, clofn.Dcl...)
diff --git a/src/cmd/compile/internal/walk/compare.go b/src/cmd/compile/internal/walk/compare.go
index fe9c5d8..0382894 100644
--- a/src/cmd/compile/internal/walk/compare.go
+++ b/src/cmd/compile/internal/walk/compare.go
@@ -473,7 +473,7 @@
// TODO(austin): This creates an ir.Name with a nil Func.
n := typecheck.NewName(sym)
ir.MarkFunc(n)
- n.SetType(types.NewSignature(types.NoPkg, nil, nil, []*types.Field{
+ n.SetType(types.NewSignature(nil, []*types.Field{
types.NewField(base.Pos, nil, types.NewPtr(t)),
types.NewField(base.Pos, nil, types.NewPtr(t)),
}, []*types.Field{
diff --git a/src/cmd/compile/internal/walk/select.go b/src/cmd/compile/internal/walk/select.go
index 570e9b5..13beb70 100644
--- a/src/cmd/compile/internal/walk/select.go
+++ b/src/cmd/compile/internal/walk/select.go
@@ -287,7 +287,7 @@
// Keep in sync with src/runtime/select.go.
func scasetype() *types.Type {
if scase == nil {
- scase = types.NewStruct(types.NoPkg, []*types.Field{
+ scase = types.NewStruct([]*types.Field{
types.NewField(base.Pos, typecheck.Lookup("c"), types.Types[types.TUNSAFEPTR]),
types.NewField(base.Pos, typecheck.Lookup("elem"), types.Types[types.TUNSAFEPTR]),
})