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
return
}
- if n, ok := n.(*RawOrigExpr); ok {
- fmt.Fprint(s, n.Raw)
- return
- }
-
switch n.Op() {
case OPAREN:
n := n.(*ParenExpr)
}
}
-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
+++ /dev/null
-// 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]
- }
-}
// 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 {
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()
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
}
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]
}
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()
}
}
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"
)
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
}
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"
}
}
}
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"
}
}
}
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"
}
}
}
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"
}
}
}
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"
}
}
}
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"
}
}