fn.SetDupok(true)
fn.SetNeedctxt(true)
- tfn.Type().SetPkg(t0.Pkg())
-
// Declare and initialize variable holding receiver.
cr := ir.NewClosureRead(rcvrtype, Rnd(int64(Widthptr), int64(rcvrtype.Align)))
ptr := NewName(lookup(".this"))
checkdupfields("field", fields)
base.Pos = lno
- return types.NewStruct(fields)
+ return types.NewStruct(ir.LocalPkg, fields)
}
func tointerface(nmethods []*ir.Field) *types.Type {
}
base.Pos = lno
- return types.NewInterface(methods)
+ return types.NewInterface(ir.LocalPkg, methods)
}
func fakeRecv() *ir.Field {
recv = funarg(nrecv)
}
- t := types.NewSignature(recv, funargs(nparams), funargs(nresults))
+ t := types.NewSignature(ir.LocalPkg, recv, funargs(nparams), funargs(nresults))
checkdupfields("argument", t.Recvs().FieldSlice(), t.Params().FieldSlice(), t.Results().FieldSlice())
return t
}
}
func (w *exportWriter) setPkg(pkg *types.Pkg, write bool) {
- if pkg == nil {
- // TODO(mdempsky): Proactively set Pkg for types and
- // remove this fallback logic.
- pkg = ir.LocalPkg
+ if pkg == types.NoPkg {
+ base.Fatalf("missing pkg")
}
if write {
fs[i] = f
}
- t := types.NewStruct(fs)
- t.SetPkg(r.currPkg)
- return t
+ return types.NewStruct(r.currPkg, fs)
case interfaceType:
r.setPkg()
methods[i] = types.NewField(pos, sym, typ)
}
- t := types.NewInterface(append(embeddeds, methods...))
- t.SetPkg(r.currPkg)
+ t := types.NewInterface(r.currPkg, append(embeddeds, methods...))
// Ensure we expand the interface in the frontend (#25055).
checkwidth(t)
if n := len(params); n > 0 {
params[n-1].SetIsDDD(r.bool())
}
- t := types.NewSignature(recv, params, results)
- t.SetPkg(r.currPkg)
- return t
+ return types.NewSignature(r.currPkg, recv, params, results)
}
func (r *importReader) paramList() []*types.Field {
)
func typeWithoutPointers() *types.Type {
- return types.NewStruct([]*types.Field{
+ return types.NewStruct(types.NoPkg, []*types.Field{
types.NewField(src.NoXPos, nil, types.New(types.TINT)),
})
}
func typeWithPointers() *types.Type {
- return types.NewStruct([]*types.Field{
+ return types.NewStruct(types.NoPkg, []*types.Field{
types.NewField(src.NoXPos, nil, types.NewPtr(types.New(types.TINT))),
})
}
field = append(field, overflow)
// link up fields
- bucket := types.NewStruct(field[:])
+ bucket := types.NewStruct(types.NoPkg, field[:])
bucket.SetNoalg(true)
dowidth(bucket)
makefield("extra", types.Types[types.TUNSAFEPTR]),
}
- hmap := types.NewStruct(fields)
+ hmap := types.NewStruct(types.NoPkg, fields)
hmap.SetNoalg(true)
dowidth(hmap)
}
// build iterator struct holding the above fields
- hiter := types.NewStruct(fields)
+ hiter := types.NewStruct(types.NoPkg, fields)
hiter.SetNoalg(true)
dowidth(hiter)
if hiter.Width != int64(12*Widthptr) {
}
// build struct holding the above fields
- s := types.NewStruct(fields)
+ s := types.NewStruct(types.NoPkg, fields)
s.SetNoalg(true)
s.Width = widstruct(s, s, 0, 1)
s.Align = uint8(Widthptr)
}
types.Types[types.TANY] = types.New(types.TANY)
- types.Types[types.TINTER] = types.NewInterface(nil)
+ types.Types[types.TINTER] = types.NewInterface(ir.LocalPkg, nil)
defBasic := func(kind types.Kind, pkg *types.Pkg, name string) *types.Type {
sym := pkg.Lookup(name)
}
func makeErrorInterface() *types.Type {
- sig := types.NewSignature(fakeRecvField(), nil, []*types.Field{
+ sig := types.NewSignature(types.NoPkg, fakeRecvField(), nil, []*types.Field{
types.NewField(src.NoXPos, nil, types.Types[types.TSTRING]),
})
method := types.NewField(src.NoXPos, lookup("Error"), sig)
- return types.NewInterface([]*types.Field{method})
+ return types.NewInterface(types.NoPkg, []*types.Field{method})
}
// finishUniverse makes the universe block visible within the current package.
return src.NoXPos
}
+// 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
}
}
-// SetPkg sets the package that t appeared in.
-func (t *Type) SetPkg(pkg *Pkg) {
- switch t.kind {
- case TFUNC:
- t.Extra.(*Func).pkg = pkg
- case TSTRUCT:
- t.Extra.(*Struct).pkg = pkg
- case TINTER:
- t.Extra.(*Interface).pkg = pkg
- default:
- Fatalf("Pkg: unexpected kind: %v", t)
- }
-}
-
// Map contains Type fields specific to maps.
type Map struct {
Key *Type // Key type
}
}
-// NewNamed returns a new basic type of the given kind.
+// NewBasic returns a new basic type of the given kind.
func NewBasic(kind Kind, obj Object) *Type {
t := New(kind)
t.sym = obj.Sym()
// NewInterface returns a new interface for the given methods and
// embedded types. Embedded types are specified as fields with no Sym.
-func NewInterface(methods []*Field) *Type {
+func NewInterface(pkg *Pkg, methods []*Field) *Type {
t := New(TINTER)
t.SetInterface(methods)
if anyBroke(methods) {
t.SetBroke(true)
}
+ t.Extra.(*Interface).pkg = pkg
return t
}
-// NewSignature returns a new function type for the given receiver,
-// parameters, and results, any of which may be nil.
-func NewSignature(recv *Field, params, results []*Field) *Type {
+// NewSignature returns a new function type for the given receiver,
+// parameters, and results, any of which may be nil.
+func NewSignature(pkg *Pkg, recv *Field, params, results []*Field) *Type {
var recvs []*Field
if recv != nil {
recvs = []*Field{recv}
ft := t.FuncType()
funargs := func(fields []*Field, funarg Funarg) *Type {
- s := NewStruct(fields)
+ s := NewStruct(NoPkg, fields)
s.StructType().Funarg = funarg
if s.Broke() {
t.SetBroke(true)
ft.Receiver = funargs(recvs, FunargRcvr)
ft.Params = funargs(params, FunargParams)
ft.Results = funargs(results, FunargResults)
+ ft.pkg = pkg
return t
}
// NewStruct returns a new struct with the given fields.
-func NewStruct(fields []*Field) *Type {
+func NewStruct(pkg *Pkg, fields []*Field) *Type {
t := New(TSTRUCT)
t.SetFields(fields)
if anyBroke(fields) {
t.SetBroke(true)
}
+ t.Extra.(*Struct).pkg = pkg
return t
}