From 0f732f8c91aa4550ce1803906a55de51760e3243 Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Sat, 26 Dec 2020 19:30:12 -0800 Subject: [PATCH] [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 Run-TryBot: Matthew Dempsky TryBot-Result: Go Bot Reviewed-by: Cuong Manh Le --- src/cmd/compile/internal/walk/expr.go | 30 ++++++--------------------- 1 file changed, 6 insertions(+), 24 deletions(-) diff --git a/src/cmd/compile/internal/walk/expr.go b/src/cmd/compile/internal/walk/expr.go index f0d9e7c2a1..53bffee181 100644 --- a/src/cmd/compile/internal/walk/expr.go +++ b/src/cmd/compile/internal/walk/expr.go @@ -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()) - } - if n.Op() == ir.OLITERAL { - n = typecheck.Expr(n) + // 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 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) -- 2.48.1