summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2020-12-11 16:52:21 -0500
committerRuss Cox <rsc@golang.org>2020-12-17 03:50:21 +0000
commitf6d2834f8f78447a06fdb05f85a2c5690e915892 (patch)
treeea28423140d4697ddc6aa1d4a49b7cffd7e6125e /src
parent7fde0d2b507b989cb9a23d6dbae9acaa13328c53 (diff)
downloadgo-git-f6d2834f8f78447a06fdb05f85a2c5690e915892.tar.gz
[dev.regabi] cmd/compile: limit Implicit method to nodes where it is defined
The general concept of an "implicit" operation is provided by every expr representation, but it really only makes sense for a few of them, and worse the exact definition of what "implicit" means differs from node to node. This CL moves the method to each node implementation, although they all share the same header bit instead of each defining a bool field that would turn into 8 bytes on 64-bit systems. Now we can say precisely which Nodes have a meaningful Implicit method: AddrExpr, CompLitExpr, ConvExpr, ParenExpr, and StarExpr. Passes buildall w/ toolstash -cmp. Change-Id: I7d85cb0507a514cdcb6eed21347f362e5fb57a91 Reviewed-on: https://go-review.googlesource.com/c/go/+/277918 Trust: Russ Cox <rsc@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'src')
-rw-r--r--src/cmd/compile/internal/ir/expr.go50
1 files changed, 30 insertions, 20 deletions
diff --git a/src/cmd/compile/internal/ir/expr.go b/src/cmd/compile/internal/ir/expr.go
index 8ea31c1929..36a11dad9a 100644
--- a/src/cmd/compile/internal/ir/expr.go
+++ b/src/cmd/compile/internal/ir/expr.go
@@ -52,10 +52,10 @@ type miniExpr struct {
const (
miniExprHasCall = 1 << iota
- miniExprImplicit
miniExprNonNil
miniExprTransient
miniExprBounded
+ miniExprImplicit // for use by implementations; not supported by every Expr
)
func (*miniExpr) isExpr() {}
@@ -66,8 +66,6 @@ func (n *miniExpr) Opt() interface{} { return n.opt }
func (n *miniExpr) SetOpt(x interface{}) { n.opt = x }
func (n *miniExpr) HasCall() bool { return n.flags&miniExprHasCall != 0 }
func (n *miniExpr) SetHasCall(b bool) { n.flags.set(miniExprHasCall, b) }
-func (n *miniExpr) Implicit() bool { return n.flags&miniExprImplicit != 0 }
-func (n *miniExpr) SetImplicit(b bool) { n.flags.set(miniExprImplicit, b) }
func (n *miniExpr) NonNil() bool { return n.flags&miniExprNonNil != 0 }
func (n *miniExpr) MarkNonNil() { n.flags |= miniExprNonNil }
func (n *miniExpr) Transient() bool { return n.flags&miniExprTransient != 0 }
@@ -121,10 +119,12 @@ func NewAddrExpr(pos src.XPos, x Node) *AddrExpr {
return n
}
-func (n *AddrExpr) Left() Node { return n.X }
-func (n *AddrExpr) SetLeft(x Node) { n.X = x }
-func (n *AddrExpr) Right() Node { return n.Alloc }
-func (n *AddrExpr) SetRight(x Node) { n.Alloc = x }
+func (n *AddrExpr) Left() Node { return n.X }
+func (n *AddrExpr) SetLeft(x Node) { n.X = x }
+func (n *AddrExpr) Right() Node { return n.Alloc }
+func (n *AddrExpr) SetRight(x Node) { n.Alloc = x }
+func (n *AddrExpr) Implicit() bool { return n.flags&miniExprImplicit != 0 }
+func (n *AddrExpr) SetImplicit(b bool) { n.flags.set(miniExprImplicit, b) }
func (n *AddrExpr) SetOp(op Op) {
switch op {
@@ -301,13 +301,15 @@ func NewCompLitExpr(pos src.XPos, op Op, typ Ntype, list []Node) *CompLitExpr {
return n
}
-func (n *CompLitExpr) Orig() Node { return n.orig }
-func (n *CompLitExpr) SetOrig(x Node) { n.orig = x }
-func (n *CompLitExpr) Right() Node { return n.Ntype }
-func (n *CompLitExpr) SetRight(x Node) { n.Ntype = toNtype(x) }
-func (n *CompLitExpr) List() Nodes { return n.List_ }
-func (n *CompLitExpr) PtrList() *Nodes { return &n.List_ }
-func (n *CompLitExpr) SetList(x Nodes) { n.List_ = x }
+func (n *CompLitExpr) Orig() Node { return n.orig }
+func (n *CompLitExpr) SetOrig(x Node) { n.orig = x }
+func (n *CompLitExpr) Right() Node { return n.Ntype }
+func (n *CompLitExpr) SetRight(x Node) { n.Ntype = toNtype(x) }
+func (n *CompLitExpr) List() Nodes { return n.List_ }
+func (n *CompLitExpr) PtrList() *Nodes { return &n.List_ }
+func (n *CompLitExpr) SetList(x Nodes) { n.List_ = x }
+func (n *CompLitExpr) Implicit() bool { return n.flags&miniExprImplicit != 0 }
+func (n *CompLitExpr) SetImplicit(b bool) { n.flags.set(miniExprImplicit, b) }
func (n *CompLitExpr) SetOp(op Op) {
switch op {
@@ -354,8 +356,10 @@ func NewConvExpr(pos src.XPos, op Op, typ *types.Type, x Node) *ConvExpr {
return n
}
-func (n *ConvExpr) Left() Node { return n.X }
-func (n *ConvExpr) SetLeft(x Node) { n.X = x }
+func (n *ConvExpr) Left() Node { return n.X }
+func (n *ConvExpr) SetLeft(x Node) { n.X = x }
+func (n *ConvExpr) Implicit() bool { return n.flags&miniExprImplicit != 0 }
+func (n *ConvExpr) SetImplicit(b bool) { n.flags.set(miniExprImplicit, b) }
func (n *ConvExpr) SetOp(op Op) {
switch op {
@@ -583,8 +587,10 @@ func NewParenExpr(pos src.XPos, x Node) *ParenExpr {
return n
}
-func (n *ParenExpr) Left() Node { return n.X }
-func (n *ParenExpr) SetLeft(x Node) { n.X = x }
+func (n *ParenExpr) Left() Node { return n.X }
+func (n *ParenExpr) SetLeft(x Node) { n.X = x }
+func (n *ParenExpr) Implicit() bool { return n.flags&miniExprImplicit != 0 }
+func (n *ParenExpr) SetImplicit(b bool) { n.flags.set(miniExprImplicit, b) }
func (*ParenExpr) CanBeNtype() {}
@@ -645,6 +651,8 @@ func (n *SelectorExpr) Sym() *types.Sym { return n.Sel }
func (n *SelectorExpr) SetSym(x *types.Sym) { n.Sel = x }
func (n *SelectorExpr) Offset() int64 { return n.Offset_ }
func (n *SelectorExpr) SetOffset(x int64) { n.Offset_ = x }
+func (n *SelectorExpr) Implicit() bool { return n.flags&miniExprImplicit != 0 }
+func (n *SelectorExpr) SetImplicit(b bool) { n.flags.set(miniExprImplicit, b) }
// Before type-checking, bytes.Buffer is a SelectorExpr.
// After type-checking it becomes a Name.
@@ -783,8 +791,10 @@ func NewStarExpr(pos src.XPos, x Node) *StarExpr {
return n
}
-func (n *StarExpr) Left() Node { return n.X }
-func (n *StarExpr) SetLeft(x Node) { n.X = x }
+func (n *StarExpr) Left() Node { return n.X }
+func (n *StarExpr) SetLeft(x Node) { n.X = x }
+func (n *StarExpr) Implicit() bool { return n.flags&miniExprImplicit != 0 }
+func (n *StarExpr) SetImplicit(b bool) { n.flags.set(miniExprImplicit, b) }
func (*StarExpr) CanBeNtype() {}