]> Cypherpunks.ru repositories - gostls13.git/commitdiff
cmd/compile/internal/noder: stop preserving original const strings
authorMatthew Dempsky <mdempsky@google.com>
Wed, 6 Sep 2023 21:00:30 +0000 (14:00 -0700)
committerGopher Robot <gobot@golang.org>
Fri, 8 Sep 2023 18:50:24 +0000 (18:50 +0000)
One of the more tedious quirks of the original frontend (i.e.,
typecheck) to preserve was that it preserved the original
representation of constants into the backend. To fit into the unified
IR model, I ended up implementing a fairly heavyweight workaround:
simply record the original constant's string expression in the export
data, so that diagnostics could still report it back, and match the
old test expectations.

But now that there's just a single frontend to support, it's easy
enough to just update the test expectations and drop this support for
"raw" constant expressions.

Change-Id: I1d859c5109d679879d937a2b213e777fbddf4f2f
Reviewed-on: https://go-review.googlesource.com/c/go/+/526376
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
src/cmd/compile/internal/ir/expr.go
src/cmd/compile/internal/ir/fmt.go
src/cmd/compile/internal/ir/node_gen.go
src/cmd/compile/internal/noder/expr.go [deleted file]
src/cmd/compile/internal/noder/helpers.go
src/cmd/compile/internal/noder/reader.go
src/cmd/compile/internal/noder/writer.go
test/escape5.go
test/escape_reflect.go
test/escape_slice.go
test/fixedbugs/issue13799.go

index 852a139883da8eec537d125d74982eecd3f1bc6e..7204451364f0b2e4c4ba5cef64609bddaa243216 100644 (file)
@@ -498,20 +498,6 @@ func NewParenExpr(pos src.XPos, x Node) *ParenExpr {
 func (n *ParenExpr) Implicit() bool     { return n.flags&miniExprImplicit != 0 }
 func (n *ParenExpr) SetImplicit(b bool) { n.flags.set(miniExprImplicit, b) }
 
-// A RawOrigExpr represents an arbitrary Go expression as a string value.
-// When printed in diagnostics, the string value is written out exactly as-is.
-type RawOrigExpr struct {
-       miniExpr
-       Raw string
-}
-
-func NewRawOrigExpr(pos src.XPos, op Op, raw string) *RawOrigExpr {
-       n := &RawOrigExpr{Raw: raw}
-       n.pos = pos
-       n.op = op
-       return n
-}
-
 // A ResultExpr represents a direct access to a result.
 type ResultExpr struct {
        miniExpr
index c5d56d10f972413feb9289b937a6bc8b8a630910..841b6a2f4f429c9295a8a5e0088fbec8a815de2c 100644 (file)
@@ -567,11 +567,6 @@ func exprFmt(n Node, s fmt.State, prec int) {
                return
        }
 
-       if n, ok := n.(*RawOrigExpr); ok {
-               fmt.Fprint(s, n.Raw)
-               return
-       }
-
        switch n.Op() {
        case OPAREN:
                n := n.(*ParenExpr)
index cde7ab0ca8b5d00b43fce4d8a8243f61efc9b3cf..1274431b14a7e284376a8f36c4983df953e946f8 100644 (file)
@@ -1171,25 +1171,6 @@ func (n *RangeStmt) editChildrenWithHidden(edit func(Node) Node) {
        }
 }
 
-func (n *RawOrigExpr) Format(s fmt.State, verb rune) { fmtNode(n, s, verb) }
-func (n *RawOrigExpr) copy() Node {
-       c := *n
-       c.init = copyNodes(c.init)
-       return &c
-}
-func (n *RawOrigExpr) doChildren(do func(Node) bool) bool {
-       if doNodes(n.init, do) {
-               return true
-       }
-       return false
-}
-func (n *RawOrigExpr) editChildren(edit func(Node) Node) {
-       editNodes(n.init, edit)
-}
-func (n *RawOrigExpr) editChildrenWithHidden(edit func(Node) Node) {
-       editNodes(n.init, edit)
-}
-
 func (n *ResultExpr) Format(s fmt.State, verb rune) { fmtNode(n, s, verb) }
 func (n *ResultExpr) copy() Node {
        c := *n
diff --git a/src/cmd/compile/internal/noder/expr.go b/src/cmd/compile/internal/noder/expr.go
deleted file mode 100644 (file)
index 14ef3b9..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-// Copyright 2021 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package noder
-
-import (
-       "fmt"
-
-       "cmd/compile/internal/ir"
-       "cmd/compile/internal/syntax"
-)
-
-// constExprOp returns an ir.Op that represents the outermost
-// operation of the given constant expression. It's intended for use
-// with ir.RawOrigExpr.
-func constExprOp(expr syntax.Expr) ir.Op {
-       switch expr := expr.(type) {
-       default:
-               panic(fmt.Sprintf("%s: unexpected expression: %T", expr.Pos(), expr))
-
-       case *syntax.BasicLit:
-               return ir.OLITERAL
-       case *syntax.Name, *syntax.SelectorExpr:
-               return ir.ONAME
-       case *syntax.CallExpr:
-               return ir.OCALL
-       case *syntax.Operation:
-               if expr.Y == nil {
-                       return unOps[expr.Op]
-               }
-               return binOps[expr.Op]
-       }
-}
index 8aa93ef5dc6d0674fa393930a503be63f522bb4b..ae31f8600637e93f2892f44214e7dd8f313c8335 100644 (file)
@@ -40,11 +40,6 @@ func typed(typ *types.Type, n ir.Node) ir.Node {
 
 // Values
 
-func OrigConst(pos src.XPos, typ *types.Type, val constant.Value, op ir.Op, raw string) ir.Node {
-       orig := ir.NewRawOrigExpr(pos, op, raw)
-       return ir.NewConstExpr(val, typed(typ, orig))
-}
-
 // FixValue returns val after converting and truncating it as
 // appropriate for typ.
 func FixValue(typ *types.Type, val constant.Value) constant.Value {
index 26865fdae256f1aefee503ccdbe6ebb2827e611e..8e28260499465c24013fa9ad34724ac97187e9cd 100644 (file)
@@ -2172,9 +2172,7 @@ func (r *reader) expr() (res ir.Node) {
                pos := r.pos()
                typ := r.typ()
                val := FixValue(typ, r.Value())
-               op := r.op()
-               orig := r.String()
-               return typecheck.Expr(OrigConst(pos, typ, val, op, orig))
+               return typed(typ, ir.NewBasicLit(pos, val))
 
        case exprNil:
                pos := r.pos()
index 5982e714a3df6075a633944df01e372dbdc13474..044771609d49bc0824ecd9c72faf992aacf82387 100644 (file)
@@ -1748,11 +1748,6 @@ func (w *writer) expr(expr syntax.Expr) {
                        assert(typ != nil)
                        w.typ(typ)
                        w.Value(tv.Value)
-
-                       // TODO(mdempsky): These details are only important for backend
-                       // diagnostics. Explore writing them out separately.
-                       w.op(constExprOp(expr))
-                       w.String(syntax.String(expr))
                        return
                }
 
index 089130dad5c73e2163b7fbd3fa0c509ada81c319..133d973ba5d5f8290d7f2746f6a2c28918350a79 100644 (file)
@@ -151,7 +151,7 @@ func f9() {
 func f10() {
        // These don't escape but are too big for the stack
        var x [1 << 30]byte         // ERROR "moved to heap: x"
-       var y = make([]byte, 1<<30) // ERROR "make\(\[\]byte, 1 << 30\) escapes to heap"
+       var y = make([]byte, 1<<30) // ERROR "make\(\[\]byte, 1073741824\) escapes to heap"
        _ = x[0] + y[0]
 }
 
index b2d674a8a67a84a41a3237d56fa927b532c17bb5..99fbada9a98eb4641d151dc4059174f10173224b 100644 (file)
@@ -115,7 +115,7 @@ func is2(x [2]int) bool {
        return v.IsValid() || v.IsNil() || v.IsZero()
 }
 
-func is3(x struct { a, b int }) bool {
+func is3(x struct{ a, b int }) bool {
        v := reflect.ValueOf(x) // ERROR "x does not escape"
        return v.IsValid() || v.IsNil() || v.IsZero()
 }
@@ -352,9 +352,9 @@ func select2(ch chan string, x string) { // ERROR "leaking param: ch$" "leaking
 }
 
 var (
-       intTyp    = reflect.TypeOf(int(0))     // ERROR "int\(0\) does not escape"
+       intTyp    = reflect.TypeOf(int(0))     // ERROR "0 does not escape"
        uintTyp   = reflect.TypeOf(uint(0))    // ERROR "uint\(0\) does not escape"
-       stringTyp = reflect.TypeOf(string("")) // ERROR "string\(.*\) does not escape"
+       stringTyp = reflect.TypeOf(string("")) // ERROR ".. does not escape"
        bytesTyp  = reflect.TypeOf([]byte{})   // ERROR "\[\]byte{} does not escape"
 )
 
index 7f94a755b99efc5e02d6fbda84705aa1c793e7cf..65181e57d7edd34559f0eba3a7a46248c3ae7a47 100644 (file)
@@ -137,7 +137,7 @@ const (
 var v4InV6Prefix = []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff}
 
 func IPv4(a, b, c, d byte) IP {
-       p := make(IP, IPv6len) // ERROR "make\(IP, IPv6len\) escapes to heap"
+       p := make(IP, IPv6len) // ERROR "make\(IP, 16\) escapes to heap"
        copy(p, v4InV6Prefix)
        p[12] = a
        p[13] = b
index 7ab4040434ddcca073bfdc208328e6bb65ec0466..f06f19829e78ea551b5ec131db9ea48bfcece5b9 100644 (file)
@@ -61,7 +61,7 @@ func test1(iter int) {
        }
 
        if len(m) != maxI {
-               panic(fmt.Sprintf("iter %d: maxI = %d, len(m) = %d", iter, maxI, len(m))) // ERROR "iter escapes to heap$" "len\(m\) escapes to heap$" "maxI escapes to heap$" "... argument does not escape$" "fmt.Sprintf\(.*\) escapes to heap"
+               panic(fmt.Sprintf("iter %d: maxI = %d, len(m) = %d", iter, maxI, len(m))) // ERROR "iter escapes to heap$" "len\(m\) escapes to heap$" "500 escapes to heap$" "... argument does not escape$" "fmt.Sprintf\(.*\) escapes to heap"
        }
 }
 
@@ -85,7 +85,7 @@ func test2(iter int) {
        }
 
        if len(m) != maxI {
-               panic(fmt.Sprintf("iter %d: maxI = %d, len(m) = %d", iter, maxI, len(m))) // ERROR "iter escapes to heap$" "len\(m\) escapes to heap$" "maxI escapes to heap$" "... argument does not escape$" "fmt.Sprintf\(.*\) escapes to heap"
+               panic(fmt.Sprintf("iter %d: maxI = %d, len(m) = %d", iter, maxI, len(m))) // ERROR "iter escapes to heap$" "len\(m\) escapes to heap$" "500 escapes to heap$" "... argument does not escape$" "fmt.Sprintf\(.*\) escapes to heap"
        }
 }
 
@@ -111,7 +111,7 @@ func test3(iter int) {
        }
 
        if *m != maxI {
-               panic(fmt.Sprintf("iter %d: maxI = %d, *m = %d", iter, maxI, *m)) // ERROR "\*m escapes to heap$" "iter escapes to heap$" "maxI escapes to heap$" "... argument does not escape$" "fmt.Sprintf\(.*\) escapes to heap"
+               panic(fmt.Sprintf("iter %d: maxI = %d, *m = %d", iter, maxI, *m)) // ERROR "\*m escapes to heap$" "iter escapes to heap$" "500 escapes to heap$" "... argument does not escape$" "fmt.Sprintf\(.*\) escapes to heap"
        }
 }
 
@@ -137,7 +137,7 @@ func test4(iter int) {
        }
 
        if *m != maxI {
-               panic(fmt.Sprintf("iter %d: maxI = %d, *m = %d", iter, maxI, *m)) // ERROR "\*m escapes to heap$" "iter escapes to heap$" "maxI escapes to heap$" "... argument does not escape$" "fmt.Sprintf\(.*\) escapes to heap"
+               panic(fmt.Sprintf("iter %d: maxI = %d, *m = %d", iter, maxI, *m)) // ERROR "\*m escapes to heap$" "iter escapes to heap$" "500 escapes to heap$" "... argument does not escape$" "fmt.Sprintf\(.*\) escapes to heap"
        }
 }
 
@@ -168,7 +168,7 @@ func test5(iter int) {
        }
 
        if *m != maxI {
-               panic(fmt.Sprintf("iter %d: maxI = %d, *m = %d", iter, maxI, *m)) // ERROR "\*m escapes to heap$" "iter escapes to heap$" "maxI escapes to heap$" "... argument does not escape$" "fmt.Sprintf\(.*\) escapes to heap"
+               panic(fmt.Sprintf("iter %d: maxI = %d, *m = %d", iter, maxI, *m)) // ERROR "\*m escapes to heap$" "iter escapes to heap$" "500 escapes to heap$" "... argument does not escape$" "fmt.Sprintf\(.*\) escapes to heap"
        }
 }
 
@@ -186,6 +186,6 @@ func test6(iter int) {
        }
 
        if *m != maxI {
-               panic(fmt.Sprintf("iter %d: maxI = %d, *m = %d", iter, maxI, *m)) // ERROR "\*m escapes to heap$" "iter escapes to heap$" "maxI escapes to heap$" "... argument does not escape$" "fmt.Sprintf\(.*\) escapes to heap"
+               panic(fmt.Sprintf("iter %d: maxI = %d, *m = %d", iter, maxI, *m)) // ERROR "\*m escapes to heap$" "iter escapes to heap$" "500 escapes to heap$" "... argument does not escape$" "fmt.Sprintf\(.*\) escapes to heap"
        }
 }