1
0
mirror of https://github.com/golang/go synced 2024-11-11 18:51:37 -07:00

cmd/compile: remove n.Diag() deadcode paths

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>
This commit is contained in:
Cuong Manh Le 2022-03-19 00:34:26 +07:00
parent da9649e6d9
commit 7ca6902c17
9 changed files with 30 additions and 59 deletions

View 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
}

View 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 }

View File

@ -46,7 +46,6 @@ type Node interface {
// Storage for analysis passes.
Esc() uint16
SetEsc(x uint16)
Diag() bool
SetDiag(x bool)
// Typecheck values:

View File

@ -198,7 +198,6 @@ 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 {
@ -207,7 +206,6 @@ func convlit1(n ir.Node, t *types.Type, explicit bool, context func() string) ir
base.Errorf("cannot use %L as type %v", n, t)
}
n.SetDiag(true)
}
n.SetType(nil)
return n

View 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)
}
n.SetOp(ir.OCONV)
n.SetType(nil)
return n

View 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

View 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)
}
}
// tcIf typechecks an OIF node.

View 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

View 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)
}
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)
}
n.SetType(nil)
case top&(ctxType|ctxExpr) == ctxType && n.Op() != ir.OTYPE && n.Op() != ir.ONONAME && (t != nil || n.Op() == ir.ONAME):
@ -462,10 +458,8 @@ 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)
}
}
return n
case ir.ONIL:
@ -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)
}
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)
}
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)
}
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)