mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
[dev.regabi] cmd/compile: eliminate more SetOrig
This CL consolidates and cleans up fmt.go's logic for skipping past Nodes introduced during typechecking. This allows eliminating SetOrig on ConvExpr and Name. Also changes ConstExpr.SetOrig to a panic for good measure. The only remaining SetOrig uses now are for rewriting multi-value "f(g())" calls and "return g()" statements, and type-checking composite literals. It should be possible to eliminate both of those as well. Passes buildall w/ toolstash -cmp. Change-Id: I478aea1a17dfb7a784293b930bf9081637eb2d7a Reviewed-on: https://go-review.googlesource.com/c/go/+/275179 Trust: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
This commit is contained in:
parent
351bc2f38c
commit
84cb51d7d7
4 changed files with 26 additions and 28 deletions
|
|
@ -523,7 +523,6 @@ func assignconvfn(n ir.Node, t *types.Type, context func() string) ir.Node {
|
||||||
r.SetType(t)
|
r.SetType(t)
|
||||||
r.SetTypecheck(1)
|
r.SetTypecheck(1)
|
||||||
r.SetImplicit(true)
|
r.SetImplicit(true)
|
||||||
r.(ir.OrigNode).SetOrig(ir.Orig(n))
|
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -321,7 +321,7 @@ func (n *ConstExpr) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
|
||||||
func (n *ConstExpr) rawCopy() Node { c := *n; return &c }
|
func (n *ConstExpr) rawCopy() Node { c := *n; return &c }
|
||||||
func (n *ConstExpr) Sym() *types.Sym { return n.orig.Sym() }
|
func (n *ConstExpr) Sym() *types.Sym { return n.orig.Sym() }
|
||||||
func (n *ConstExpr) Orig() Node { return n.orig }
|
func (n *ConstExpr) Orig() Node { return n.orig }
|
||||||
func (n *ConstExpr) SetOrig(orig Node) { n.orig = orig }
|
func (n *ConstExpr) SetOrig(orig Node) { panic(n.no("SetOrig")) }
|
||||||
func (n *ConstExpr) Val() constant.Value { return n.val }
|
func (n *ConstExpr) Val() constant.Value { return n.val }
|
||||||
|
|
||||||
// A ConvExpr is a conversion Type(X).
|
// A ConvExpr is a conversion Type(X).
|
||||||
|
|
@ -344,8 +344,6 @@ func NewConvExpr(pos src.XPos, op Op, typ *types.Type, x Node) *ConvExpr {
|
||||||
func (n *ConvExpr) String() string { return fmt.Sprint(n) }
|
func (n *ConvExpr) String() string { return fmt.Sprint(n) }
|
||||||
func (n *ConvExpr) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
|
func (n *ConvExpr) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
|
||||||
func (n *ConvExpr) rawCopy() Node { c := *n; return &c }
|
func (n *ConvExpr) rawCopy() Node { c := *n; return &c }
|
||||||
func (n *ConvExpr) Orig() Node { return n.orig }
|
|
||||||
func (n *ConvExpr) SetOrig(x Node) { n.orig = x }
|
|
||||||
func (n *ConvExpr) Left() Node { return n.X }
|
func (n *ConvExpr) Left() Node { return n.X }
|
||||||
func (n *ConvExpr) SetLeft(x Node) { n.X = x }
|
func (n *ConvExpr) SetLeft(x Node) { n.X = x }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1071,6 +1071,7 @@ var OpPrec = []int{
|
||||||
OCALL: 8,
|
OCALL: 8,
|
||||||
OCAP: 8,
|
OCAP: 8,
|
||||||
OCLOSE: 8,
|
OCLOSE: 8,
|
||||||
|
OCOMPLIT: 8,
|
||||||
OCONVIFACE: 8,
|
OCONVIFACE: 8,
|
||||||
OCONVNOP: 8,
|
OCONVNOP: 8,
|
||||||
OCONV: 8,
|
OCONV: 8,
|
||||||
|
|
@ -1179,15 +1180,30 @@ var OpPrec = []int{
|
||||||
}
|
}
|
||||||
|
|
||||||
func exprFmt(n Node, s fmt.State, prec int, mode FmtMode) {
|
func exprFmt(n Node, s fmt.State, prec int, mode FmtMode) {
|
||||||
for n != nil && n.Implicit() && (n.Op() == ODEREF || n.Op() == OADDR) {
|
for {
|
||||||
n = n.Left()
|
|
||||||
}
|
|
||||||
|
|
||||||
if n == nil {
|
if n == nil {
|
||||||
fmt.Fprint(s, "<N>")
|
fmt.Fprint(s, "<N>")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We always want the original, if any.
|
||||||
|
if o := Orig(n); o != n {
|
||||||
|
n = o
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Skip implicit operations introduced during typechecking.
|
||||||
|
switch n.Op() {
|
||||||
|
case OADDR, ODEREF, OCONV, OCONVNOP, OCONVIFACE:
|
||||||
|
if n.Implicit() {
|
||||||
|
n = n.Left()
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
nprec := OpPrec[n.Op()]
|
nprec := OpPrec[n.Op()]
|
||||||
if n.Op() == OTYPE && n.Sym() != nil {
|
if n.Op() == OTYPE && n.Sym() != nil {
|
||||||
nprec = 8
|
nprec = 8
|
||||||
|
|
@ -1206,16 +1222,10 @@ func exprFmt(n Node, s fmt.State, prec int, mode FmtMode) {
|
||||||
fmt.Fprint(s, "nil")
|
fmt.Fprint(s, "nil")
|
||||||
|
|
||||||
case OLITERAL: // this is a bit of a mess
|
case OLITERAL: // this is a bit of a mess
|
||||||
if mode == FErr {
|
if mode == FErr && n.Sym() != nil {
|
||||||
if orig := Orig(n); orig != nil && orig != n {
|
|
||||||
exprFmt(orig, s, prec, mode)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if n.Sym() != nil {
|
|
||||||
fmt.Fprint(s, smodeString(n.Sym(), mode))
|
fmt.Fprint(s, smodeString(n.Sym(), mode))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
needUnparen := false
|
needUnparen := false
|
||||||
if n.Type() != nil && !n.Type().IsUntyped() {
|
if n.Type() != nil && !n.Type().IsUntyped() {
|
||||||
|
|
@ -1558,13 +1568,6 @@ func exprFmt(n Node, s fmt.State, prec int, mode FmtMode) {
|
||||||
|
|
||||||
func nodeFmt(n Node, s fmt.State, flag FmtFlag, mode FmtMode) {
|
func nodeFmt(n Node, s fmt.State, flag FmtFlag, mode FmtMode) {
|
||||||
t := n.Type()
|
t := n.Type()
|
||||||
|
|
||||||
// We almost always want the original.
|
|
||||||
// TODO(gri) Why the special case for OLITERAL?
|
|
||||||
if n.Op() != OLITERAL && Orig(n) != nil {
|
|
||||||
n = Orig(n)
|
|
||||||
}
|
|
||||||
|
|
||||||
if flag&FmtLong != 0 && t != nil {
|
if flag&FmtLong != 0 && t != nil {
|
||||||
if t.Kind() == types.TNIL {
|
if t.Kind() == types.TNIL {
|
||||||
fmt.Fprint(s, "nil")
|
fmt.Fprint(s, "nil")
|
||||||
|
|
|
||||||
|
|
@ -155,8 +155,6 @@ func (n *Name) rawCopy() Node { c := *n; return &c }
|
||||||
func (n *Name) Name() *Name { return n }
|
func (n *Name) Name() *Name { return n }
|
||||||
func (n *Name) Sym() *types.Sym { return n.sym }
|
func (n *Name) Sym() *types.Sym { return n.sym }
|
||||||
func (n *Name) SetSym(x *types.Sym) { n.sym = x }
|
func (n *Name) SetSym(x *types.Sym) { n.sym = x }
|
||||||
func (n *Name) Orig() Node { return n.orig }
|
|
||||||
func (n *Name) SetOrig(x Node) { n.orig = x }
|
|
||||||
func (n *Name) SubOp() Op { return n.subOp }
|
func (n *Name) SubOp() Op { return n.subOp }
|
||||||
func (n *Name) SetSubOp(x Op) { n.subOp = x }
|
func (n *Name) SetSubOp(x Op) { n.subOp = x }
|
||||||
func (n *Name) Class() Class { return n.class }
|
func (n *Name) Class() Class { return n.class }
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue