]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal: write type parameters for aliases
authorTim King <taking@google.com>
Tue, 20 Aug 2024 19:43:59 +0000 (12:43 -0700)
committerTim King <taking@google.com>
Fri, 23 Aug 2024 19:22:02 +0000 (19:22 +0000)
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>
src/cmd/compile/internal/importer/ureader.go
src/cmd/compile/internal/noder/reader.go
src/cmd/compile/internal/noder/writer.go
src/go/internal/gcimporter/ureader.go

index 467b1d418f41c9263ed9f68a20e21f40bd64e1d7..5f14eb695e44dd580741f88af101900551f3299d 100644 (file)
@@ -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)
 
index a825d60f7eb813c292a9663dc423697155948033..33fb7d35e1c0fad15cfdd7382fd0189b19cb2e7c 100644 (file)
@@ -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
index c3ca40879062d0e36c3cda7f8480ee9db4e08018..ecc03cbd838f24bf7fc7d2b8bfc922fc6b511b3a 100644 (file)
@@ -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
                }
 
index e4b4e17749903ae27ae059f13f53edd166ec4c59..b763ff5cca368618ac6f6e5e466707190cdd13be 100644 (file)
@@ -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))