]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.typeparams] cmd/compile: keep export format unchanged if no type params are...
authorDan Scales <danscales@google.com>
Mon, 9 Aug 2021 23:00:29 +0000 (16:00 -0700)
committerDan Scales <danscales@google.com>
Tue, 10 Aug 2021 19:48:58 +0000 (19:48 +0000)
Added new export tags 'G' and 'U' to export parameterized
functions/methods and parameterized types respectively. This has the
advantage that the Go 1.18 format remains backward-compatible with the
Go 1.17 format if no type parameters are exported.

Change-Id: I9dba8faaa65609eb3f9c693bd0c79daee98bd865
Reviewed-on: https://go-review.googlesource.com/c/go/+/340989
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Dan Scales <danscales@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/cmd/compile/internal/importer/iimport.go
src/cmd/compile/internal/typecheck/iexport.go
src/cmd/compile/internal/typecheck/iimport.go
src/go/internal/gcimporter/iimport.go

index 99eb96441599e30131aaa302612f680401f3e37e..6051cdaf2318c691c070b1f1eb3afccce3e44fc6 100644 (file)
@@ -308,19 +308,18 @@ func (r *importReader) obj(name string) {
 
                r.declare(types2.NewConst(pos, r.currPkg, name, typ, val))
 
-       case 'F':
+       case 'F', 'G':
                var tparams []*types2.TypeName
-               if r.p.exportVersion >= iexportVersionGenerics {
+               if tag == 'G' {
                        tparams = r.tparamList()
                }
                sig := r.signature(nil)
                sig.SetTParams(tparams)
-
                r.declare(types2.NewFunc(pos, r.currPkg, name, sig))
 
-       case 'T':
+       case 'T', 'U':
                var tparams []*types2.TypeName
-               if r.p.exportVersion >= iexportVersionGenerics {
+               if tag == 'U' {
                        tparams = r.tparamList()
                }
 
@@ -328,7 +327,9 @@ func (r *importReader) obj(name string) {
                // declaration before recursing.
                obj := types2.NewTypeName(pos, r.currPkg, name, nil)
                named := types2.NewNamed(obj, nil, nil)
-               named.SetTParams(tparams)
+               if tag == 'U' {
+                       named.SetTParams(tparams)
+               }
                r.declare(obj)
 
                underlying := r.p.typAt(r.uint64(), named).Underlying()
index 2944908bcbc74c009f200d1194c6c1ffc1f7a050..5f510a0a250cd1e659d443f1ed766871e9e78e94 100644 (file)
@@ -314,12 +314,7 @@ func WriteExports(out io.Writer, extensions bool) {
        // Assemble header.
        var hdr intWriter
        hdr.WriteByte('i')
-       if base.Flag.G > 0 {
-               hdr.uint64(iexportVersionCurrent)
-       } else {
-               // Use old export format if doing -G=0 (no generics)
-               hdr.uint64(iexportVersionPosCol)
-       }
+       hdr.uint64(iexportVersionCurrent)
        hdr.uint64(uint64(p.strings.Len()))
        hdr.uint64(dataLen)
 
@@ -487,7 +482,11 @@ func (p *iexporter) doDecl(n *ir.Name) {
                        }
 
                        // Function.
-                       w.tag('F')
+                       if n.Type().TParams().NumFields() == 0 {
+                               w.tag('F')
+                       } else {
+                               w.tag('G')
+                       }
                        w.pos(n.Pos())
                        // The tparam list of the function type is the
                        // declaration of the type params. So, write out the type
@@ -495,7 +494,7 @@ func (p *iexporter) doDecl(n *ir.Name) {
                        // referenced via their type offset (via typOff) in all
                        // other places in the signature and function that they
                        // are used.
-                       if base.Flag.G > 0 {
+                       if n.Type().TParams().NumFields() > 0 {
                                w.tparamList(n.Type().TParams().FieldSlice())
                        }
                        w.signature(n.Type())
@@ -544,10 +543,14 @@ func (p *iexporter) doDecl(n *ir.Name) {
                }
 
                // Defined type.
-               w.tag('T')
+               if len(n.Type().RParams()) == 0 {
+                       w.tag('T')
+               } else {
+                       w.tag('U')
+               }
                w.pos(n.Pos())
 
-               if base.Flag.G > 0 {
+               if len(n.Type().RParams()) > 0 {
                        // Export type parameters, if any, needed for this type
                        w.typeList(n.Type().RParams())
                }
index d5f4bba98b2b0e2b5ef2f51614976338e6d20c90..83974b6d5678feff3282d3df76377c50e4b43384 100644 (file)
@@ -305,9 +305,9 @@ func (r *importReader) doDecl(sym *types.Sym) *ir.Name {
                r.constExt(n)
                return n
 
-       case 'F':
+       case 'F', 'G':
                var tparams []*types.Field
-               if r.p.exportVersion >= iexportVersionGenerics {
+               if tag == 'G' {
                        tparams = r.tparamList()
                }
                typ := r.signature(nil, tparams)
@@ -316,9 +316,9 @@ func (r *importReader) doDecl(sym *types.Sym) *ir.Name {
                r.funcExt(n)
                return n
 
-       case 'T':
+       case 'T', 'U':
                var rparams []*types.Type
-               if r.p.exportVersion >= iexportVersionGenerics {
+               if tag == 'U' {
                        rparams = r.typeList()
                }
 
@@ -326,7 +326,7 @@ func (r *importReader) doDecl(sym *types.Sym) *ir.Name {
                // declaration before recursing.
                n := importtype(pos, sym)
                t := n.Type()
-               if rparams != nil {
+               if tag == 'U' {
                        t.SetRParams(rparams)
                }
 
index b300860e94074a0c24a7e5c7fcec4db38fbe6bc5..d4778d3a745fdf5ecda6db0e3b3f09c247f74682 100644 (file)
@@ -290,24 +290,14 @@ func (r *importReader) obj(name string) {
                r.declare(types.NewConst(pos, r.currPkg, name, typ, val))
 
        case 'F':
-               if r.p.exportVersion >= iexportVersionGenerics {
-                       numTparams := r.uint64()
-                       if numTparams > 0 {
-                               errorf("unexpected tparam")
-                       }
-               }
                sig := r.signature(nil)
 
                r.declare(types.NewFunc(pos, r.currPkg, name, sig))
 
-       case 'T':
-               if r.p.exportVersion >= iexportVersionGenerics {
-                       numTparams := r.uint64()
-                       if numTparams > 0 {
-                               errorf("unexpected tparam")
-                       }
-               }
+       case 'G':
+               errorf("unexpected parameterized function/method")
 
+       case 'T':
                // Types can be recursive. We need to setup a stub
                // declaration before recursing.
                obj := types.NewTypeName(pos, r.currPkg, name, nil)
@@ -328,6 +318,9 @@ func (r *importReader) obj(name string) {
                        }
                }
 
+       case 'U':
+               errorf("unexpected parameterized type")
+
        case 'V':
                typ := r.typ()