aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/gc/export.go
diff options
context:
space:
mode:
authorMatthew Dempsky <mdempsky@google.com>2018-03-30 18:58:03 -0700
committerMatthew Dempsky <mdempsky@google.com>2018-04-02 22:41:56 +0000
commitbcc8edfd8a6b95865911e7a03a21b40bad0acc1d (patch)
tree6d12ac34f19fe86d31b68bc412bed2ed56dffb14 /src/cmd/compile/internal/gc/export.go
parentfd22542eaa02f73bdd1e74b5116165813fc3458b (diff)
downloadgo-bcc8edfd8a6b95865911e7a03a21b40bad0acc1d.tar.gz
go-bcc8edfd8a6b95865911e7a03a21b40bad0acc1d.zip
cmd/compile: simplify reexport logic
Currently, we reexport any package-scope constant, function, type, or variable declarations needed by an inlineable function body. However, now that we have an early pass to walk inlineable function bodies (golang.org/cl/74110), we can simplify the logic for finding these declarations. The binary export format supports writing out type declarations in-place at their first use. Also, it always writes out constants by value, so their declarations never need to be reexported. Notably, we attempted this before (golang.org/cl/36170) and had to revert it (golang.org/cl/45911). However, this was because while writing out inline bodies, we could discover variable/function dependencies. By collecting variable/function dependencies during inlineable function discovery, we avoid this problem. While here, get rid of isInlineable. We already typecheck inlineable function bodies during inlFlood, so it's become a no-op. Just move the comment explaining parameter numbering to its caller. Change-Id: Ibbfaafce793733675d3a2ad98791758583055666 Reviewed-on: https://go-review.googlesource.com/103864 Reviewed-by: Robert Griesemer <gri@golang.org>
Diffstat (limited to 'src/cmd/compile/internal/gc/export.go')
-rw-r--r--src/cmd/compile/internal/gc/export.go131
1 files changed, 12 insertions, 119 deletions
diff --git a/src/cmd/compile/internal/gc/export.go b/src/cmd/compile/internal/gc/export.go
index c5d5c52205..10ce23b16c 100644
--- a/src/cmd/compile/internal/gc/export.go
+++ b/src/cmd/compile/internal/gc/export.go
@@ -53,6 +53,18 @@ func exportsym(n *Node) {
exportlist = append(exportlist, n)
}
+// reexportsym marks n for reexport.
+func reexportsym(n *Node) {
+ if exportedsym(n.Sym) {
+ return
+ }
+
+ if Debug['E'] != 0 {
+ fmt.Printf("reexport name %v\n", n.Sym)
+ }
+ exportlist = append(exportlist, n)
+}
+
func exportname(s string) bool {
if r := s[0]; r < utf8.RuneSelf {
return 'A' <= r && r <= 'Z'
@@ -96,125 +108,6 @@ func autoexport(n *Node, ctxt Class) {
}
}
-// Look for anything we need for the inline body
-func reexportdeplist(ll Nodes) {
- for _, n := range ll.Slice() {
- reexportdep(n)
- }
-}
-
-func reexportdep(n *Node) {
- if n == nil {
- return
- }
-
- //print("reexportdep %+hN\n", n);
- switch n.Op {
- case ONAME:
- switch n.Class() {
- case PFUNC:
- // methods will be printed along with their type
- // nodes for T.Method expressions
- if n.isMethodExpression() {
- break
- }
-
- // nodes for method calls.
- if n.Type == nil || n.IsMethod() {
- break
- }
- fallthrough
-
- case PEXTERN:
- if n.Sym != nil && !exportedsym(n.Sym) {
- if Debug['E'] != 0 {
- fmt.Printf("reexport name %v\n", n.Sym)
- }
- exportlist = append(exportlist, n)
- }
- }
-
- // Local variables in the bodies need their type.
- case ODCL:
- t := n.Left.Type
-
- if t != types.Types[t.Etype] && t != types.Idealbool && t != types.Idealstring {
- if t.IsPtr() {
- t = t.Elem()
- }
- if t != nil && t.Sym != nil && t.Sym.Def != nil && !exportedsym(t.Sym) {
- if Debug['E'] != 0 {
- fmt.Printf("reexport type %v from declaration\n", t.Sym)
- }
- exportlist = append(exportlist, asNode(t.Sym.Def))
- }
- }
-
- case OLITERAL:
- t := n.Type
- if t != types.Types[n.Type.Etype] && t != types.Idealbool && t != types.Idealstring {
- if t.IsPtr() {
- t = t.Elem()
- }
- if t != nil && t.Sym != nil && t.Sym.Def != nil && !exportedsym(t.Sym) {
- if Debug['E'] != 0 {
- fmt.Printf("reexport literal type %v\n", t.Sym)
- }
- exportlist = append(exportlist, asNode(t.Sym.Def))
- }
- }
- fallthrough
-
- case OTYPE:
- if n.Sym != nil && n.Sym.Def != nil && !exportedsym(n.Sym) {
- if Debug['E'] != 0 {
- fmt.Printf("reexport literal/type %v\n", n.Sym)
- }
- exportlist = append(exportlist, n)
- }
-
- // for operations that need a type when rendered, put the type on the export list.
- case OCONV,
- OCONVIFACE,
- OCONVNOP,
- ORUNESTR,
- OARRAYBYTESTR,
- OARRAYRUNESTR,
- OSTRARRAYBYTE,
- OSTRARRAYRUNE,
- ODOTTYPE,
- ODOTTYPE2,
- OSTRUCTLIT,
- OARRAYLIT,
- OSLICELIT,
- OPTRLIT,
- OMAKEMAP,
- OMAKESLICE,
- OMAKECHAN:
- t := n.Type
-
- switch t.Etype {
- case TARRAY, TCHAN, TPTR32, TPTR64, TSLICE:
- if t.Sym == nil {
- t = t.Elem()
- }
- }
- if t != nil && t.Sym != nil && t.Sym.Def != nil && !exportedsym(t.Sym) {
- if Debug['E'] != 0 {
- fmt.Printf("reexport type for expression %v\n", t.Sym)
- }
- exportlist = append(exportlist, asNode(t.Sym.Def))
- }
- }
-
- reexportdep(n.Left)
- reexportdep(n.Right)
- reexportdeplist(n.List)
- reexportdeplist(n.Rlist)
- reexportdeplist(n.Ninit)
- reexportdeplist(n.Nbody)
-}
-
// methodbyname sorts types by symbol name.
type methodbyname []*types.Field