]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.regabi] cmd/compile: eliminate more SetOrig
authorMatthew Dempsky <mdempsky@google.com>
Thu, 3 Dec 2020 19:56:29 +0000 (11:56 -0800)
committerMatthew Dempsky <mdempsky@google.com>
Fri, 4 Dec 2020 01:20:58 +0000 (01:20 +0000)
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>
src/cmd/compile/internal/gc/subr.go
src/cmd/compile/internal/ir/expr.go
src/cmd/compile/internal/ir/fmt.go
src/cmd/compile/internal/ir/name.go

index 970f78b355ad36938af6470f81dec2f22c7932ff..65eb61e6800f5b6d316b54ee9e775bd3e1200adf 100644 (file)
@@ -523,7 +523,6 @@ func assignconvfn(n ir.Node, t *types.Type, context func() string) ir.Node {
        r.SetType(t)
        r.SetTypecheck(1)
        r.SetImplicit(true)
-       r.(ir.OrigNode).SetOrig(ir.Orig(n))
        return r
 }
 
index 18d85a01df8dfabee63c6b738e169015ecf060a8..49543f4286f1ec676c785960f1a5b4f7059d3edd 100644 (file)
@@ -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) Sym() *types.Sym               { return n.orig.Sym() }
 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 }
 
 // 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) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
 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) SetLeft(x Node)                { n.X = x }
 
index 45a66a2290925a554a5399334d06b9935be1e12f..bc5536241ea1d39d23393ab6971aa20c3f4c4ae6 100644 (file)
@@ -1071,6 +1071,7 @@ var OpPrec = []int{
        OCALL:          8,
        OCAP:           8,
        OCLOSE:         8,
+       OCOMPLIT:       8,
        OCONVIFACE:     8,
        OCONVNOP:       8,
        OCONV:          8,
@@ -1179,13 +1180,28 @@ var OpPrec = []int{
 }
 
 func exprFmt(n Node, s fmt.State, prec int, mode FmtMode) {
-       for n != nil && n.Implicit() && (n.Op() == ODEREF || n.Op() == OADDR) {
-               n = n.Left()
-       }
+       for {
+               if n == nil {
+                       fmt.Fprint(s, "<N>")
+                       return
+               }
 
-       if n == nil {
-               fmt.Fprint(s, "<N>")
-               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()]
@@ -1206,15 +1222,9 @@ func exprFmt(n Node, s fmt.State, prec int, mode FmtMode) {
                fmt.Fprint(s, "nil")
 
        case OLITERAL: // this is a bit of a mess
-               if mode == FErr {
-                       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))
-                               return
-                       }
+               if mode == FErr && n.Sym() != nil {
+                       fmt.Fprint(s, smodeString(n.Sym(), mode))
+                       return
                }
 
                needUnparen := false
@@ -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) {
        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 t.Kind() == types.TNIL {
                        fmt.Fprint(s, "nil")
index aeeb63d2d65fc093db7826c010ae96b71b44aee4..67d4d2b39112151aa280b5eb026db9eaa83141b2 100644 (file)
@@ -155,8 +155,6 @@ func (n *Name) rawCopy() Node                 { c := *n; return &c }
 func (n *Name) Name() *Name                   { return n }
 func (n *Name) Sym() *types.Sym               { return n.sym }
 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) SetSubOp(x Op)                 { n.subOp = x }
 func (n *Name) Class() Class                  { return n.class }