r.declare(types2.NewConst(pos, r.currPkg, name, typ, val))
- case 'F':
+ case 'F', 'G':
var tparams []*types2.TypeName
- if r.p.exportVersion >= iexportVersionGenerics {
+ if tag == 'G' {
tparams = r.tparamList()
}
sig := r.signature(nil)
sig.SetTParams(tparams)
-
r.declare(types2.NewFunc(pos, r.currPkg, name, sig))
- case 'T':
+ case 'T', 'U':
var tparams []*types2.TypeName
- if r.p.exportVersion >= iexportVersionGenerics {
+ if tag == 'U' {
tparams = r.tparamList()
}
// declaration before recursing.
obj := types2.NewTypeName(pos, r.currPkg, name, nil)
named := types2.NewNamed(obj, nil, nil)
- named.SetTParams(tparams)
+ if tag == 'U' {
+ named.SetTParams(tparams)
+ }
r.declare(obj)
underlying := r.p.typAt(r.uint64(), named).Underlying()
// Assemble header.
var hdr intWriter
hdr.WriteByte('i')
- if base.Flag.G > 0 {
- hdr.uint64(iexportVersionCurrent)
- } else {
- // Use old export format if doing -G=0 (no generics)
- hdr.uint64(iexportVersionPosCol)
- }
+ hdr.uint64(iexportVersionCurrent)
hdr.uint64(uint64(p.strings.Len()))
hdr.uint64(dataLen)
}
// Function.
- w.tag('F')
+ if n.Type().TParams().NumFields() == 0 {
+ w.tag('F')
+ } else {
+ w.tag('G')
+ }
w.pos(n.Pos())
// The tparam list of the function type is the
// declaration of the type params. So, write out the type
// referenced via their type offset (via typOff) in all
// other places in the signature and function that they
// are used.
- if base.Flag.G > 0 {
+ if n.Type().TParams().NumFields() > 0 {
w.tparamList(n.Type().TParams().FieldSlice())
}
w.signature(n.Type())
}
// Defined type.
- w.tag('T')
+ if len(n.Type().RParams()) == 0 {
+ w.tag('T')
+ } else {
+ w.tag('U')
+ }
w.pos(n.Pos())
- if base.Flag.G > 0 {
+ if len(n.Type().RParams()) > 0 {
// Export type parameters, if any, needed for this type
w.typeList(n.Type().RParams())
}
r.constExt(n)
return n
- case 'F':
+ case 'F', 'G':
var tparams []*types.Field
- if r.p.exportVersion >= iexportVersionGenerics {
+ if tag == 'G' {
tparams = r.tparamList()
}
typ := r.signature(nil, tparams)
r.funcExt(n)
return n
- case 'T':
+ case 'T', 'U':
var rparams []*types.Type
- if r.p.exportVersion >= iexportVersionGenerics {
+ if tag == 'U' {
rparams = r.typeList()
}
// declaration before recursing.
n := importtype(pos, sym)
t := n.Type()
- if rparams != nil {
+ if tag == 'U' {
t.SetRParams(rparams)
}
r.declare(types.NewConst(pos, r.currPkg, name, typ, val))
case 'F':
- if r.p.exportVersion >= iexportVersionGenerics {
- numTparams := r.uint64()
- if numTparams > 0 {
- errorf("unexpected tparam")
- }
- }
sig := r.signature(nil)
r.declare(types.NewFunc(pos, r.currPkg, name, sig))
- case 'T':
- if r.p.exportVersion >= iexportVersionGenerics {
- numTparams := r.uint64()
- if numTparams > 0 {
- errorf("unexpected tparam")
- }
- }
+ case 'G':
+ errorf("unexpected parameterized function/method")
+ case 'T':
// Types can be recursive. We need to setup a stub
// declaration before recursing.
obj := types.NewTypeName(pos, r.currPkg, name, nil)
}
}
+ case 'U':
+ errorf("unexpected parameterized type")
+
case 'V':
typ := r.typ()