diff --git a/src/cmd/compile/internal/importer/iimport.go b/src/cmd/compile/internal/importer/iimport.go index 4a7fece188d236e52442e881064d7871432a1dab..97feb7f3fdd5baa3f60454fdf4ffa2a0c29d3c20 100644 --- a/src/cmd/compile/internal/importer/iimport.go +++ b/src/cmd/compile/internal/importer/iimport.go @@ -321,10 +321,14 @@ func (r *importReader) obj(name string) { pos := r.pos() switch tag { - case 'A': - typ := r.typ() - - r.declare(types2.NewTypeName(pos, r.currPkg, name, typ)) + case 'A', 'B': + var tparams []*types2.TypeParam + if tag == 'B' { + tparams = r.tparamList() + } + rhs := r.typ() + const enabled = true // This is now always enabled within the compiler. + r.declare(newAliasTypeName(enabled, pos, r.currPkg, name, rhs, tparams)) case 'C': typ, val := r.value() diff --git a/src/cmd/compile/internal/importer/ureader.go b/src/cmd/compile/internal/importer/ureader.go index e8d3e20cee969a141badb30f83fe699dd935de77..e0405b9afbe271ef4069520db14eb4a4418b67c9 100644 --- a/src/cmd/compile/internal/importer/ureader.go +++ b/src/cmd/compile/internal/importer/ureader.go @@ -410,8 +410,9 @@ 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. typ := r.typ() - return newAliasTypeName(pr.enableAlias, pos, objPkg, objName, typ) + return newAliasTypeName(pr.enableAlias, pos, objPkg, objName, typ, tparams) case pkgbits.ObjConst: pos := r.pos() @@ -537,13 +538,15 @@ func (r *reader) ident(marker pkgbits.SyncMarker) (*types2.Package, string) { } // newAliasTypeName returns a new TypeName, with a materialized *types2.Alias if supported. -func newAliasTypeName(aliases bool, pos syntax.Pos, pkg *types2.Package, name string, rhs types2.Type) *types2.TypeName { +func newAliasTypeName(aliases bool, pos syntax.Pos, pkg *types2.Package, name string, rhs types2.Type, tparams []*types2.TypeParam) *types2.TypeName { // Copied from x/tools/internal/aliases.NewAlias via // GOROOT/src/go/internal/gcimporter/ureader.go. if aliases { tname := types2.NewTypeName(pos, pkg, name, nil) - _ = types2.NewAlias(tname, rhs) // form TypeName -> Alias cycle + a := types2.NewAlias(tname, rhs) // form TypeName -> Alias cycle + a.SetTypeParams(tparams) return tname } + assert(len(tparams) == 0) return types2.NewTypeName(pos, pkg, name, rhs) } diff --git a/src/cmd/compile/internal/typecheck/iexport.go b/src/cmd/compile/internal/typecheck/iexport.go index 83d35b365f29d561f0e6b78bda439933aeae6a4f..29d6b2cc2dcb55bfee0552d8706a695cf8774df0 100644 --- a/src/cmd/compile/internal/typecheck/iexport.go +++ b/src/cmd/compile/internal/typecheck/iexport.go @@ -90,8 +90,9 @@ // } // // type Alias struct { -// Tag byte // 'A' +// Tag byte // 'A' or 'B' // Pos Pos +// TypeParams []typeOff // only present if Tag == 'B' // Type typeOff // } // diff --git a/src/go/internal/gcimporter/iimport.go b/src/go/internal/gcimporter/iimport.go index e7750e5e51dc823afc9f0fba54ee7101f1e7115d..b36210c8179af53470b6381ccac666402da3190a 100644 --- a/src/go/internal/gcimporter/iimport.go +++ b/src/go/internal/gcimporter/iimport.go @@ -333,10 +333,13 @@ func (r *importReader) obj(name string) { pos := r.pos() switch tag { - case 'A': - typ := r.typ() - - r.declare(types.NewTypeName(pos, r.currPkg, name, typ)) + case 'A', 'B': + var tparams []*types.TypeParam + if tag == 'B' { + tparams = r.tparamList() + } + rhs := r.typ() + r.declare(newAliasTypeName(pos, r.currPkg, name, rhs, tparams)) case 'C': typ, val := r.value() diff --git a/src/go/internal/gcimporter/ureader.go b/src/go/internal/gcimporter/ureader.go index 5353b244e207e8f0891a5c7500cc79374b354ba8..68d50626c5cafee3d89ea1b8b73a33692d311807 100644 --- a/src/go/internal/gcimporter/ureader.go +++ b/src/go/internal/gcimporter/ureader.go @@ -482,8 +482,9 @@ 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. typ := r.typ() - declare(newAliasTypeName(pos, objPkg, objName, typ)) + declare(newAliasTypeName(pos, objPkg, objName, typ, tparams)) case pkgbits.ObjConst: pos := r.pos() @@ -661,14 +662,16 @@ func pkgScope(pkg *types.Package) *types.Scope { } // newAliasTypeName returns a new TypeName, with a materialized *types.Alias if supported. -func newAliasTypeName(pos token.Pos, pkg *types.Package, name string, rhs types.Type) *types.TypeName { +func newAliasTypeName(pos token.Pos, pkg *types.Package, name string, rhs types.Type, tparams []*types.TypeParam) *types.TypeName { // When GODEBUG=gotypesalias=1 or unset, the Type() of the return value is a // *types.Alias. Copied from x/tools/internal/aliases.NewAlias. switch godebug.New("gotypesalias").Value() { case "", "1": tname := types.NewTypeName(pos, pkg, name, nil) - _ = types.NewAlias(tname, rhs) // form TypeName -> Alias cycle + a := types.NewAlias(tname, rhs) // form TypeName -> Alias cycle + a.SetTypeParams(tparams) return tname } + assert(len(tparams) == 0) return types.NewTypeName(pos, pkg, name, rhs) }