]> Cypherpunks.ru repositories - gostls13.git/commitdiff
cmd/compile: allow inlining of functions that declare a const
authorTodd Neal <todd@tneal.org>
Wed, 16 Mar 2016 23:44:17 +0000 (18:44 -0500)
committerRobert Griesemer <gri@golang.org>
Fri, 18 Mar 2016 23:26:36 +0000 (23:26 +0000)
Consider functions with an ODCLCONST for inlining and modify exprfmt to
ignore those nodes when exporting. Don't add symbols to the export list
if there is no definition.  This occurs when OLITERAL symbols are looked
up via Pkglookup for non-exported symbols.

Fixes #7655

Change-Id: I1de827850f4c69e58107447314fe7433e378e069
Reviewed-on: https://go-review.googlesource.com/20773
Run-TryBot: Todd Neal <todd@tneal.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
src/cmd/compile/internal/gc/bexport.go
src/cmd/compile/internal/gc/bimport.go
src/cmd/compile/internal/gc/export.go
src/cmd/compile/internal/gc/fmt.go
src/cmd/compile/internal/gc/inl.go
test/inline.go

index cbe2a812a4abea62e6b4dc5a86c36e95e6d45884..bf5b57757eb9efd6a1e146f2269044896258e588 100644 (file)
@@ -984,7 +984,7 @@ func (p *exporter) node(n *Node) {
        case OBREAK, OCONTINUE, OGOTO, OFALL, OXFALL:
                p.nodesOrNil(n.Left, nil)
 
-       case OEMPTY:
+       case OEMPTY, ODCLCONST:
                // nothing to do
 
        case OLABEL:
index f063557363574334b40440374b1785e57b4c8772..16d0e39c6d009204925bcbc06cbce96b947b5ea7 100644 (file)
@@ -751,7 +751,7 @@ func (p *importer) node() *Node {
        case OBREAK, OCONTINUE, OGOTO, OFALL, OXFALL:
                n.Left, _ = p.nodesOrNil()
 
-       case OEMPTY:
+       case OEMPTY, ODCLCONST:
                // nothing to do
 
        case OLABEL:
index 3e6b517436a914548e5e832d578a55a74361ec1c..751ad57174dd7c586e75a952b201e17192d23a34 100644 (file)
@@ -176,7 +176,7 @@ func reexportdep(n *Node) {
                fallthrough
 
        case OTYPE:
-               if n.Sym != nil && !exportedsym(n.Sym) {
+               if n.Sym != nil && n.Sym.Def != nil && !exportedsym(n.Sym) {
                        if Debug['E'] != 0 {
                                fmt.Printf("reexport literal/type %v\n", n.Sym)
                        }
@@ -331,7 +331,7 @@ func dumpexporttype(t *Type) {
                        if Debug['l'] < 2 {
                                typecheckinl(f.Type.Nname)
                        }
-                       exportf("\tfunc %v %v %v { %v }\n", Tconv(f.Type.Recvs(), FmtSharp), Sconv(f.Sym, FmtShort|FmtByte|FmtSharp), Tconv(f.Type, FmtShort|FmtSharp), Hconv(f.Type.Nname.Func.Inl, FmtSharp))
+                       exportf("\tfunc %v %v %v { %v }\n", Tconv(f.Type.Recvs(), FmtSharp), Sconv(f.Sym, FmtShort|FmtByte|FmtSharp), Tconv(f.Type, FmtShort|FmtSharp), Hconv(f.Type.Nname.Func.Inl, FmtSharp|FmtBody))
                        reexportdeplist(f.Type.Nname.Func.Inl)
                } else {
                        exportf("\tfunc %v %v %v\n", Tconv(f.Type.Recvs(), FmtSharp), Sconv(f.Sym, FmtShort|FmtByte|FmtSharp), Tconv(f.Type, FmtShort|FmtSharp))
index 73b030dd8a04f0ecc94add64248f9eaa3fd2e7d5..39320d1f613589e948a50eb2e92e39bc7d3a7804 100644 (file)
@@ -1413,6 +1413,13 @@ func exprfmt(n *Node, prec int) string {
                f += fmt.Sprintf(" %v ", Oconv(Op(n.Etype), FmtSharp))
                f += exprfmt(n.Right, nprec+1)
                return f
+
+       case ODCLCONST:
+               // if exporting, DCLCONST should just be removed as its usage
+               // has already been replaced with literals
+               if fmtbody {
+                       return ""
+               }
        }
 
        return fmt.Sprintf("<node %v>", Oconv(n.Op, 0))
index 15922abb590b0b92655199bc5ae640362710218e..ebfeb9b1578233e12e0d4d1d4d83498ae05c179e 100644 (file)
@@ -217,8 +217,7 @@ func ishairy(n *Node, budget *int) bool {
                OSWITCH,
                OPROC,
                ODEFER,
-               ODCLTYPE,  // can't print yet
-               ODCLCONST, // can't print yet
+               ODCLTYPE, // can't print yet
                ORETJMP:
                return true
        }
index fb20fab3292582c911c2707baa4d7c236d9f75dd..8984d059d8439ce20ea72d7b0aa38b4c49e7a59a 100644 (file)
@@ -31,3 +31,8 @@ func g(x int) int {
 func h(x int) int { // ERROR "can inline h"
        return x + 2
 }
+
+func i(x int) int { // ERROR "can inline i"
+       const y = 2
+       return x + y
+}