[dev.regabi] cmd/compile: minor walkExpr cleanups

This CL cleans up a few minor points in walkExpr:

1. We don't actually care about computing the type-size of all
expressions that are walked. We care about computing the type-size of
all expressions that are *returned* by walk, as these are the
expressions that will actually be seen by the back end.

2. There's no need to call typecheck.EvalConst anymore. EvalConst used
to be responsible for doing additional constant folding during walk;
but for a while a now, it has done only as much constant folding as is
required during type checking (because doing further constant folding
led to too many issues with Go spec compliance). Instead, more
aggressive constant folding is handled entirely by SSA.

3. The code for detecting string constants and generating their
symbols can be simplified somewhat.

Passes toolstash -cmp.

Change-Id: I464ef5bceb8a97689c8f55435369a3402a5ebc55
Reviewed-on: https://go-review.googlesource.com/c/go/+/280434
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
This commit is contained in:
Matthew Dempsky 2020-12-26 19:30:12 -08:00
parent 0de8eafd98
commit 0f732f8c91

View file

@ -26,15 +26,6 @@ func walkExpr(n ir.Node, init *ir.Nodes) ir.Node {
return n
}
// Eagerly checkwidth all expressions for the back end.
if n.Type() != nil && !n.Type().WidthCalculated() {
switch n.Type().Kind() {
case types.TBLANK, types.TNIL, types.TIDEAL:
default:
types.CheckSize(n.Type())
}
}
if init == n.PtrInit() {
// not okay to use n->ninit when walking n,
// because we might replace n with some other node
@ -70,23 +61,14 @@ func walkExpr(n ir.Node, init *ir.Nodes) ir.Node {
n = walkExpr1(n, init)
// Expressions that are constant at run time but not
// considered const by the language spec are not turned into
// constants until walk. For example, if n is y%1 == 0, the
// walk of y%1 may have replaced it by 0.
// Check whether n with its updated args is itself now a constant.
t := n.Type()
n = typecheck.EvalConst(n)
if n.Type() != t {
base.Fatalf("evconst changed Type: %v had type %v, now %v", n, t, n.Type())
// Eagerly compute sizes of all expressions for the back end.
if typ := n.Type(); typ != nil && typ.Kind() != types.TBLANK && !typ.IsFuncArgStruct() {
types.CheckSize(typ)
}
if n.Op() == ir.OLITERAL {
n = typecheck.Expr(n)
if ir.IsConst(n, constant.String) {
// Emit string symbol now to avoid emitting
// any concurrently during the backend.
if v := n.Val(); v.Kind() == constant.String {
_ = staticdata.StringSym(n.Pos(), constant.StringVal(v))
}
_ = staticdata.StringSym(n.Pos(), constant.StringVal(n.Val()))
}
updateHasCall(n)