mirror of
https://github.com/golang/go
synced 2024-09-04 23:44:16 +00:00
[dev.typeparams] cmd/compile: don't export/import type parameter indices anymore
types2 now determines type parameter indices lazily, so we don't need them just as we are importing. We set them in types1 as we are importing the type param list itself. type param indices are not strongly needed in types1 - we only use them in one place which could be rewritten. But I kept them in analogy to types2 (TypeParam.Index). Fixes #47451 Change-Id: I30631f95c45a259354eaf7ec5194f71e799eb358 Reviewed-on: https://go-review.googlesource.com/c/go/+/340532 Run-TryBot: Dan Scales <danscales@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org> Trust: Dan Scales <danscales@google.com>
This commit is contained in:
parent
9e0ac72d68
commit
d10a904712
|
@ -364,10 +364,6 @@ func (r *importReader) obj(name string) {
|
||||||
if r.p.exportVersion < iexportVersionGenerics {
|
if r.p.exportVersion < iexportVersionGenerics {
|
||||||
errorf("unexpected type param type")
|
errorf("unexpected type param type")
|
||||||
}
|
}
|
||||||
// Type parameter indices are lazily "allocated".
|
|
||||||
// There's no need to export them anymore.
|
|
||||||
// TODO change the export format accordingly
|
|
||||||
_ = int(r.int64())
|
|
||||||
name0, sub := parseSubscript(name)
|
name0, sub := parseSubscript(name)
|
||||||
tn := types2.NewTypeName(pos, r.currPkg, name0, nil)
|
tn := types2.NewTypeName(pos, r.currPkg, name0, nil)
|
||||||
t := (*types2.Checker)(nil).NewTypeParam(tn, nil)
|
t := (*types2.Checker)(nil).NewTypeParam(tn, nil)
|
||||||
|
|
|
@ -531,7 +531,6 @@ func (p *iexporter) doDecl(n *ir.Name) {
|
||||||
// A typeparam has a name, and has a type bound rather
|
// A typeparam has a name, and has a type bound rather
|
||||||
// than an underlying type.
|
// than an underlying type.
|
||||||
w.pos(n.Pos())
|
w.pos(n.Pos())
|
||||||
w.int64(int64(n.Type().Index()))
|
|
||||||
w.typ(n.Type().Bound())
|
w.typ(n.Type().Bound())
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
|
@ -388,8 +388,9 @@ func (r *importReader) doDecl(sym *types.Sym) *ir.Name {
|
||||||
// this types2-to-types1 translation.
|
// this types2-to-types1 translation.
|
||||||
return sym.Def.(*ir.Name)
|
return sym.Def.(*ir.Name)
|
||||||
}
|
}
|
||||||
index := int(r.int64())
|
// The typeparam index is set at the point where the containing type
|
||||||
t := types.NewTypeParam(sym, index)
|
// param list is imported.
|
||||||
|
t := types.NewTypeParam(sym, 0)
|
||||||
// Nname needed to save the pos.
|
// Nname needed to save the pos.
|
||||||
nname := ir.NewDeclNameAt(pos, ir.OTYPE, sym)
|
nname := ir.NewDeclNameAt(pos, ir.OTYPE, sym)
|
||||||
sym.Def = nname
|
sym.Def = nname
|
||||||
|
@ -875,6 +876,9 @@ func (r *importReader) typeList() []*types.Type {
|
||||||
ts := make([]*types.Type, n)
|
ts := make([]*types.Type, n)
|
||||||
for i := range ts {
|
for i := range ts {
|
||||||
ts[i] = r.typ()
|
ts[i] = r.typ()
|
||||||
|
if ts[i].IsTypeParam() {
|
||||||
|
ts[i].SetIndex(i)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return ts
|
return ts
|
||||||
}
|
}
|
||||||
|
@ -887,6 +891,7 @@ func (r *importReader) tparamList() []*types.Field {
|
||||||
fs := make([]*types.Field, n)
|
fs := make([]*types.Field, n)
|
||||||
for i := range fs {
|
for i := range fs {
|
||||||
typ := r.typ()
|
typ := r.typ()
|
||||||
|
typ.SetIndex(i)
|
||||||
fs[i] = types.NewField(typ.Pos(), typ.Sym(), typ)
|
fs[i] = types.NewField(typ.Pos(), typ.Sym(), typ)
|
||||||
}
|
}
|
||||||
return fs
|
return fs
|
||||||
|
|
|
@ -1885,6 +1885,12 @@ func (t *Type) Index() int {
|
||||||
return t.Extra.(*Typeparam).index
|
return t.Extra.(*Typeparam).index
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetIndex sets the index of the type param within its param list.
|
||||||
|
func (t *Type) SetIndex(i int) {
|
||||||
|
t.wantEtype(TTYPEPARAM)
|
||||||
|
t.Extra.(*Typeparam).index = i
|
||||||
|
}
|
||||||
|
|
||||||
// SetBound sets the bound of a typeparam.
|
// SetBound sets the bound of a typeparam.
|
||||||
func (t *Type) SetBound(bound *Type) {
|
func (t *Type) SetBound(bound *Type) {
|
||||||
t.wantEtype(TTYPEPARAM)
|
t.wantEtype(TTYPEPARAM)
|
||||||
|
|
Loading…
Reference in a new issue