]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: remove n.Diag() deadcode paths
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Fri, 18 Mar 2022 17:34:26 +0000 (00:34 +0700)
committerCuong Manh Le <cuong.manhle.vn@gmail.com>
Fri, 18 Mar 2022 23:20:51 +0000 (23:20 +0000)
CL 392918 changed n.Diag() to always return false, we can now get rid
of all its deadcode paths.

Updates #51691

Change-Id: I64c07970493e7bdcf89df9508ce88132ef4aa4d7
Reviewed-on: https://go-review.googlesource.com/c/go/+/393915
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/cmd/compile/internal/ir/expr.go
src/cmd/compile/internal/ir/mini.go
src/cmd/compile/internal/ir/node.go
src/cmd/compile/internal/typecheck/const.go
src/cmd/compile/internal/typecheck/expr.go
src/cmd/compile/internal/typecheck/func.go
src/cmd/compile/internal/typecheck/stmt.go
src/cmd/compile/internal/typecheck/subr.go
src/cmd/compile/internal/typecheck/typecheck.go

index ff3cc8ed6e7622fdc4ff280ca4b29c3830c35eb6..815e369ad83bc806e20faf79d919bf8f0cf9d591 100644 (file)
@@ -242,7 +242,6 @@ func NewConstExpr(val constant.Value, orig Node) Node {
        n.orig = orig
        n.SetType(orig.Type())
        n.SetTypecheck(orig.Typecheck())
-       n.SetDiag(orig.Diag())
        return n
 }
 
index cb05dfae26b2a18876095cd0aead2c90e2cc2ba5..7bc816356dafc97aee1e5742c01e949898f9079e 100644 (file)
@@ -67,7 +67,6 @@ func (n *miniNode) SetTypecheck(x uint8) {
        n.bits.set2(miniTypecheckShift, x)
 }
 
-func (n *miniNode) Diag() bool     { return false }
 func (n *miniNode) SetDiag(x bool) { base.AssertfAt(!x, n.Pos(), "SetDiag") }
 
 func (n *miniNode) Walked() bool     { return n.bits&miniWalked != 0 }
index d8c4022950547210142c550ff793a4df8ddacc9b..390af6aad21c3f340c90d58a893c3ffcfbacb5f7 100644 (file)
@@ -46,7 +46,6 @@ type Node interface {
        // Storage for analysis passes.
        Esc() uint16
        SetEsc(x uint16)
-       Diag() bool
        SetDiag(x bool)
 
        // Typecheck values:
index 311944361a0260f8ddb23613369a1e100c295943..79387dd7353053eaf312421eaa37505a081f18da 100644 (file)
@@ -198,16 +198,14 @@ func convlit1(n ir.Node, t *types.Type, explicit bool, context func() string) ir
                return n
        }
 
-       if !n.Diag() {
-               if explicit {
-                       base.Errorf("cannot convert %L to type %v", n, t)
-               } else if context != nil {
-                       base.Errorf("cannot use %L as type %v in %s", n, t, context())
-               } else {
-                       base.Errorf("cannot use %L as type %v", n, t)
-               }
-               n.SetDiag(true)
+       if explicit {
+               base.Errorf("cannot convert %L to type %v", n, t)
+       } else if context != nil {
+               base.Errorf("cannot use %L as type %v in %s", n, t, context())
+       } else {
+               base.Errorf("cannot use %L as type %v", n, t)
        }
+       n.SetDiag(true)
 
        n.SetType(nil)
        return n
index 7920a9a46c0b69b06629c3b60777f9b7dfbe043a..50271403415ec79777277cb9fa8325eb33e0fe78 100644 (file)
@@ -413,10 +413,8 @@ func tcConv(n *ir.ConvExpr) ir.Node {
        }
        op, why := Convertop(n.X.Op() == ir.OLITERAL, t, n.Type())
        if op == ir.OXXX {
-               if !n.Diag() && !n.X.Diag() {
-                       base.Errorf("cannot convert %L to type %v%s", n.X, n.Type(), why)
-                       n.SetDiag(true)
-               }
+               base.Errorf("cannot convert %L to type %v%s", n.X, n.Type(), why)
+               n.SetDiag(true)
                n.SetOp(ir.OCONV)
                n.SetType(nil)
                return n
index 0a0b5f5e780d2a1e0c6c41c81f54cb8d41d4a531..630a17b7f2b38003de295d41bbc420f5ba6e4451 100644 (file)
@@ -308,9 +308,6 @@ func tcFunc(n *ir.Func) {
 func tcCall(n *ir.CallExpr, top int) ir.Node {
        Stmts(n.Init()) // imported rewritten f(g()) calls (#30907)
        n.X = typecheck(n.X, ctxExpr|ctxType|ctxCallee)
-       if n.X.Diag() {
-               n.SetDiag(true)
-       }
 
        l := n.X
 
index 393481d4a9ed4bbd27ca202a1ed7acb6ab4442df..603b9819b1c35ed15a30f703b3423c4b676f35be 100644 (file)
@@ -313,12 +313,10 @@ func tcGoDefer(n *ir.GoDeferStmt) {
                return
        }
 
-       if !n.Diag() {
-               // The syntax made sure it was a call, so this must be
-               // a conversion.
-               n.SetDiag(true)
-               base.ErrorfAt(n.Pos(), "%s requires function call, not conversion", what)
-       }
+       // The syntax made sure it was a call, so this must be
+       // a conversion.
+       n.SetDiag(true)
+       base.ErrorfAt(n.Pos(), "%s requires function call, not conversion", what)
 }
 
 // tcIf typechecks an OIF node.
index 0b46037a3b6a66385ab49d082d28ed53dd545575..fdc6ba5929437201c13e163e15a45eac38fa3e7b 100644 (file)
@@ -135,9 +135,6 @@ func NodNil() ir.Node {
 // modifies the tree with missing field names.
 func AddImplicitDots(n *ir.SelectorExpr) *ir.SelectorExpr {
        n.X = typecheck(n.X, ctxType|ctxExpr)
-       if n.X.Diag() {
-               n.SetDiag(true)
-       }
        t := n.X.Type()
        if t == nil {
                return n
index 6860c71a7213583c150f75e1d5ece99b075ec7c2..ccf4183435fcd1b4b5601a18cd5219decc695e9b 100644 (file)
@@ -404,10 +404,8 @@ func typecheck(n ir.Node, top int) (res ir.Node) {
        // this code a bit, especially the final case.
        switch {
        case top&(ctxStmt|ctxExpr) == ctxExpr && !isExpr && n.Op() != ir.OTYPE && !isMulti:
-               if !n.Diag() {
-                       base.Errorf("%v used as value", n)
-                       n.SetDiag(true)
-               }
+               base.Errorf("%v used as value", n)
+               n.SetDiag(true)
                if t != nil {
                        n.SetType(nil)
                }
@@ -417,10 +415,8 @@ func typecheck(n ir.Node, top int) (res ir.Node) {
                n.SetDiag(true)
 
        case top&(ctxStmt|ctxExpr) == ctxStmt && !isStmt && t != nil:
-               if !n.Diag() {
-                       base.Errorf("%v evaluated but not used", n)
-                       n.SetDiag(true)
-               }
+               base.Errorf("%v evaluated but not used", n)
+               n.SetDiag(true)
                n.SetType(nil)
 
        case top&(ctxType|ctxExpr) == ctxType && n.Op() != ir.OTYPE && n.Op() != ir.ONONAME && (t != nil || n.Op() == ir.ONAME):
@@ -462,9 +458,7 @@ func typecheck1(n ir.Node, top int) ir.Node {
 
        case ir.OLITERAL:
                if n.Sym() == nil && n.Type() == nil {
-                       if !n.Diag() {
-                               base.Fatalf("literal missing type: %v", n)
-                       }
+                       base.Fatalf("literal missing type: %v", n)
                }
                return n
 
@@ -473,12 +467,10 @@ func typecheck1(n ir.Node, top int) ir.Node {
 
        // names
        case ir.ONONAME:
-               if !n.Diag() {
-                       // Note: adderrorname looks for this string and
-                       // adds context about the outer expression
-                       base.ErrorfAt(n.Pos(), "undefined: %v", n.Sym())
-                       n.SetDiag(true)
-               }
+               // Note: adderrorname looks for this string and
+               // adds context about the outer expression
+               base.ErrorfAt(n.Pos(), "undefined: %v", n.Sym())
+               n.SetDiag(true)
                n.SetType(nil)
                return n
 
@@ -813,9 +805,7 @@ func typecheck1(n ir.Node, top int) ir.Node {
        case ir.ODEFER, ir.OGO:
                n := n.(*ir.GoDeferStmt)
                n.Call = typecheck(n.Call, ctxStmt|ctxExpr)
-               if !n.Call.Diag() {
-                       tcGoDefer(n)
-               }
+               tcGoDefer(n)
                return n
 
        case ir.OFOR, ir.OFORUNTIL:
@@ -1383,7 +1373,7 @@ invalidddd:
        return
 
 notenough:
-       if n == nil || (!n.Diag() && n.Type() != nil) {
+       if n == nil || n.Type() != nil {
                details := errorDetails(nl, tstruct, isddd)
                if call != nil {
                        // call is the expression being called, not the overall call.
@@ -1546,14 +1536,12 @@ func typecheckarraylit(elemType *types.Type, bound int64, elts []ir.Node, ctx st
                        elt.Key = Expr(elt.Key)
                        key = IndexConst(elt.Key)
                        if key < 0 {
-                               if !elt.Key.Diag() {
-                                       if key == -2 {
-                                               base.Errorf("index too large")
-                                       } else {
-                                               base.Errorf("index must be non-negative integer constant")
-                                       }
-                                       elt.Key.SetDiag(true)
+                               if key == -2 {
+                                       base.Errorf("index too large")
+                               } else {
+                                       base.Errorf("index must be non-negative integer constant")
                                }
+                               elt.Key.SetDiag(true)
                                key = -(1 << 30) // stay negative for a while
                        }
                        kv = elt
@@ -1628,9 +1616,7 @@ func checkassign(stmt ir.Node, n ir.Node) {
        }
 
        defer n.SetType(nil)
-       if n.Diag() {
-               return
-       }
+
        switch {
        case n.Op() == ir.ODOT && n.(*ir.SelectorExpr).X.Op() == ir.OINDEXMAP:
                base.Errorf("cannot assign to struct field %v in map", n)