]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: don't lose //go:nointerface pragma in export data
authorRobert Griesemer <gri@golang.org>
Fri, 1 Jul 2016 17:51:59 +0000 (10:51 -0700)
committerRobert Griesemer <gri@golang.org>
Fri, 1 Jul 2016 19:20:11 +0000 (19:20 +0000)
Fixes #16243.

Change-Id: I207d1e8aa48abe453a23c709ccf4f8e07368595b
Reviewed-on: https://go-review.googlesource.com/24648
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/compile/internal/gc/bexport.go
src/cmd/compile/internal/gc/bimport.go
src/cmd/compile/internal/gc/builtin.go
src/cmd/compile/internal/gc/parser.go
src/go/internal/gcimporter/bimport.go

index c7be2deaa2c37bfcf28bdac6769e446e76496cb5..38e035edc8ed371ee9ba39b679c86b5ed832f44d 100644 (file)
@@ -153,7 +153,13 @@ const debugFormat = false // default: false
 // TODO(gri) disable and remove once there is only one export format again
 const forceObjFileStability = true
 
-const exportVersion = "v0"
+// Supported export format versions.
+// TODO(gri) Make this more systematic (issue #16244).
+const (
+       exportVersion0 = "v0"
+       exportVersion1 = "v1"
+       exportVersion  = exportVersion1
+)
 
 // exportInlined enables the export of inlined function bodies and related
 // dependencies. The compiler should work w/o any loss of functionality with
@@ -727,6 +733,14 @@ func (p *exporter) typ(t *Type) {
                        p.paramList(sig.Params(), inlineable)
                        p.paramList(sig.Results(), inlineable)
 
+                       // for issue #16243
+                       // We make this conditional for 1.7 to avoid consistency problems
+                       // with installed packages compiled with an older version.
+                       // TODO(gri) Clean up after 1.7 is out (issue #16244)
+                       if exportVersion == exportVersion1 {
+                               p.bool(m.Nointerface)
+                       }
+
                        var f *Func
                        if inlineable {
                                f = mfn.Func
index 5a4d9a3c55a2fe6789da6cf9730f14704ecc8f90..2b666cc21ce30e8b11c868c1974ab92af0ec6c22 100644 (file)
@@ -21,8 +21,9 @@ import (
 // changes to bimport.go and bexport.go.
 
 type importer struct {
-       in  *bufio.Reader
-       buf []byte // reused for reading strings
+       in      *bufio.Reader
+       buf     []byte // reused for reading strings
+       version string
 
        // object lists, in order of deserialization
        strList       []string
@@ -67,8 +68,9 @@ func Import(in *bufio.Reader) {
 
        // --- generic export data ---
 
-       if v := p.string(); v != exportVersion {
-               Fatalf("importer: unknown export data version: %s", v)
+       p.version = p.string()
+       if p.version != exportVersion0 && p.version != exportVersion1 {
+               Fatalf("importer: unknown export data version: %s", p.version)
        }
 
        // populate typList with predeclared "known" types
@@ -432,10 +434,15 @@ func (p *importer) typ() *Type {
                        params := p.paramList()
                        result := p.paramList()
 
+                       nointerface := false
+                       if p.version == exportVersion1 {
+                               nointerface = p.bool()
+                       }
+
                        n := methodname1(newname(sym), recv[0].Right)
                        n.Type = functype(recv[0], params, result)
                        checkwidth(n.Type)
-                       addmethod(sym, n.Type, tsym.Pkg, false, false)
+                       addmethod(sym, n.Type, tsym.Pkg, false, nointerface)
                        p.funcList = append(p.funcList, n)
                        importlist = append(importlist, n)
 
index b9010f4366dcce491133187a396ae9b7d1711bbb..c1a641874eef59a3d76e780f8b5543cba262edbb 100644 (file)
@@ -3,7 +3,7 @@
 package gc
 
 const runtimeimport = "" +
-       "cn\x00\x03v0\x01\rruntime\x00\t\x11newobject\x00\x02\x17\"\vtyp·2\x00\x00" +
+       "cn\x00\x03v1\x01\rruntime\x00\t\x11newobject\x00\x02\x17\"\vtyp·2\x00\x00" +
        "\x01\x17:\x00\t\x13panicindex\x00\x00\x00\t\x13panicslice\x00\x00\x00\t\x15pani" +
        "cdivide\x00\x00\x00\t\x15throwreturn\x00\x00\x00\t\x11throwinit\x00\x00\x00" +
        "\t\x11panicwrap\x00\x05 \x00 \x00 \x00\x00\t\rgopanic\x00\x01\x1b\x00\x00\x00\x00\t\x11go" +
@@ -105,6 +105,6 @@ const runtimeimport = "" +
        "\x01\x02\v\x00\x01\x00\n$$\n"
 
 const unsafeimport = "" +
-       "cn\x00\x03v0\x01\vunsafe\x00\x05\r\rPointer\x00\x16\x00\t\x0fOffsetof\x00\x01" +
+       "cn\x00\x03v1\x01\vunsafe\x00\x05\r\rPointer\x00\x16\x00\t\x0fOffsetof\x00\x01" +
        ":\x00\x01\x16\x00\t\vSizeof\x00\x01:\x00\x01\x16\x00\t\rAlignof\x00\x01:\x00\x01\x16\x00\v\b\x00\v" +
        "\x00\x01\x00\n$$\n"
index 7ffd42f83cba51f6667ebd51877df317c4fe01cf..3897db955cf778bae4562536803b7f4c9e4773a8 100644 (file)
@@ -2006,7 +2006,8 @@ func (p *parser) hidden_fndcl() *Node {
                ss.Type = functype(s2[0], s6, s8)
 
                checkwidth(ss.Type)
-               addmethod(s4, ss.Type, p.structpkg, false, false)
+               addmethod(s4, ss.Type, p.structpkg, false, p.pragma&Nointerface != 0)
+               p.pragma = 0
                funchdr(ss)
 
                // inl.C's inlnode in on a dotmeth node expects to find the inlineable body as
index 341358287a1ffda5aa474a2a43837e8e542cc35f..75c2d9123e98747e7ef4ddc49fe984a852654134 100644 (file)
@@ -21,6 +21,7 @@ type importer struct {
        data    []byte
        path    string
        buf     []byte // for reading strings
+       version string
 
        // object lists
        strList       []string         // in order of appearance
@@ -66,8 +67,9 @@ func BImportData(imports map[string]*types.Package, data []byte, path string) (i
 
        // --- generic export data ---
 
-       if v := p.string(); v != "v0" {
-               return p.read, nil, fmt.Errorf("unknown export data version: %s", v)
+       p.version = p.string()
+       if p.version != "v0" && p.version != "v1" {
+               return p.read, nil, fmt.Errorf("unknown export data version: %s", p.version)
        }
 
        // populate typList with predeclared "known" types
@@ -304,6 +306,10 @@ func (p *importer) typ(parent *types.Package) types.Type {
                        params, isddd := p.paramList()
                        result, _ := p.paramList()
 
+                       if p.version == "v1" {
+                               p.int() // nointerface flag - discarded
+                       }
+
                        sig := types.NewSignature(recv.At(0), params, result, isddd)
                        t0.AddMethod(types.NewFunc(token.NoPos, parent, name, sig))
                }