]> Cypherpunks repositories - gostls13.git/commitdiff
go/internal/gcimporter: indexed format imports for type parameters aliases
authorTim King <taking@google.com>
Fri, 9 Aug 2024 21:36:21 +0000 (14:36 -0700)
committerTim King <taking@google.com>
Fri, 16 Aug 2024 22:38:15 +0000 (22:38 +0000)
Add support for importing a new 'B' tag for type parameters aliases
in the indexed data format.

Updates #68778

Change-Id: I3bd82870d4c4619a3771de30baf6d54f6ee5959e
Reviewed-on: https://go-review.googlesource.com/c/go/+/604635
Reviewed-by: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: David Chase <drchase@google.com>
src/cmd/compile/internal/importer/iimport.go
src/cmd/compile/internal/importer/ureader.go
src/cmd/compile/internal/typecheck/iexport.go
src/go/internal/gcimporter/iimport.go
src/go/internal/gcimporter/ureader.go

index 4a7fece188d236e52442e881064d7871432a1dab..97feb7f3fdd5baa3f60454fdf4ffa2a0c29d3c20 100644 (file)
@@ -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()
index e8d3e20cee969a141badb30f83fe699dd935de77..e0405b9afbe271ef4069520db14eb4a4418b67c9 100644 (file)
@@ -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)
 }
index 83d35b365f29d561f0e6b78bda439933aeae6a4f..29d6b2cc2dcb55bfee0552d8706a695cf8774df0 100644 (file)
@@ -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
 //     }
 //
index e7750e5e51dc823afc9f0fba54ee7101f1e7115d..b36210c8179af53470b6381ccac666402da3190a 100644 (file)
@@ -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()
index 5353b244e207e8f0891a5c7500cc79374b354ba8..68d50626c5cafee3d89ea1b8b73a33692d311807 100644 (file)
@@ -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)
 }