]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: remove typecheck.Orig* functions
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Tue, 12 Sep 2023 03:45:54 +0000 (10:45 +0700)
committerGopher Robot <gobot@golang.org>
Tue, 12 Sep 2023 16:07:23 +0000 (16:07 +0000)
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 <cuong.manhle.vn@gmail.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/cmd/compile/internal/loopvar/loopvar.go
src/cmd/compile/internal/staticinit/sched.go
src/cmd/compile/internal/typecheck/const.go
src/cmd/compile/internal/walk/builtin.go

index 7126d780b61247f4295b5c485cebf7522a16d739..ecf9401eeb16bf22a5535c358b14dcf3a2466eff 100644 (file)
@@ -355,26 +355,17 @@ func ForCapture(fn *ir.Func) []VarAndLoop {
                                        })
 
                                        postNotNil := x.Post != nil
-                                       var tmpFirstDcl *ir.AssignStmt
+                                       var tmpFirstDcl ir.Node
                                        if postNotNil {
                                                // body' = prebody +
                                                // (6)     if tmp_first {tmp_first = false} else {Post} +
                                                //         if !cond {break} + ...
                                                tmpFirst := typecheck.TempAt(base.Pos, fn, types.Types[types.TBOOL])
-
-                                               // tmpFirstAssign assigns val to tmpFirst
-                                               tmpFirstAssign := func(val bool) *ir.AssignStmt {
-                                                       s := ir.NewAssignStmt(x.Pos(), tmpFirst, typecheck.OrigBool(tmpFirst, val))
-                                                       s.SetTypecheck(1)
-                                                       return s
-                                               }
-
-                                               tmpFirstDcl = tmpFirstAssign(true)
-                                               tmpFirstDcl.Def = true // also declares tmpFirst
-                                               tmpFirstSetFalse := tmpFirstAssign(false)
+                                               tmpFirstDcl = typecheck.Stmt(ir.NewAssignStmt(x.Pos(), tmpFirst, ir.NewBool(base.Pos, true)))
+                                               tmpFirstSetFalse := typecheck.Stmt(ir.NewAssignStmt(x.Pos(), tmpFirst, ir.NewBool(base.Pos, false)))
                                                ifTmpFirst := ir.NewIfStmt(x.Pos(), tmpFirst, ir.Nodes{tmpFirstSetFalse}, ir.Nodes{x.Post})
-                                               ifTmpFirst.SetTypecheck(1)
-                                               preBody.Append(ifTmpFirst)
+                                               ifTmpFirst.PtrInit().Append(typecheck.Stmt(ir.NewDecl(base.Pos, ir.ODCL, tmpFirst))) // declares tmpFirst
+                                               preBody.Append(typecheck.Stmt(ifTmpFirst))
                                        }
 
                                        // body' = prebody +
index 4358ac678af3c4e7f4c1011e2aa300106c385a05..4191f6997ebcf47af0475bf7479271bb1fd2ace5 100644 (file)
@@ -1033,7 +1033,7 @@ func addStr(n *ir.AddStringExpr) ir.Node {
                for _, c := range s {
                        strs = append(strs, ir.StringVal(c))
                }
-               return typecheck.OrigConst(n, constant.MakeString(strings.Join(strs, "")))
+               return ir.NewConstExpr(constant.MakeString(strings.Join(strs, "")), n)
        }
        newList := make([]ir.Node, 0, need)
        for i := 0; i < len(s); i++ {
@@ -1046,9 +1046,7 @@ func addStr(n *ir.AddStringExpr) ir.Node {
                                i2++
                        }
 
-                       nl := ir.Copy(n).(*ir.AddStringExpr)
-                       nl.List = s[i:i2]
-                       newList = append(newList, typecheck.OrigConst(nl, constant.MakeString(strings.Join(strs, ""))))
+                       newList = append(newList, ir.NewConstExpr(constant.MakeString(strings.Join(strs, "")), s[i]))
                        i = i2 - 1
                } else {
                        newList = append(newList, s[i])
index 56a2072d290c53c0af36091c70a06f07cacc78ed..119cc37ad6bad974ac5f671e7db0a6496e1aaf0b 100644 (file)
@@ -8,7 +8,6 @@ import (
        "fmt"
        "go/constant"
        "go/token"
-       "internal/types/errors"
        "math"
        "math/big"
        "unicode"
@@ -330,50 +329,6 @@ func makeComplex(real, imag constant.Value) constant.Value {
        return constant.BinaryOp(constant.ToFloat(real), token.ADD, constant.MakeImag(constant.ToFloat(imag)))
 }
 
-// For matching historical "constant OP overflow" error messages.
-// TODO(mdempsky): Replace with error messages like go/types uses.
-var overflowNames = [...]string{
-       ir.OADD:    "addition",
-       ir.OSUB:    "subtraction",
-       ir.OMUL:    "multiplication",
-       ir.OLSH:    "shift",
-       ir.OXOR:    "bitwise XOR",
-       ir.OBITNOT: "bitwise complement",
-}
-
-// OrigConst returns an OLITERAL with orig n and value v.
-func OrigConst(n ir.Node, v constant.Value) ir.Node {
-       lno := ir.SetPos(n)
-       v = ConvertVal(v, n.Type(), false)
-       base.Pos = lno
-
-       switch v.Kind() {
-       case constant.Int:
-               if constant.BitLen(v) <= ir.ConstPrec {
-                       break
-               }
-               fallthrough
-       case constant.Unknown:
-               what := overflowNames[n.Op()]
-               if what == "" {
-                       base.Fatalf("unexpected overflow: %v", n.Op())
-               }
-               base.ErrorfAt(n.Pos(), errors.NumericOverflow, "constant %v overflow", what)
-               n.SetType(nil)
-               return n
-       }
-
-       return ir.NewConstExpr(v, n)
-}
-
-func OrigBool(n ir.Node, v bool) ir.Node {
-       return OrigConst(n, constant.MakeBool(v))
-}
-
-func OrigInt(n ir.Node, v int64) ir.Node {
-       return OrigConst(n, constant.MakeInt64(v))
-}
-
 // DefaultLit on both nodes simultaneously;
 // if they're both ideal going in they better
 // get the same type going out.
index 56dad14f21acf68b81ba465b2aa781a4a8c1acda..cb481f40eff6503d21f3b282e682a24891947d96 100644 (file)
@@ -274,7 +274,7 @@ func walkLenCap(n *ir.UnaryExpr, init *ir.Nodes) ir.Node {
        }
        if t.IsArray() {
                safeExpr(n.X, init)
-               con := typecheck.OrigInt(n, t.NumElem())
+               con := ir.NewConstExpr(constant.MakeInt64(t.NumElem()), n)
                con.SetTypecheck(1)
                return con
        }