Skip to content

Commit e50bbae

Browse files
cuonglmgopherbot
authored andcommitted
cmd/compile: remove typecheck.Orig* functions
Same as CL 526397, but for typecheck. Change-Id: Ia8f19a54ffaa2ae3b86a4c66cbe6d973482796cd Reviewed-on: https://go-review.googlesource.com/c/go/+/526236 Auto-Submit: Cuong Manh Le <[email protected]> Reviewed-by: Matthew Dempsky <[email protected]> Reviewed-by: Cherry Mui <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent aa381c5 commit e50bbae

File tree

4 files changed

+8
-64
lines changed

4 files changed

+8
-64
lines changed

src/cmd/compile/internal/loopvar/loopvar.go

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -355,26 +355,17 @@ func ForCapture(fn *ir.Func) []VarAndLoop {
355355
})
356356

357357
postNotNil := x.Post != nil
358-
var tmpFirstDcl *ir.AssignStmt
358+
var tmpFirstDcl ir.Node
359359
if postNotNil {
360360
// body' = prebody +
361361
// (6) if tmp_first {tmp_first = false} else {Post} +
362362
// if !cond {break} + ...
363363
tmpFirst := typecheck.TempAt(base.Pos, fn, types.Types[types.TBOOL])
364-
365-
// tmpFirstAssign assigns val to tmpFirst
366-
tmpFirstAssign := func(val bool) *ir.AssignStmt {
367-
s := ir.NewAssignStmt(x.Pos(), tmpFirst, typecheck.OrigBool(tmpFirst, val))
368-
s.SetTypecheck(1)
369-
return s
370-
}
371-
372-
tmpFirstDcl = tmpFirstAssign(true)
373-
tmpFirstDcl.Def = true // also declares tmpFirst
374-
tmpFirstSetFalse := tmpFirstAssign(false)
364+
tmpFirstDcl = typecheck.Stmt(ir.NewAssignStmt(x.Pos(), tmpFirst, ir.NewBool(base.Pos, true)))
365+
tmpFirstSetFalse := typecheck.Stmt(ir.NewAssignStmt(x.Pos(), tmpFirst, ir.NewBool(base.Pos, false)))
375366
ifTmpFirst := ir.NewIfStmt(x.Pos(), tmpFirst, ir.Nodes{tmpFirstSetFalse}, ir.Nodes{x.Post})
376-
ifTmpFirst.SetTypecheck(1)
377-
preBody.Append(ifTmpFirst)
367+
ifTmpFirst.PtrInit().Append(typecheck.Stmt(ir.NewDecl(base.Pos, ir.ODCL, tmpFirst))) // declares tmpFirst
368+
preBody.Append(typecheck.Stmt(ifTmpFirst))
378369
}
379370

380371
// body' = prebody +

src/cmd/compile/internal/staticinit/sched.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,7 @@ func addStr(n *ir.AddStringExpr) ir.Node {
10331033
for _, c := range s {
10341034
strs = append(strs, ir.StringVal(c))
10351035
}
1036-
return typecheck.OrigConst(n, constant.MakeString(strings.Join(strs, "")))
1036+
return ir.NewConstExpr(constant.MakeString(strings.Join(strs, "")), n)
10371037
}
10381038
newList := make([]ir.Node, 0, need)
10391039
for i := 0; i < len(s); i++ {
@@ -1046,9 +1046,7 @@ func addStr(n *ir.AddStringExpr) ir.Node {
10461046
i2++
10471047
}
10481048

1049-
nl := ir.Copy(n).(*ir.AddStringExpr)
1050-
nl.List = s[i:i2]
1051-
newList = append(newList, typecheck.OrigConst(nl, constant.MakeString(strings.Join(strs, ""))))
1049+
newList = append(newList, ir.NewConstExpr(constant.MakeString(strings.Join(strs, "")), s[i]))
10521050
i = i2 - 1
10531051
} else {
10541052
newList = append(newList, s[i])

src/cmd/compile/internal/typecheck/const.go

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"fmt"
99
"go/constant"
1010
"go/token"
11-
"internal/types/errors"
1211
"math"
1312
"math/big"
1413
"unicode"
@@ -330,50 +329,6 @@ func makeComplex(real, imag constant.Value) constant.Value {
330329
return constant.BinaryOp(constant.ToFloat(real), token.ADD, constant.MakeImag(constant.ToFloat(imag)))
331330
}
332331

333-
// For matching historical "constant OP overflow" error messages.
334-
// TODO(mdempsky): Replace with error messages like go/types uses.
335-
var overflowNames = [...]string{
336-
ir.OADD: "addition",
337-
ir.OSUB: "subtraction",
338-
ir.OMUL: "multiplication",
339-
ir.OLSH: "shift",
340-
ir.OXOR: "bitwise XOR",
341-
ir.OBITNOT: "bitwise complement",
342-
}
343-
344-
// OrigConst returns an OLITERAL with orig n and value v.
345-
func OrigConst(n ir.Node, v constant.Value) ir.Node {
346-
lno := ir.SetPos(n)
347-
v = ConvertVal(v, n.Type(), false)
348-
base.Pos = lno
349-
350-
switch v.Kind() {
351-
case constant.Int:
352-
if constant.BitLen(v) <= ir.ConstPrec {
353-
break
354-
}
355-
fallthrough
356-
case constant.Unknown:
357-
what := overflowNames[n.Op()]
358-
if what == "" {
359-
base.Fatalf("unexpected overflow: %v", n.Op())
360-
}
361-
base.ErrorfAt(n.Pos(), errors.NumericOverflow, "constant %v overflow", what)
362-
n.SetType(nil)
363-
return n
364-
}
365-
366-
return ir.NewConstExpr(v, n)
367-
}
368-
369-
func OrigBool(n ir.Node, v bool) ir.Node {
370-
return OrigConst(n, constant.MakeBool(v))
371-
}
372-
373-
func OrigInt(n ir.Node, v int64) ir.Node {
374-
return OrigConst(n, constant.MakeInt64(v))
375-
}
376-
377332
// DefaultLit on both nodes simultaneously;
378333
// if they're both ideal going in they better
379334
// get the same type going out.

src/cmd/compile/internal/walk/builtin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ func walkLenCap(n *ir.UnaryExpr, init *ir.Nodes) ir.Node {
274274
}
275275
if t.IsArray() {
276276
safeExpr(n.X, init)
277-
con := typecheck.OrigInt(n, t.NumElem())
277+
con := ir.NewConstExpr(constant.MakeInt64(t.NumElem()), n)
278278
con.SetTypecheck(1)
279279
return con
280280
}

0 commit comments

Comments
 (0)