Skip to content

Commit

Permalink
cmd/compile/internal: write type parameters for aliases
Browse files Browse the repository at this point in the history
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 <drchase@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
  • Loading branch information
timothy-king committed Aug 23, 2024
1 parent 02a9f51 commit 3b36d92
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/cmd/compile/internal/importer/ureader.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,10 @@ func (pr *pkgReader) objIdx(idx pkgbits.Index) (*types2.Package, string) {

case pkgbits.ObjAlias:
pos := r.pos()
var tparams []*types2.TypeParam // TODO(#68778): Read tparams for unified IR.
var tparams []*types2.TypeParam
if r.Version().Has(pkgbits.AliasTypeParamNames) {
tparams = r.typeParamNames()
}
typ := r.typ()
return newAliasTypeName(pr.enableAlias, pos, objPkg, objName, typ, tparams)

Expand Down
4 changes: 4 additions & 0 deletions src/cmd/compile/internal/noder/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,10 @@ func (pr *pkgReader) objIdxMayFail(idx index, implicits, explicits []*types.Type
case pkgbits.ObjAlias:
name := do(ir.OTYPE, false)

if r.Version().Has(pkgbits.AliasTypeParamNames) {
r.typeParamNames()
}

// Clumsy dance: the r.typ() call here might recursively find this
// type alias name, before we've set its type (#66873). So we
// temporarily clear sym.Def and then restore it later, if still
Expand Down
16 changes: 12 additions & 4 deletions src/cmd/compile/internal/noder/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -855,11 +855,19 @@ func (w *writer) doObj(wext *writer, obj types2.Object) pkgbits.CodeObj {
case *types2.TypeName:
if obj.IsAlias() {
w.pos(obj)
t := obj.Type()
if alias, ok := t.(*types2.Alias); ok { // materialized alias
t = alias.Rhs()
rhs := obj.Type()
var tparams *types2.TypeParamList
if alias, ok := rhs.(*types2.Alias); ok { // materialized alias
assert(alias.TypeArgs() == nil)
tparams = alias.TypeParams()
rhs = alias.Rhs()
}
w.typ(t)
if w.Version().Has(pkgbits.AliasTypeParamNames) {
w.typeParamNames(tparams)
}
// TODO(taking): enable this assertion once this is not intended to be a nop.
// assert(w.Version().Has(pkgbits.AliasTypeParamNames) || tparams.Len() == 0)
w.typ(rhs)
return pkgbits.ObjAlias
}

Expand Down
5 changes: 4 additions & 1 deletion src/go/internal/gcimporter/ureader.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,10 @@ func (pr *pkgReader) objIdx(idx pkgbits.Index) (*types.Package, string) {

case pkgbits.ObjAlias:
pos := r.pos()
var tparams []*types.TypeParam // TODO(#68778): Read tparams for unified IR.
var tparams []*types.TypeParam
if r.Version().Has(pkgbits.AliasTypeParamNames) {
tparams = r.typeParamNames()
}
typ := r.typ()
declare(newAliasTypeName(pos, objPkg, objName, typ, tparams))

Expand Down

0 comments on commit 3b36d92

Please sign in to comment.