From f4ab8203bab58b3c4ae53a99535719a747d05332 Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Mon, 18 May 2015 10:27:59 -0700 Subject: [PATCH] cmd/internal/gc: separate Node param fields Param will be converted from an anonymous to a named field in a subsequent, automated CL. Reduces Node size from 368 to 328. Reduces inuse_space on the rotate tests by about 3%. No functional changes. Passes toolstash -cmp. Updates #9933. Change-Id: I5867b00328abf17ee24aea6ca58876bae9d8bfed Reviewed-on: https://go-review.googlesource.com/10210 Reviewed-by: Russ Cox --- src/cmd/internal/gc/export.go | 2 +- src/cmd/internal/gc/subr.go | 4 ++++ src/cmd/internal/gc/syntax.go | 26 +++++++++++++++----------- src/cmd/internal/gc/typecheck.go | 8 ++++---- 4 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/cmd/internal/gc/export.go b/src/cmd/internal/gc/export.go index 1efc8150c5..614de4e2ce 100644 --- a/src/cmd/internal/gc/export.go +++ b/src/cmd/internal/gc/export.go @@ -64,7 +64,7 @@ func autoexport(n *Node, ctxt uint8) { if (ctxt != PEXTERN && ctxt != PFUNC) || dclcontext != PEXTERN { return } - if n.Ntype != nil && n.Ntype.Op == OTFUNC && n.Ntype.Left != nil { // method + if n.Param != nil && n.Ntype != nil && n.Ntype.Op == OTFUNC && n.Ntype.Left != nil { // method return } diff --git a/src/cmd/internal/gc/subr.go b/src/cmd/internal/gc/subr.go index 33741c3baf..b10a6b3d3d 100644 --- a/src/cmd/internal/gc/subr.go +++ b/src/cmd/internal/gc/subr.go @@ -371,8 +371,12 @@ func Nod(op int, nleft *Node, nright *Node) *Node { switch op { case OCLOSURE, ODCLFUNC: n.Func = new(Func) + n.Param = new(Param) case ONAME: n.Name = new(Name) + n.Param = new(Param) + case ODCLFIELD: + n.Param = new(Param) } return n } diff --git a/src/cmd/internal/gc/syntax.go b/src/cmd/internal/gc/syntax.go index d4ede60c90..d52a3d4fe7 100644 --- a/src/cmd/internal/gc/syntax.go +++ b/src/cmd/internal/gc/syntax.go @@ -65,21 +65,12 @@ type Node struct { // ONAME Name *Name - Ntype *Node Defn *Node // ONAME: initializing assignment; OLABEL: labeled statement Pack *Node // real package for import . names Curfn *Node // function for local variables Paramfld *Type // TFIELD for this PPARAM; also for ODOT, curfn - - // ONAME func param with PHEAP - Outerexpr *Node // expression copied into closure for variable - Stackparam *Node // OPARAM node referring to stack copy of param - Alloc *Node // allocation call - - // ONAME closure param with PPARAMREF - Outer *Node // outer PPARAMREF in nested closure - Closure *Node // ONAME/PHEAP <-> ONAME/PPARAMREF - Top int // top context (Ecall, Eproc, etc) + Alloc *Node // allocation call + *Param // OPACK Pkg *Pkg @@ -115,6 +106,19 @@ type Name struct { Needzero bool // if it contains pointers, needs to be zeroed on function entry } +type Param struct { + Ntype *Node + + // ONAME func param with PHEAP + Outerexpr *Node // expression copied into closure for variable + Stackparam *Node // OPARAM node referring to stack copy of param + + // ONAME closure param with PPARAMREF + Outer *Node // outer PPARAMREF in nested closure + Closure *Node // ONAME/PHEAP <-> ONAME/PPARAMREF + Top int // top context (Ecall, Eproc, etc) +} + // Func holds Node fields used only with function-like nodes. type Func struct { Shortname *Node diff --git a/src/cmd/internal/gc/typecheck.go b/src/cmd/internal/gc/typecheck.go index 06f8b34305..8af9f084e2 100644 --- a/src/cmd/internal/gc/typecheck.go +++ b/src/cmd/internal/gc/typecheck.go @@ -813,7 +813,7 @@ OpSwitch: var l *Node for l = n.Left; l != r; l = l.Left { l.Addrtaken = true - if l.Closure != nil { + if l.Param != nil && l.Closure != nil { l.Closure.Addrtaken = true } } @@ -822,7 +822,7 @@ OpSwitch: Fatal("found non-orig name node %v", l) } l.Addrtaken = true - if l.Closure != nil { + if l.Param != nil && l.Closure != nil { l.Closure.Addrtaken = true } defaultlit(&n.Left, nil) @@ -3273,13 +3273,13 @@ func checkassign(stmt *Node, n *Node) { var l *Node for l = n; l != r; l = l.Left { l.Assigned = true - if l.Closure != nil { + if l.Param != nil && l.Closure != nil { l.Closure.Assigned = true } } l.Assigned = true - if l.Closure != nil { + if l.Param != nil && l.Closure != nil { l.Closure.Assigned = true } }