Skip to content

Commit 3b36d92

Browse files
committed
cmd/compile/internal: write type parameters for aliases
Writes the field for type parameter names for aliases when the bitstream is >= V2. This is a no-op at the moment as the writer is hardwired to V1. Updates #68778 Change-Id: I5887e3608239b9a6a47e3cc21cacb75b84e1d186 Reviewed-on: https://go-review.googlesource.com/c/go/+/607235 Reviewed-by: David Chase <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Robert Griesemer <[email protected]> Reviewed-by: Cuong Manh Le <[email protected]>
1 parent 02a9f51 commit 3b36d92

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

src/cmd/compile/internal/importer/ureader.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,10 @@ func (pr *pkgReader) objIdx(idx pkgbits.Index) (*types2.Package, string) {
417417

418418
case pkgbits.ObjAlias:
419419
pos := r.pos()
420-
var tparams []*types2.TypeParam // TODO(#68778): Read tparams for unified IR.
420+
var tparams []*types2.TypeParam
421+
if r.Version().Has(pkgbits.AliasTypeParamNames) {
422+
tparams = r.typeParamNames()
423+
}
421424
typ := r.typ()
422425
return newAliasTypeName(pr.enableAlias, pos, objPkg, objName, typ, tparams)
423426

src/cmd/compile/internal/noder/reader.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,10 @@ func (pr *pkgReader) objIdxMayFail(idx index, implicits, explicits []*types.Type
746746
case pkgbits.ObjAlias:
747747
name := do(ir.OTYPE, false)
748748

749+
if r.Version().Has(pkgbits.AliasTypeParamNames) {
750+
r.typeParamNames()
751+
}
752+
749753
// Clumsy dance: the r.typ() call here might recursively find this
750754
// type alias name, before we've set its type (#66873). So we
751755
// temporarily clear sym.Def and then restore it later, if still

src/cmd/compile/internal/noder/writer.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -855,11 +855,19 @@ func (w *writer) doObj(wext *writer, obj types2.Object) pkgbits.CodeObj {
855855
case *types2.TypeName:
856856
if obj.IsAlias() {
857857
w.pos(obj)
858-
t := obj.Type()
859-
if alias, ok := t.(*types2.Alias); ok { // materialized alias
860-
t = alias.Rhs()
858+
rhs := obj.Type()
859+
var tparams *types2.TypeParamList
860+
if alias, ok := rhs.(*types2.Alias); ok { // materialized alias
861+
assert(alias.TypeArgs() == nil)
862+
tparams = alias.TypeParams()
863+
rhs = alias.Rhs()
861864
}
862-
w.typ(t)
865+
if w.Version().Has(pkgbits.AliasTypeParamNames) {
866+
w.typeParamNames(tparams)
867+
}
868+
// TODO(taking): enable this assertion once this is not intended to be a nop.
869+
// assert(w.Version().Has(pkgbits.AliasTypeParamNames) || tparams.Len() == 0)
870+
w.typ(rhs)
863871
return pkgbits.ObjAlias
864872
}
865873

src/go/internal/gcimporter/ureader.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,10 @@ func (pr *pkgReader) objIdx(idx pkgbits.Index) (*types.Package, string) {
488488

489489
case pkgbits.ObjAlias:
490490
pos := r.pos()
491-
var tparams []*types.TypeParam // TODO(#68778): Read tparams for unified IR.
491+
var tparams []*types.TypeParam
492+
if r.Version().Has(pkgbits.AliasTypeParamNames) {
493+
tparams = r.typeParamNames()
494+
}
492495
typ := r.typ()
493496
declare(newAliasTypeName(pos, objPkg, objName, typ, tparams))
494497

0 commit comments

Comments
 (0)