2015-02-13 14:40:36 -05:00
|
|
|
// Copyright 2009 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 gc
|
|
|
|
|
|
2016-12-06 17:08:06 -08:00
|
|
|
import (
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
"cmd/compile/internal/types"
|
cmd/compile: fix misleading "truncated to int" messages
When defining an int const, the compiler tries to cast the RHS
expression to int. The cast may fail for three reasons:
1. expr is an integer constant that overflows int
2. expr is a floating point constant
3. expr is a complex constant, or not a number
In the second case, in order to print a sensible error message, we
must distinguish between a floating point constant that should be
included in the error message and a floating point constant that
cannot be reasonably formatted for inclusion in an error message.
For example, in:
const a int = 1.1
const b int = 1 + 1e-100
a is in the former group, while b is in the latter, since the floating
point value resulting from the evaluation of the rhs of the assignment
(1.00...01) is too long to be fully printed in an error message, and
cannot be shortened without making the error message misleading
(rounding or truncating it would result in a "1", which looks like an
integer constant, and it makes little sense in an error message about
an invalid floating point expression).
To fix this problem, we try to format the float value using fconv
(which is used by the error reporting mechanism to format float
arguments), and then parse the resulting string back to a
big.Float. If the result is an integer, we assume that expr is a float
value that cannot be reasonably be formatted as a string, and we emit
an error message that does not include its string representation.
Also, change the error message for overflows to a more conservative
"integer too large", which does not mention overflows that are only
caused by an internal implementation restriction.
Also, change (*Mpint) SetFloat so that it returns a bool (instead of
0/-1 for success/failure).
Fixes #11371
Change-Id: Ibbc73e2ed2eaf41f07827b0649d0eb637150ecaa
Reviewed-on: https://go-review.googlesource.com/35411
Run-TryBot: Alberto Donizetti <alb.donizetti@gmail.com>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2017-01-18 11:48:14 +01:00
|
|
|
"math/big"
|
2016-12-06 17:08:06 -08:00
|
|
|
"strings"
|
|
|
|
|
)
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2016-04-05 14:20:04 -07:00
|
|
|
// Ctype describes the constant kind of an "ideal" (untyped) constant.
|
2017-10-10 17:36:03 +01:00
|
|
|
type Ctype uint8
|
2016-04-05 14:20:04 -07:00
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
CTxxx Ctype = iota
|
|
|
|
|
|
|
|
|
|
CTINT
|
|
|
|
|
CTRUNE
|
|
|
|
|
CTFLT
|
|
|
|
|
CTCPLX
|
|
|
|
|
CTSTR
|
|
|
|
|
CTBOOL
|
|
|
|
|
CTNIL
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type Val struct {
|
|
|
|
|
// U contains one of:
|
|
|
|
|
// bool bool when n.ValCtype() == CTBOOL
|
|
|
|
|
// *Mpint int when n.ValCtype() == CTINT, rune when n.ValCtype() == CTRUNE
|
|
|
|
|
// *Mpflt float when n.ValCtype() == CTFLT
|
|
|
|
|
// *Mpcplx pair of floats when n.ValCtype() == CTCPLX
|
|
|
|
|
// string string when n.ValCtype() == CTSTR
|
|
|
|
|
// *Nilval when n.ValCtype() == CTNIL
|
|
|
|
|
U interface{}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (v Val) Ctype() Ctype {
|
|
|
|
|
switch x := v.U.(type) {
|
|
|
|
|
default:
|
|
|
|
|
Fatalf("unexpected Ctype for %T", v.U)
|
|
|
|
|
panic("not reached")
|
|
|
|
|
case nil:
|
|
|
|
|
return 0
|
|
|
|
|
case *NilVal:
|
|
|
|
|
return CTNIL
|
|
|
|
|
case bool:
|
|
|
|
|
return CTBOOL
|
|
|
|
|
case *Mpint:
|
|
|
|
|
if x.Rune {
|
|
|
|
|
return CTRUNE
|
|
|
|
|
}
|
|
|
|
|
return CTINT
|
|
|
|
|
case *Mpflt:
|
|
|
|
|
return CTFLT
|
|
|
|
|
case *Mpcplx:
|
|
|
|
|
return CTCPLX
|
|
|
|
|
case string:
|
|
|
|
|
return CTSTR
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-01 10:58:30 -07:00
|
|
|
func eqval(a, b Val) bool {
|
|
|
|
|
if a.Ctype() != b.Ctype() {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
switch x := a.U.(type) {
|
|
|
|
|
default:
|
|
|
|
|
Fatalf("unexpected Ctype for %T", a.U)
|
|
|
|
|
panic("not reached")
|
|
|
|
|
case *NilVal:
|
|
|
|
|
return true
|
|
|
|
|
case bool:
|
|
|
|
|
y := b.U.(bool)
|
|
|
|
|
return x == y
|
|
|
|
|
case *Mpint:
|
|
|
|
|
y := b.U.(*Mpint)
|
|
|
|
|
return x.Cmp(y) == 0
|
|
|
|
|
case *Mpflt:
|
|
|
|
|
y := b.U.(*Mpflt)
|
|
|
|
|
return x.Cmp(y) == 0
|
|
|
|
|
case *Mpcplx:
|
|
|
|
|
y := b.U.(*Mpcplx)
|
|
|
|
|
return x.Real.Cmp(&y.Real) == 0 && x.Imag.Cmp(&y.Imag) == 0
|
|
|
|
|
case string:
|
|
|
|
|
y := b.U.(string)
|
|
|
|
|
return x == y
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-05 17:28:28 -07:00
|
|
|
// Interface returns the constant value stored in v as an interface{}.
|
|
|
|
|
// It returns int64s for ints and runes, float64s for floats,
|
|
|
|
|
// complex128s for complex values, and nil for constant nils.
|
|
|
|
|
func (v Val) Interface() interface{} {
|
|
|
|
|
switch x := v.U.(type) {
|
|
|
|
|
default:
|
|
|
|
|
Fatalf("unexpected Interface for %T", v.U)
|
|
|
|
|
panic("not reached")
|
|
|
|
|
case *NilVal:
|
|
|
|
|
return nil
|
|
|
|
|
case bool, string:
|
|
|
|
|
return x
|
|
|
|
|
case *Mpint:
|
|
|
|
|
return x.Int64()
|
|
|
|
|
case *Mpflt:
|
|
|
|
|
return x.Float64()
|
|
|
|
|
case *Mpcplx:
|
|
|
|
|
return complex(x.Real.Float64(), x.Imag.Float64())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-05 14:20:04 -07:00
|
|
|
type NilVal struct{}
|
|
|
|
|
|
2016-04-01 14:51:02 -07:00
|
|
|
// Int64 returns n as an int64.
|
|
|
|
|
// n must be an integer or rune constant.
|
|
|
|
|
func (n *Node) Int64() int64 {
|
2015-04-22 20:08:03 -07:00
|
|
|
if !Isconst(n, CTINT) {
|
2017-02-26 15:25:57 -08:00
|
|
|
Fatalf("Int64(%v)", n)
|
2015-04-22 20:08:03 -07:00
|
|
|
}
|
2016-03-20 13:55:42 -07:00
|
|
|
return n.Val().U.(*Mpint).Int64()
|
2015-04-22 20:08:03 -07:00
|
|
|
}
|
|
|
|
|
|
2018-08-22 14:01:22 +02:00
|
|
|
// CanInt64 reports whether it is safe to call Int64() on n.
|
|
|
|
|
func (n *Node) CanInt64() bool {
|
|
|
|
|
if !Isconst(n, CTINT) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if the value inside n cannot be represented as an int64, the
|
|
|
|
|
// return value of Int64 is undefined
|
|
|
|
|
return n.Val().U.(*Mpint).CmpInt64(n.Int64()) == 0
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-26 15:25:57 -08:00
|
|
|
// Bool returns n as a bool.
|
|
|
|
|
// n must be a boolean constant.
|
|
|
|
|
func (n *Node) Bool() bool {
|
|
|
|
|
if !Isconst(n, CTBOOL) {
|
|
|
|
|
Fatalf("Bool(%v)", n)
|
|
|
|
|
}
|
|
|
|
|
return n.Val().U.(bool)
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-22 09:51:12 +09:00
|
|
|
// truncate float literal fv to 32-bit or 64-bit precision
|
|
|
|
|
// according to type; return truncated value.
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
func truncfltlit(oldv *Mpflt, t *types.Type) *Mpflt {
|
2015-02-13 14:40:36 -05:00
|
|
|
if t == nil {
|
|
|
|
|
return oldv
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-12 20:57:13 +02:00
|
|
|
if overflow(Val{oldv}, t) {
|
|
|
|
|
// If there was overflow, simply continuing would set the
|
|
|
|
|
// value to Inf which in turn would lead to spurious follow-on
|
|
|
|
|
// errors. Avoid this by returning the existing value.
|
|
|
|
|
return oldv
|
|
|
|
|
}
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2015-03-20 16:59:08 -07:00
|
|
|
fv := newMpflt()
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
// convert large precision literal floating
|
|
|
|
|
// into limited precision (float64 or float32)
|
|
|
|
|
switch t.Etype {
|
2017-04-12 20:57:13 +02:00
|
|
|
case types.TFLOAT32:
|
|
|
|
|
fv.SetFloat64(oldv.Float32())
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
case types.TFLOAT64:
|
2017-04-12 20:57:13 +02:00
|
|
|
fv.SetFloat64(oldv.Float64())
|
|
|
|
|
default:
|
|
|
|
|
Fatalf("truncfltlit: unexpected Etype %v", t.Etype)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return fv
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-07 11:54:29 +01:00
|
|
|
// truncate Real and Imag parts of Mpcplx to 32-bit or 64-bit
|
|
|
|
|
// precision, according to type; return truncated value. In case of
|
|
|
|
|
// overflow, calls yyerror but does not truncate the input value.
|
|
|
|
|
func trunccmplxlit(oldv *Mpcplx, t *types.Type) *Mpcplx {
|
|
|
|
|
if t == nil {
|
|
|
|
|
return oldv
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if overflow(Val{oldv}, t) {
|
2017-04-12 20:57:13 +02:00
|
|
|
// If there was overflow, simply continuing would set the
|
|
|
|
|
// value to Inf which in turn would lead to spurious follow-on
|
|
|
|
|
// errors. Avoid this by returning the existing value.
|
2017-03-07 11:54:29 +01:00
|
|
|
return oldv
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cv := newMpcmplx()
|
|
|
|
|
|
|
|
|
|
switch t.Etype {
|
2017-04-12 20:57:13 +02:00
|
|
|
case types.TCOMPLEX64:
|
2017-03-07 11:54:29 +01:00
|
|
|
cv.Real.SetFloat64(oldv.Real.Float32())
|
|
|
|
|
cv.Imag.SetFloat64(oldv.Imag.Float32())
|
2017-04-12 20:57:13 +02:00
|
|
|
case types.TCOMPLEX128:
|
2017-03-07 11:54:29 +01:00
|
|
|
cv.Real.SetFloat64(oldv.Real.Float64())
|
|
|
|
|
cv.Imag.SetFloat64(oldv.Imag.Float64())
|
|
|
|
|
default:
|
|
|
|
|
Fatalf("trunccplxlit: unexpected Etype %v", t.Etype)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return cv
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-17 12:24:11 -07:00
|
|
|
// canReuseNode indicates whether it is known to be safe
|
|
|
|
|
// to reuse a Node.
|
|
|
|
|
type canReuseNode bool
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
noReuse canReuseNode = false // not necessarily safe to reuse
|
|
|
|
|
reuseOK canReuseNode = true // safe to reuse
|
|
|
|
|
)
|
|
|
|
|
|
2015-10-22 09:51:12 +09:00
|
|
|
// convert n, if literal, to type t.
|
|
|
|
|
// implicit conversion.
|
cmd/compile: reduce use of **Node parameters
Escape analysis has a hard time with tree-like
structures (see #13493 and #14858).
This is unlikely to change.
As a result, when invoking a function that accepts
a **Node parameter, we usually allocate a *Node
on the heap. This happens a whole lot.
This CL changes functions from taking a **Node
to acting more like append: It both modifies
the input and returns a replacement for it.
Because of the cascading nature of escape analysis,
in order to get the benefits, I had to modify
almost all such functions. The remaining functions
are in racewalk and the backend. I would be happy
to update them as well in a separate CL.
This CL was created by manually updating the
function signatures and the directly impacted
bits of code. The callsites were then automatically
updated using a bespoke script:
https://gist.github.com/josharian/046b1be7aceae244de39
For ease of reviewing and future understanding,
this CL is also broken down into four CLs,
mailed separately, which show the manual
and the automated changes separately.
They are CLs 20990, 20991, 20992, and 20993.
Passes toolstash -cmp.
name old time/op new time/op delta
Template 335ms ± 5% 324ms ± 5% -3.35% (p=0.000 n=23+24)
Unicode 176ms ± 9% 165ms ± 6% -6.12% (p=0.000 n=23+24)
GoTypes 1.10s ± 4% 1.07s ± 2% -2.77% (p=0.000 n=24+24)
Compiler 5.31s ± 3% 5.15s ± 3% -2.95% (p=0.000 n=24+24)
MakeBash 41.6s ± 1% 41.7s ± 2% ~ (p=0.586 n=23+23)
name old alloc/op new alloc/op delta
Template 63.3MB ± 0% 62.4MB ± 0% -1.36% (p=0.000 n=25+23)
Unicode 42.4MB ± 0% 41.6MB ± 0% -1.99% (p=0.000 n=24+25)
GoTypes 220MB ± 0% 217MB ± 0% -1.11% (p=0.000 n=25+25)
Compiler 994MB ± 0% 973MB ± 0% -2.08% (p=0.000 n=24+25)
name old allocs/op new allocs/op delta
Template 681k ± 0% 574k ± 0% -15.71% (p=0.000 n=24+25)
Unicode 518k ± 0% 413k ± 0% -20.34% (p=0.000 n=25+24)
GoTypes 2.08M ± 0% 1.78M ± 0% -14.62% (p=0.000 n=25+25)
Compiler 9.26M ± 0% 7.64M ± 0% -17.48% (p=0.000 n=25+25)
name old text-bytes new text-bytes delta
HelloSize 578k ± 0% 578k ± 0% ~ (all samples are equal)
CmdGoSize 6.46M ± 0% 6.46M ± 0% ~ (all samples are equal)
name old data-bytes new data-bytes delta
HelloSize 128k ± 0% 128k ± 0% ~ (all samples are equal)
CmdGoSize 281k ± 0% 281k ± 0% ~ (all samples are equal)
name old exe-bytes new exe-bytes delta
HelloSize 921k ± 0% 921k ± 0% ~ (all samples are equal)
CmdGoSize 9.86M ± 0% 9.86M ± 0% ~ (all samples are equal)
Change-Id: I277d95bd56d51c166ef7f560647aeaa092f3f475
Reviewed-on: https://go-review.googlesource.com/20959
Reviewed-by: Dave Cheney <dave@cheney.net>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-03-20 08:03:31 -07:00
|
|
|
// The result of convlit MUST be assigned back to n, e.g.
|
|
|
|
|
// n.Left = convlit(n.Left, t)
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
func convlit(n *Node, t *types.Type) *Node {
|
2016-03-17 12:24:11 -07:00
|
|
|
return convlit1(n, t, false, noReuse)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2016-03-17 12:24:11 -07:00
|
|
|
// convlit1 converts n, if literal, to type t.
|
|
|
|
|
// It returns a new node if necessary.
|
cmd/compile: reduce use of **Node parameters
Escape analysis has a hard time with tree-like
structures (see #13493 and #14858).
This is unlikely to change.
As a result, when invoking a function that accepts
a **Node parameter, we usually allocate a *Node
on the heap. This happens a whole lot.
This CL changes functions from taking a **Node
to acting more like append: It both modifies
the input and returns a replacement for it.
Because of the cascading nature of escape analysis,
in order to get the benefits, I had to modify
almost all such functions. The remaining functions
are in racewalk and the backend. I would be happy
to update them as well in a separate CL.
This CL was created by manually updating the
function signatures and the directly impacted
bits of code. The callsites were then automatically
updated using a bespoke script:
https://gist.github.com/josharian/046b1be7aceae244de39
For ease of reviewing and future understanding,
this CL is also broken down into four CLs,
mailed separately, which show the manual
and the automated changes separately.
They are CLs 20990, 20991, 20992, and 20993.
Passes toolstash -cmp.
name old time/op new time/op delta
Template 335ms ± 5% 324ms ± 5% -3.35% (p=0.000 n=23+24)
Unicode 176ms ± 9% 165ms ± 6% -6.12% (p=0.000 n=23+24)
GoTypes 1.10s ± 4% 1.07s ± 2% -2.77% (p=0.000 n=24+24)
Compiler 5.31s ± 3% 5.15s ± 3% -2.95% (p=0.000 n=24+24)
MakeBash 41.6s ± 1% 41.7s ± 2% ~ (p=0.586 n=23+23)
name old alloc/op new alloc/op delta
Template 63.3MB ± 0% 62.4MB ± 0% -1.36% (p=0.000 n=25+23)
Unicode 42.4MB ± 0% 41.6MB ± 0% -1.99% (p=0.000 n=24+25)
GoTypes 220MB ± 0% 217MB ± 0% -1.11% (p=0.000 n=25+25)
Compiler 994MB ± 0% 973MB ± 0% -2.08% (p=0.000 n=24+25)
name old allocs/op new allocs/op delta
Template 681k ± 0% 574k ± 0% -15.71% (p=0.000 n=24+25)
Unicode 518k ± 0% 413k ± 0% -20.34% (p=0.000 n=25+24)
GoTypes 2.08M ± 0% 1.78M ± 0% -14.62% (p=0.000 n=25+25)
Compiler 9.26M ± 0% 7.64M ± 0% -17.48% (p=0.000 n=25+25)
name old text-bytes new text-bytes delta
HelloSize 578k ± 0% 578k ± 0% ~ (all samples are equal)
CmdGoSize 6.46M ± 0% 6.46M ± 0% ~ (all samples are equal)
name old data-bytes new data-bytes delta
HelloSize 128k ± 0% 128k ± 0% ~ (all samples are equal)
CmdGoSize 281k ± 0% 281k ± 0% ~ (all samples are equal)
name old exe-bytes new exe-bytes delta
HelloSize 921k ± 0% 921k ± 0% ~ (all samples are equal)
CmdGoSize 9.86M ± 0% 9.86M ± 0% ~ (all samples are equal)
Change-Id: I277d95bd56d51c166ef7f560647aeaa092f3f475
Reviewed-on: https://go-review.googlesource.com/20959
Reviewed-by: Dave Cheney <dave@cheney.net>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-03-20 08:03:31 -07:00
|
|
|
// The result of convlit1 MUST be assigned back to n, e.g.
|
2016-03-17 12:24:11 -07:00
|
|
|
// n.Left = convlit1(n.Left, t, explicit, reuse)
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
func convlit1(n *Node, t *types.Type, explicit bool, reuse canReuseNode) *Node {
|
2016-04-01 13:36:24 -07:00
|
|
|
if n == nil || t == nil || n.Type == nil || t.IsUntyped() || n.Type == t {
|
cmd/compile: reduce use of **Node parameters
Escape analysis has a hard time with tree-like
structures (see #13493 and #14858).
This is unlikely to change.
As a result, when invoking a function that accepts
a **Node parameter, we usually allocate a *Node
on the heap. This happens a whole lot.
This CL changes functions from taking a **Node
to acting more like append: It both modifies
the input and returns a replacement for it.
Because of the cascading nature of escape analysis,
in order to get the benefits, I had to modify
almost all such functions. The remaining functions
are in racewalk and the backend. I would be happy
to update them as well in a separate CL.
This CL was created by manually updating the
function signatures and the directly impacted
bits of code. The callsites were then automatically
updated using a bespoke script:
https://gist.github.com/josharian/046b1be7aceae244de39
For ease of reviewing and future understanding,
this CL is also broken down into four CLs,
mailed separately, which show the manual
and the automated changes separately.
They are CLs 20990, 20991, 20992, and 20993.
Passes toolstash -cmp.
name old time/op new time/op delta
Template 335ms ± 5% 324ms ± 5% -3.35% (p=0.000 n=23+24)
Unicode 176ms ± 9% 165ms ± 6% -6.12% (p=0.000 n=23+24)
GoTypes 1.10s ± 4% 1.07s ± 2% -2.77% (p=0.000 n=24+24)
Compiler 5.31s ± 3% 5.15s ± 3% -2.95% (p=0.000 n=24+24)
MakeBash 41.6s ± 1% 41.7s ± 2% ~ (p=0.586 n=23+23)
name old alloc/op new alloc/op delta
Template 63.3MB ± 0% 62.4MB ± 0% -1.36% (p=0.000 n=25+23)
Unicode 42.4MB ± 0% 41.6MB ± 0% -1.99% (p=0.000 n=24+25)
GoTypes 220MB ± 0% 217MB ± 0% -1.11% (p=0.000 n=25+25)
Compiler 994MB ± 0% 973MB ± 0% -2.08% (p=0.000 n=24+25)
name old allocs/op new allocs/op delta
Template 681k ± 0% 574k ± 0% -15.71% (p=0.000 n=24+25)
Unicode 518k ± 0% 413k ± 0% -20.34% (p=0.000 n=25+24)
GoTypes 2.08M ± 0% 1.78M ± 0% -14.62% (p=0.000 n=25+25)
Compiler 9.26M ± 0% 7.64M ± 0% -17.48% (p=0.000 n=25+25)
name old text-bytes new text-bytes delta
HelloSize 578k ± 0% 578k ± 0% ~ (all samples are equal)
CmdGoSize 6.46M ± 0% 6.46M ± 0% ~ (all samples are equal)
name old data-bytes new data-bytes delta
HelloSize 128k ± 0% 128k ± 0% ~ (all samples are equal)
CmdGoSize 281k ± 0% 281k ± 0% ~ (all samples are equal)
name old exe-bytes new exe-bytes delta
HelloSize 921k ± 0% 921k ± 0% ~ (all samples are equal)
CmdGoSize 9.86M ± 0% 9.86M ± 0% ~ (all samples are equal)
Change-Id: I277d95bd56d51c166ef7f560647aeaa092f3f475
Reviewed-on: https://go-review.googlesource.com/20959
Reviewed-by: Dave Cheney <dave@cheney.net>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-03-20 08:03:31 -07:00
|
|
|
return n
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
2016-04-01 13:36:24 -07:00
|
|
|
if !explicit && !n.Type.IsUntyped() {
|
cmd/compile: reduce use of **Node parameters
Escape analysis has a hard time with tree-like
structures (see #13493 and #14858).
This is unlikely to change.
As a result, when invoking a function that accepts
a **Node parameter, we usually allocate a *Node
on the heap. This happens a whole lot.
This CL changes functions from taking a **Node
to acting more like append: It both modifies
the input and returns a replacement for it.
Because of the cascading nature of escape analysis,
in order to get the benefits, I had to modify
almost all such functions. The remaining functions
are in racewalk and the backend. I would be happy
to update them as well in a separate CL.
This CL was created by manually updating the
function signatures and the directly impacted
bits of code. The callsites were then automatically
updated using a bespoke script:
https://gist.github.com/josharian/046b1be7aceae244de39
For ease of reviewing and future understanding,
this CL is also broken down into four CLs,
mailed separately, which show the manual
and the automated changes separately.
They are CLs 20990, 20991, 20992, and 20993.
Passes toolstash -cmp.
name old time/op new time/op delta
Template 335ms ± 5% 324ms ± 5% -3.35% (p=0.000 n=23+24)
Unicode 176ms ± 9% 165ms ± 6% -6.12% (p=0.000 n=23+24)
GoTypes 1.10s ± 4% 1.07s ± 2% -2.77% (p=0.000 n=24+24)
Compiler 5.31s ± 3% 5.15s ± 3% -2.95% (p=0.000 n=24+24)
MakeBash 41.6s ± 1% 41.7s ± 2% ~ (p=0.586 n=23+23)
name old alloc/op new alloc/op delta
Template 63.3MB ± 0% 62.4MB ± 0% -1.36% (p=0.000 n=25+23)
Unicode 42.4MB ± 0% 41.6MB ± 0% -1.99% (p=0.000 n=24+25)
GoTypes 220MB ± 0% 217MB ± 0% -1.11% (p=0.000 n=25+25)
Compiler 994MB ± 0% 973MB ± 0% -2.08% (p=0.000 n=24+25)
name old allocs/op new allocs/op delta
Template 681k ± 0% 574k ± 0% -15.71% (p=0.000 n=24+25)
Unicode 518k ± 0% 413k ± 0% -20.34% (p=0.000 n=25+24)
GoTypes 2.08M ± 0% 1.78M ± 0% -14.62% (p=0.000 n=25+25)
Compiler 9.26M ± 0% 7.64M ± 0% -17.48% (p=0.000 n=25+25)
name old text-bytes new text-bytes delta
HelloSize 578k ± 0% 578k ± 0% ~ (all samples are equal)
CmdGoSize 6.46M ± 0% 6.46M ± 0% ~ (all samples are equal)
name old data-bytes new data-bytes delta
HelloSize 128k ± 0% 128k ± 0% ~ (all samples are equal)
CmdGoSize 281k ± 0% 281k ± 0% ~ (all samples are equal)
name old exe-bytes new exe-bytes delta
HelloSize 921k ± 0% 921k ± 0% ~ (all samples are equal)
CmdGoSize 9.86M ± 0% 9.86M ± 0% ~ (all samples are equal)
Change-Id: I277d95bd56d51c166ef7f560647aeaa092f3f475
Reviewed-on: https://go-review.googlesource.com/20959
Reviewed-by: Dave Cheney <dave@cheney.net>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-03-20 08:03:31 -07:00
|
|
|
return n
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2016-03-17 12:24:11 -07:00
|
|
|
if n.Op == OLITERAL && !reuse {
|
|
|
|
|
// Can't always set n.Type directly on OLITERAL nodes.
|
|
|
|
|
// See discussion on CL 20813.
|
2018-09-20 15:22:33 -07:00
|
|
|
n = n.rawcopy()
|
2016-03-17 12:24:11 -07:00
|
|
|
reuse = true
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch n.Op {
|
|
|
|
|
default:
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
if n.Type == types.Idealbool {
|
2018-02-14 14:08:17 -08:00
|
|
|
if !t.IsBoolean() {
|
|
|
|
|
t = types.Types[TBOOL]
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
2018-02-14 14:08:17 -08:00
|
|
|
switch n.Op {
|
|
|
|
|
case ONOT:
|
|
|
|
|
n.Left = convlit(n.Left, t)
|
|
|
|
|
case OANDAND, OOROR:
|
|
|
|
|
n.Left = convlit(n.Left, t)
|
|
|
|
|
n.Right = convlit(n.Right, t)
|
|
|
|
|
}
|
|
|
|
|
n.Type = t
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2018-06-27 15:38:29 -07:00
|
|
|
if n.Type.IsUntyped() {
|
|
|
|
|
if t.IsInterface() {
|
|
|
|
|
n.Left, n.Right = defaultlit2(n.Left, n.Right, true)
|
|
|
|
|
n.Type = n.Left.Type // same as n.Right.Type per defaultlit2
|
|
|
|
|
} else {
|
|
|
|
|
n.Left = convlit(n.Left, t)
|
|
|
|
|
n.Right = convlit(n.Right, t)
|
|
|
|
|
n.Type = t
|
|
|
|
|
}
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
cmd/compile: reduce use of **Node parameters
Escape analysis has a hard time with tree-like
structures (see #13493 and #14858).
This is unlikely to change.
As a result, when invoking a function that accepts
a **Node parameter, we usually allocate a *Node
on the heap. This happens a whole lot.
This CL changes functions from taking a **Node
to acting more like append: It both modifies
the input and returns a replacement for it.
Because of the cascading nature of escape analysis,
in order to get the benefits, I had to modify
almost all such functions. The remaining functions
are in racewalk and the backend. I would be happy
to update them as well in a separate CL.
This CL was created by manually updating the
function signatures and the directly impacted
bits of code. The callsites were then automatically
updated using a bespoke script:
https://gist.github.com/josharian/046b1be7aceae244de39
For ease of reviewing and future understanding,
this CL is also broken down into four CLs,
mailed separately, which show the manual
and the automated changes separately.
They are CLs 20990, 20991, 20992, and 20993.
Passes toolstash -cmp.
name old time/op new time/op delta
Template 335ms ± 5% 324ms ± 5% -3.35% (p=0.000 n=23+24)
Unicode 176ms ± 9% 165ms ± 6% -6.12% (p=0.000 n=23+24)
GoTypes 1.10s ± 4% 1.07s ± 2% -2.77% (p=0.000 n=24+24)
Compiler 5.31s ± 3% 5.15s ± 3% -2.95% (p=0.000 n=24+24)
MakeBash 41.6s ± 1% 41.7s ± 2% ~ (p=0.586 n=23+23)
name old alloc/op new alloc/op delta
Template 63.3MB ± 0% 62.4MB ± 0% -1.36% (p=0.000 n=25+23)
Unicode 42.4MB ± 0% 41.6MB ± 0% -1.99% (p=0.000 n=24+25)
GoTypes 220MB ± 0% 217MB ± 0% -1.11% (p=0.000 n=25+25)
Compiler 994MB ± 0% 973MB ± 0% -2.08% (p=0.000 n=24+25)
name old allocs/op new allocs/op delta
Template 681k ± 0% 574k ± 0% -15.71% (p=0.000 n=24+25)
Unicode 518k ± 0% 413k ± 0% -20.34% (p=0.000 n=25+24)
GoTypes 2.08M ± 0% 1.78M ± 0% -14.62% (p=0.000 n=25+25)
Compiler 9.26M ± 0% 7.64M ± 0% -17.48% (p=0.000 n=25+25)
name old text-bytes new text-bytes delta
HelloSize 578k ± 0% 578k ± 0% ~ (all samples are equal)
CmdGoSize 6.46M ± 0% 6.46M ± 0% ~ (all samples are equal)
name old data-bytes new data-bytes delta
HelloSize 128k ± 0% 128k ± 0% ~ (all samples are equal)
CmdGoSize 281k ± 0% 281k ± 0% ~ (all samples are equal)
name old exe-bytes new exe-bytes delta
HelloSize 921k ± 0% 921k ± 0% ~ (all samples are equal)
CmdGoSize 9.86M ± 0% 9.86M ± 0% ~ (all samples are equal)
Change-Id: I277d95bd56d51c166ef7f560647aeaa092f3f475
Reviewed-on: https://go-review.googlesource.com/20959
Reviewed-by: Dave Cheney <dave@cheney.net>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-03-20 08:03:31 -07:00
|
|
|
return n
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2018-06-27 15:38:29 -07:00
|
|
|
// target is invalid type for a constant? leave alone.
|
2015-02-13 14:40:36 -05:00
|
|
|
case OLITERAL:
|
2015-03-01 07:54:01 +00:00
|
|
|
if !okforconst[t.Etype] && n.Type.Etype != TNIL {
|
2016-03-17 12:24:11 -07:00
|
|
|
return defaultlitreuse(n, nil, reuse)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2015-04-01 09:38:44 -07:00
|
|
|
case OLSH, ORSH:
|
2016-04-01 13:36:24 -07:00
|
|
|
n.Left = convlit1(n.Left, t, explicit && n.Left.Type.IsUntyped(), noReuse)
|
2015-02-13 14:40:36 -05:00
|
|
|
t = n.Left.Type
|
2015-05-27 00:47:05 -04:00
|
|
|
if t != nil && t.Etype == TIDEAL && n.Val().Ctype() != CTINT {
|
|
|
|
|
n.SetVal(toint(n.Val()))
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
2016-03-30 15:09:25 -07:00
|
|
|
if t != nil && !t.IsInteger() {
|
2016-09-15 15:45:10 +10:00
|
|
|
yyerror("invalid operation: %v (shift of type %v)", n, t)
|
2015-02-13 14:40:36 -05:00
|
|
|
t = nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
n.Type = t
|
cmd/compile: reduce use of **Node parameters
Escape analysis has a hard time with tree-like
structures (see #13493 and #14858).
This is unlikely to change.
As a result, when invoking a function that accepts
a **Node parameter, we usually allocate a *Node
on the heap. This happens a whole lot.
This CL changes functions from taking a **Node
to acting more like append: It both modifies
the input and returns a replacement for it.
Because of the cascading nature of escape analysis,
in order to get the benefits, I had to modify
almost all such functions. The remaining functions
are in racewalk and the backend. I would be happy
to update them as well in a separate CL.
This CL was created by manually updating the
function signatures and the directly impacted
bits of code. The callsites were then automatically
updated using a bespoke script:
https://gist.github.com/josharian/046b1be7aceae244de39
For ease of reviewing and future understanding,
this CL is also broken down into four CLs,
mailed separately, which show the manual
and the automated changes separately.
They are CLs 20990, 20991, 20992, and 20993.
Passes toolstash -cmp.
name old time/op new time/op delta
Template 335ms ± 5% 324ms ± 5% -3.35% (p=0.000 n=23+24)
Unicode 176ms ± 9% 165ms ± 6% -6.12% (p=0.000 n=23+24)
GoTypes 1.10s ± 4% 1.07s ± 2% -2.77% (p=0.000 n=24+24)
Compiler 5.31s ± 3% 5.15s ± 3% -2.95% (p=0.000 n=24+24)
MakeBash 41.6s ± 1% 41.7s ± 2% ~ (p=0.586 n=23+23)
name old alloc/op new alloc/op delta
Template 63.3MB ± 0% 62.4MB ± 0% -1.36% (p=0.000 n=25+23)
Unicode 42.4MB ± 0% 41.6MB ± 0% -1.99% (p=0.000 n=24+25)
GoTypes 220MB ± 0% 217MB ± 0% -1.11% (p=0.000 n=25+25)
Compiler 994MB ± 0% 973MB ± 0% -2.08% (p=0.000 n=24+25)
name old allocs/op new allocs/op delta
Template 681k ± 0% 574k ± 0% -15.71% (p=0.000 n=24+25)
Unicode 518k ± 0% 413k ± 0% -20.34% (p=0.000 n=25+24)
GoTypes 2.08M ± 0% 1.78M ± 0% -14.62% (p=0.000 n=25+25)
Compiler 9.26M ± 0% 7.64M ± 0% -17.48% (p=0.000 n=25+25)
name old text-bytes new text-bytes delta
HelloSize 578k ± 0% 578k ± 0% ~ (all samples are equal)
CmdGoSize 6.46M ± 0% 6.46M ± 0% ~ (all samples are equal)
name old data-bytes new data-bytes delta
HelloSize 128k ± 0% 128k ± 0% ~ (all samples are equal)
CmdGoSize 281k ± 0% 281k ± 0% ~ (all samples are equal)
name old exe-bytes new exe-bytes delta
HelloSize 921k ± 0% 921k ± 0% ~ (all samples are equal)
CmdGoSize 9.86M ± 0% 9.86M ± 0% ~ (all samples are equal)
Change-Id: I277d95bd56d51c166ef7f560647aeaa092f3f475
Reviewed-on: https://go-review.googlesource.com/20959
Reviewed-by: Dave Cheney <dave@cheney.net>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-03-20 08:03:31 -07:00
|
|
|
return n
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
case OCOMPLEX:
|
|
|
|
|
if n.Type.Etype == TIDEAL {
|
|
|
|
|
switch t.Etype {
|
|
|
|
|
default:
|
2016-04-22 15:45:24 -07:00
|
|
|
// If trying to convert to non-complex type,
|
|
|
|
|
// leave as complex128 and let typechecker complain.
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
t = types.Types[TCOMPLEX128]
|
2015-02-13 14:40:36 -05:00
|
|
|
fallthrough
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
case types.TCOMPLEX128:
|
2015-02-13 14:40:36 -05:00
|
|
|
n.Type = t
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
n.Left = convlit(n.Left, types.Types[TFLOAT64])
|
|
|
|
|
n.Right = convlit(n.Right, types.Types[TFLOAT64])
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
case TCOMPLEX64:
|
|
|
|
|
n.Type = t
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
n.Left = convlit(n.Left, types.Types[TFLOAT32])
|
|
|
|
|
n.Right = convlit(n.Right, types.Types[TFLOAT32])
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
cmd/compile: reduce use of **Node parameters
Escape analysis has a hard time with tree-like
structures (see #13493 and #14858).
This is unlikely to change.
As a result, when invoking a function that accepts
a **Node parameter, we usually allocate a *Node
on the heap. This happens a whole lot.
This CL changes functions from taking a **Node
to acting more like append: It both modifies
the input and returns a replacement for it.
Because of the cascading nature of escape analysis,
in order to get the benefits, I had to modify
almost all such functions. The remaining functions
are in racewalk and the backend. I would be happy
to update them as well in a separate CL.
This CL was created by manually updating the
function signatures and the directly impacted
bits of code. The callsites were then automatically
updated using a bespoke script:
https://gist.github.com/josharian/046b1be7aceae244de39
For ease of reviewing and future understanding,
this CL is also broken down into four CLs,
mailed separately, which show the manual
and the automated changes separately.
They are CLs 20990, 20991, 20992, and 20993.
Passes toolstash -cmp.
name old time/op new time/op delta
Template 335ms ± 5% 324ms ± 5% -3.35% (p=0.000 n=23+24)
Unicode 176ms ± 9% 165ms ± 6% -6.12% (p=0.000 n=23+24)
GoTypes 1.10s ± 4% 1.07s ± 2% -2.77% (p=0.000 n=24+24)
Compiler 5.31s ± 3% 5.15s ± 3% -2.95% (p=0.000 n=24+24)
MakeBash 41.6s ± 1% 41.7s ± 2% ~ (p=0.586 n=23+23)
name old alloc/op new alloc/op delta
Template 63.3MB ± 0% 62.4MB ± 0% -1.36% (p=0.000 n=25+23)
Unicode 42.4MB ± 0% 41.6MB ± 0% -1.99% (p=0.000 n=24+25)
GoTypes 220MB ± 0% 217MB ± 0% -1.11% (p=0.000 n=25+25)
Compiler 994MB ± 0% 973MB ± 0% -2.08% (p=0.000 n=24+25)
name old allocs/op new allocs/op delta
Template 681k ± 0% 574k ± 0% -15.71% (p=0.000 n=24+25)
Unicode 518k ± 0% 413k ± 0% -20.34% (p=0.000 n=25+24)
GoTypes 2.08M ± 0% 1.78M ± 0% -14.62% (p=0.000 n=25+25)
Compiler 9.26M ± 0% 7.64M ± 0% -17.48% (p=0.000 n=25+25)
name old text-bytes new text-bytes delta
HelloSize 578k ± 0% 578k ± 0% ~ (all samples are equal)
CmdGoSize 6.46M ± 0% 6.46M ± 0% ~ (all samples are equal)
name old data-bytes new data-bytes delta
HelloSize 128k ± 0% 128k ± 0% ~ (all samples are equal)
CmdGoSize 281k ± 0% 281k ± 0% ~ (all samples are equal)
name old exe-bytes new exe-bytes delta
HelloSize 921k ± 0% 921k ± 0% ~ (all samples are equal)
CmdGoSize 9.86M ± 0% 9.86M ± 0% ~ (all samples are equal)
Change-Id: I277d95bd56d51c166ef7f560647aeaa092f3f475
Reviewed-on: https://go-review.googlesource.com/20959
Reviewed-by: Dave Cheney <dave@cheney.net>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-03-20 08:03:31 -07:00
|
|
|
return n
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2018-06-27 15:38:29 -07:00
|
|
|
// avoid repeated calculations, errors
|
2016-09-15 14:34:20 +10:00
|
|
|
if eqtype(n.Type, t) {
|
cmd/compile: reduce use of **Node parameters
Escape analysis has a hard time with tree-like
structures (see #13493 and #14858).
This is unlikely to change.
As a result, when invoking a function that accepts
a **Node parameter, we usually allocate a *Node
on the heap. This happens a whole lot.
This CL changes functions from taking a **Node
to acting more like append: It both modifies
the input and returns a replacement for it.
Because of the cascading nature of escape analysis,
in order to get the benefits, I had to modify
almost all such functions. The remaining functions
are in racewalk and the backend. I would be happy
to update them as well in a separate CL.
This CL was created by manually updating the
function signatures and the directly impacted
bits of code. The callsites were then automatically
updated using a bespoke script:
https://gist.github.com/josharian/046b1be7aceae244de39
For ease of reviewing and future understanding,
this CL is also broken down into four CLs,
mailed separately, which show the manual
and the automated changes separately.
They are CLs 20990, 20991, 20992, and 20993.
Passes toolstash -cmp.
name old time/op new time/op delta
Template 335ms ± 5% 324ms ± 5% -3.35% (p=0.000 n=23+24)
Unicode 176ms ± 9% 165ms ± 6% -6.12% (p=0.000 n=23+24)
GoTypes 1.10s ± 4% 1.07s ± 2% -2.77% (p=0.000 n=24+24)
Compiler 5.31s ± 3% 5.15s ± 3% -2.95% (p=0.000 n=24+24)
MakeBash 41.6s ± 1% 41.7s ± 2% ~ (p=0.586 n=23+23)
name old alloc/op new alloc/op delta
Template 63.3MB ± 0% 62.4MB ± 0% -1.36% (p=0.000 n=25+23)
Unicode 42.4MB ± 0% 41.6MB ± 0% -1.99% (p=0.000 n=24+25)
GoTypes 220MB ± 0% 217MB ± 0% -1.11% (p=0.000 n=25+25)
Compiler 994MB ± 0% 973MB ± 0% -2.08% (p=0.000 n=24+25)
name old allocs/op new allocs/op delta
Template 681k ± 0% 574k ± 0% -15.71% (p=0.000 n=24+25)
Unicode 518k ± 0% 413k ± 0% -20.34% (p=0.000 n=25+24)
GoTypes 2.08M ± 0% 1.78M ± 0% -14.62% (p=0.000 n=25+25)
Compiler 9.26M ± 0% 7.64M ± 0% -17.48% (p=0.000 n=25+25)
name old text-bytes new text-bytes delta
HelloSize 578k ± 0% 578k ± 0% ~ (all samples are equal)
CmdGoSize 6.46M ± 0% 6.46M ± 0% ~ (all samples are equal)
name old data-bytes new data-bytes delta
HelloSize 128k ± 0% 128k ± 0% ~ (all samples are equal)
CmdGoSize 281k ± 0% 281k ± 0% ~ (all samples are equal)
name old exe-bytes new exe-bytes delta
HelloSize 921k ± 0% 921k ± 0% ~ (all samples are equal)
CmdGoSize 9.86M ± 0% 9.86M ± 0% ~ (all samples are equal)
Change-Id: I277d95bd56d51c166ef7f560647aeaa092f3f475
Reviewed-on: https://go-review.googlesource.com/20959
Reviewed-by: Dave Cheney <dave@cheney.net>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-03-20 08:03:31 -07:00
|
|
|
return n
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2015-02-23 16:07:24 -05:00
|
|
|
ct := consttype(n)
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
var et types.EType
|
2017-10-10 17:36:03 +01:00
|
|
|
if ct == 0 {
|
2015-02-13 14:40:36 -05:00
|
|
|
goto bad
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-29 20:07:09 -08:00
|
|
|
et = t.Etype
|
2015-02-13 14:40:36 -05:00
|
|
|
if et == TINTER {
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
if ct == CTNIL && n.Type == types.Types[TNIL] {
|
2015-02-13 14:40:36 -05:00
|
|
|
n.Type = t
|
cmd/compile: reduce use of **Node parameters
Escape analysis has a hard time with tree-like
structures (see #13493 and #14858).
This is unlikely to change.
As a result, when invoking a function that accepts
a **Node parameter, we usually allocate a *Node
on the heap. This happens a whole lot.
This CL changes functions from taking a **Node
to acting more like append: It both modifies
the input and returns a replacement for it.
Because of the cascading nature of escape analysis,
in order to get the benefits, I had to modify
almost all such functions. The remaining functions
are in racewalk and the backend. I would be happy
to update them as well in a separate CL.
This CL was created by manually updating the
function signatures and the directly impacted
bits of code. The callsites were then automatically
updated using a bespoke script:
https://gist.github.com/josharian/046b1be7aceae244de39
For ease of reviewing and future understanding,
this CL is also broken down into four CLs,
mailed separately, which show the manual
and the automated changes separately.
They are CLs 20990, 20991, 20992, and 20993.
Passes toolstash -cmp.
name old time/op new time/op delta
Template 335ms ± 5% 324ms ± 5% -3.35% (p=0.000 n=23+24)
Unicode 176ms ± 9% 165ms ± 6% -6.12% (p=0.000 n=23+24)
GoTypes 1.10s ± 4% 1.07s ± 2% -2.77% (p=0.000 n=24+24)
Compiler 5.31s ± 3% 5.15s ± 3% -2.95% (p=0.000 n=24+24)
MakeBash 41.6s ± 1% 41.7s ± 2% ~ (p=0.586 n=23+23)
name old alloc/op new alloc/op delta
Template 63.3MB ± 0% 62.4MB ± 0% -1.36% (p=0.000 n=25+23)
Unicode 42.4MB ± 0% 41.6MB ± 0% -1.99% (p=0.000 n=24+25)
GoTypes 220MB ± 0% 217MB ± 0% -1.11% (p=0.000 n=25+25)
Compiler 994MB ± 0% 973MB ± 0% -2.08% (p=0.000 n=24+25)
name old allocs/op new allocs/op delta
Template 681k ± 0% 574k ± 0% -15.71% (p=0.000 n=24+25)
Unicode 518k ± 0% 413k ± 0% -20.34% (p=0.000 n=25+24)
GoTypes 2.08M ± 0% 1.78M ± 0% -14.62% (p=0.000 n=25+25)
Compiler 9.26M ± 0% 7.64M ± 0% -17.48% (p=0.000 n=25+25)
name old text-bytes new text-bytes delta
HelloSize 578k ± 0% 578k ± 0% ~ (all samples are equal)
CmdGoSize 6.46M ± 0% 6.46M ± 0% ~ (all samples are equal)
name old data-bytes new data-bytes delta
HelloSize 128k ± 0% 128k ± 0% ~ (all samples are equal)
CmdGoSize 281k ± 0% 281k ± 0% ~ (all samples are equal)
name old exe-bytes new exe-bytes delta
HelloSize 921k ± 0% 921k ± 0% ~ (all samples are equal)
CmdGoSize 9.86M ± 0% 9.86M ± 0% ~ (all samples are equal)
Change-Id: I277d95bd56d51c166ef7f560647aeaa092f3f475
Reviewed-on: https://go-review.googlesource.com/20959
Reviewed-by: Dave Cheney <dave@cheney.net>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-03-20 08:03:31 -07:00
|
|
|
return n
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
2016-03-17 12:24:11 -07:00
|
|
|
return defaultlitreuse(n, nil, reuse)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch ct {
|
|
|
|
|
default:
|
|
|
|
|
goto bad
|
|
|
|
|
|
|
|
|
|
case CTNIL:
|
|
|
|
|
switch et {
|
|
|
|
|
default:
|
|
|
|
|
n.Type = nil
|
|
|
|
|
goto bad
|
|
|
|
|
|
|
|
|
|
// let normal conversion code handle it
|
|
|
|
|
case TSTRING:
|
cmd/compile: reduce use of **Node parameters
Escape analysis has a hard time with tree-like
structures (see #13493 and #14858).
This is unlikely to change.
As a result, when invoking a function that accepts
a **Node parameter, we usually allocate a *Node
on the heap. This happens a whole lot.
This CL changes functions from taking a **Node
to acting more like append: It both modifies
the input and returns a replacement for it.
Because of the cascading nature of escape analysis,
in order to get the benefits, I had to modify
almost all such functions. The remaining functions
are in racewalk and the backend. I would be happy
to update them as well in a separate CL.
This CL was created by manually updating the
function signatures and the directly impacted
bits of code. The callsites were then automatically
updated using a bespoke script:
https://gist.github.com/josharian/046b1be7aceae244de39
For ease of reviewing and future understanding,
this CL is also broken down into four CLs,
mailed separately, which show the manual
and the automated changes separately.
They are CLs 20990, 20991, 20992, and 20993.
Passes toolstash -cmp.
name old time/op new time/op delta
Template 335ms ± 5% 324ms ± 5% -3.35% (p=0.000 n=23+24)
Unicode 176ms ± 9% 165ms ± 6% -6.12% (p=0.000 n=23+24)
GoTypes 1.10s ± 4% 1.07s ± 2% -2.77% (p=0.000 n=24+24)
Compiler 5.31s ± 3% 5.15s ± 3% -2.95% (p=0.000 n=24+24)
MakeBash 41.6s ± 1% 41.7s ± 2% ~ (p=0.586 n=23+23)
name old alloc/op new alloc/op delta
Template 63.3MB ± 0% 62.4MB ± 0% -1.36% (p=0.000 n=25+23)
Unicode 42.4MB ± 0% 41.6MB ± 0% -1.99% (p=0.000 n=24+25)
GoTypes 220MB ± 0% 217MB ± 0% -1.11% (p=0.000 n=25+25)
Compiler 994MB ± 0% 973MB ± 0% -2.08% (p=0.000 n=24+25)
name old allocs/op new allocs/op delta
Template 681k ± 0% 574k ± 0% -15.71% (p=0.000 n=24+25)
Unicode 518k ± 0% 413k ± 0% -20.34% (p=0.000 n=25+24)
GoTypes 2.08M ± 0% 1.78M ± 0% -14.62% (p=0.000 n=25+25)
Compiler 9.26M ± 0% 7.64M ± 0% -17.48% (p=0.000 n=25+25)
name old text-bytes new text-bytes delta
HelloSize 578k ± 0% 578k ± 0% ~ (all samples are equal)
CmdGoSize 6.46M ± 0% 6.46M ± 0% ~ (all samples are equal)
name old data-bytes new data-bytes delta
HelloSize 128k ± 0% 128k ± 0% ~ (all samples are equal)
CmdGoSize 281k ± 0% 281k ± 0% ~ (all samples are equal)
name old exe-bytes new exe-bytes delta
HelloSize 921k ± 0% 921k ± 0% ~ (all samples are equal)
CmdGoSize 9.86M ± 0% 9.86M ± 0% ~ (all samples are equal)
Change-Id: I277d95bd56d51c166ef7f560647aeaa092f3f475
Reviewed-on: https://go-review.googlesource.com/20959
Reviewed-by: Dave Cheney <dave@cheney.net>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-03-20 08:03:31 -07:00
|
|
|
return n
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
case TARRAY:
|
2016-04-18 14:02:08 -07:00
|
|
|
goto bad
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2018-04-07 03:08:46 -07:00
|
|
|
case TPTR32, TPTR64, TUNSAFEPTR:
|
|
|
|
|
n.SetVal(Val{new(Mpint)})
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2018-04-07 03:08:46 -07:00
|
|
|
case TCHAN, TFUNC, TINTER, TMAP, TSLICE:
|
|
|
|
|
break
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2015-04-01 09:38:44 -07:00
|
|
|
case CTSTR, CTBOOL:
|
2016-02-29 20:07:09 -08:00
|
|
|
if et != n.Type.Etype {
|
2015-02-13 14:40:36 -05:00
|
|
|
goto bad
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-01 09:38:44 -07:00
|
|
|
case CTINT, CTRUNE, CTFLT, CTCPLX:
|
2015-05-01 19:50:27 -07:00
|
|
|
if n.Type.Etype == TUNSAFEPTR && t.Etype != TUINTPTR {
|
|
|
|
|
goto bad
|
|
|
|
|
}
|
2015-10-26 16:00:59 -07:00
|
|
|
ct := n.Val().Ctype()
|
2016-09-16 00:33:29 +10:00
|
|
|
if isInt[et] {
|
2015-02-13 14:40:36 -05:00
|
|
|
switch ct {
|
|
|
|
|
default:
|
|
|
|
|
goto bad
|
|
|
|
|
|
2015-04-01 09:38:44 -07:00
|
|
|
case CTCPLX, CTFLT, CTRUNE:
|
2015-05-27 00:47:05 -04:00
|
|
|
n.SetVal(toint(n.Val()))
|
2015-02-13 14:40:36 -05:00
|
|
|
fallthrough
|
|
|
|
|
|
|
|
|
|
case CTINT:
|
2015-05-27 00:47:05 -04:00
|
|
|
overflow(n.Val(), t)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
2016-09-16 00:33:29 +10:00
|
|
|
} else if isFloat[et] {
|
2015-02-13 14:40:36 -05:00
|
|
|
switch ct {
|
|
|
|
|
default:
|
|
|
|
|
goto bad
|
|
|
|
|
|
2015-04-01 09:38:44 -07:00
|
|
|
case CTCPLX, CTINT, CTRUNE:
|
2015-05-27 00:47:05 -04:00
|
|
|
n.SetVal(toflt(n.Val()))
|
2015-02-13 14:40:36 -05:00
|
|
|
fallthrough
|
|
|
|
|
|
|
|
|
|
case CTFLT:
|
2015-05-27 00:47:05 -04:00
|
|
|
n.SetVal(Val{truncfltlit(n.Val().U.(*Mpflt), t)})
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
2016-09-16 00:33:29 +10:00
|
|
|
} else if isComplex[et] {
|
2015-02-13 14:40:36 -05:00
|
|
|
switch ct {
|
|
|
|
|
default:
|
|
|
|
|
goto bad
|
|
|
|
|
|
2015-04-01 09:38:44 -07:00
|
|
|
case CTFLT, CTINT, CTRUNE:
|
2015-05-27 00:47:05 -04:00
|
|
|
n.SetVal(tocplx(n.Val()))
|
2015-11-04 15:47:48 -05:00
|
|
|
fallthrough
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
case CTCPLX:
|
2017-03-07 11:54:29 +01:00
|
|
|
n.SetVal(Val{trunccmplxlit(n.Val().U.(*Mpcplx), t)})
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
} else if et == types.TSTRING && (ct == CTINT || ct == CTRUNE) && explicit {
|
2015-05-27 00:47:05 -04:00
|
|
|
n.SetVal(tostr(n.Val()))
|
2015-02-13 14:40:36 -05:00
|
|
|
} else {
|
|
|
|
|
goto bad
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
n.Type = t
|
cmd/compile: reduce use of **Node parameters
Escape analysis has a hard time with tree-like
structures (see #13493 and #14858).
This is unlikely to change.
As a result, when invoking a function that accepts
a **Node parameter, we usually allocate a *Node
on the heap. This happens a whole lot.
This CL changes functions from taking a **Node
to acting more like append: It both modifies
the input and returns a replacement for it.
Because of the cascading nature of escape analysis,
in order to get the benefits, I had to modify
almost all such functions. The remaining functions
are in racewalk and the backend. I would be happy
to update them as well in a separate CL.
This CL was created by manually updating the
function signatures and the directly impacted
bits of code. The callsites were then automatically
updated using a bespoke script:
https://gist.github.com/josharian/046b1be7aceae244de39
For ease of reviewing and future understanding,
this CL is also broken down into four CLs,
mailed separately, which show the manual
and the automated changes separately.
They are CLs 20990, 20991, 20992, and 20993.
Passes toolstash -cmp.
name old time/op new time/op delta
Template 335ms ± 5% 324ms ± 5% -3.35% (p=0.000 n=23+24)
Unicode 176ms ± 9% 165ms ± 6% -6.12% (p=0.000 n=23+24)
GoTypes 1.10s ± 4% 1.07s ± 2% -2.77% (p=0.000 n=24+24)
Compiler 5.31s ± 3% 5.15s ± 3% -2.95% (p=0.000 n=24+24)
MakeBash 41.6s ± 1% 41.7s ± 2% ~ (p=0.586 n=23+23)
name old alloc/op new alloc/op delta
Template 63.3MB ± 0% 62.4MB ± 0% -1.36% (p=0.000 n=25+23)
Unicode 42.4MB ± 0% 41.6MB ± 0% -1.99% (p=0.000 n=24+25)
GoTypes 220MB ± 0% 217MB ± 0% -1.11% (p=0.000 n=25+25)
Compiler 994MB ± 0% 973MB ± 0% -2.08% (p=0.000 n=24+25)
name old allocs/op new allocs/op delta
Template 681k ± 0% 574k ± 0% -15.71% (p=0.000 n=24+25)
Unicode 518k ± 0% 413k ± 0% -20.34% (p=0.000 n=25+24)
GoTypes 2.08M ± 0% 1.78M ± 0% -14.62% (p=0.000 n=25+25)
Compiler 9.26M ± 0% 7.64M ± 0% -17.48% (p=0.000 n=25+25)
name old text-bytes new text-bytes delta
HelloSize 578k ± 0% 578k ± 0% ~ (all samples are equal)
CmdGoSize 6.46M ± 0% 6.46M ± 0% ~ (all samples are equal)
name old data-bytes new data-bytes delta
HelloSize 128k ± 0% 128k ± 0% ~ (all samples are equal)
CmdGoSize 281k ± 0% 281k ± 0% ~ (all samples are equal)
name old exe-bytes new exe-bytes delta
HelloSize 921k ± 0% 921k ± 0% ~ (all samples are equal)
CmdGoSize 9.86M ± 0% 9.86M ± 0% ~ (all samples are equal)
Change-Id: I277d95bd56d51c166ef7f560647aeaa092f3f475
Reviewed-on: https://go-review.googlesource.com/20959
Reviewed-by: Dave Cheney <dave@cheney.net>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-03-20 08:03:31 -07:00
|
|
|
return n
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
bad:
|
2017-02-27 19:56:38 +02:00
|
|
|
if !n.Diag() {
|
|
|
|
|
if !t.Broke() {
|
2017-06-27 19:29:59 -04:00
|
|
|
yyerror("cannot convert %L to type %v", n, t)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
2017-02-27 19:56:38 +02:00
|
|
|
n.SetDiag(true)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2016-04-01 13:36:24 -07:00
|
|
|
if n.Type.IsUntyped() {
|
2016-03-17 12:24:11 -07:00
|
|
|
n = defaultlitreuse(n, nil, reuse)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
cmd/compile: reduce use of **Node parameters
Escape analysis has a hard time with tree-like
structures (see #13493 and #14858).
This is unlikely to change.
As a result, when invoking a function that accepts
a **Node parameter, we usually allocate a *Node
on the heap. This happens a whole lot.
This CL changes functions from taking a **Node
to acting more like append: It both modifies
the input and returns a replacement for it.
Because of the cascading nature of escape analysis,
in order to get the benefits, I had to modify
almost all such functions. The remaining functions
are in racewalk and the backend. I would be happy
to update them as well in a separate CL.
This CL was created by manually updating the
function signatures and the directly impacted
bits of code. The callsites were then automatically
updated using a bespoke script:
https://gist.github.com/josharian/046b1be7aceae244de39
For ease of reviewing and future understanding,
this CL is also broken down into four CLs,
mailed separately, which show the manual
and the automated changes separately.
They are CLs 20990, 20991, 20992, and 20993.
Passes toolstash -cmp.
name old time/op new time/op delta
Template 335ms ± 5% 324ms ± 5% -3.35% (p=0.000 n=23+24)
Unicode 176ms ± 9% 165ms ± 6% -6.12% (p=0.000 n=23+24)
GoTypes 1.10s ± 4% 1.07s ± 2% -2.77% (p=0.000 n=24+24)
Compiler 5.31s ± 3% 5.15s ± 3% -2.95% (p=0.000 n=24+24)
MakeBash 41.6s ± 1% 41.7s ± 2% ~ (p=0.586 n=23+23)
name old alloc/op new alloc/op delta
Template 63.3MB ± 0% 62.4MB ± 0% -1.36% (p=0.000 n=25+23)
Unicode 42.4MB ± 0% 41.6MB ± 0% -1.99% (p=0.000 n=24+25)
GoTypes 220MB ± 0% 217MB ± 0% -1.11% (p=0.000 n=25+25)
Compiler 994MB ± 0% 973MB ± 0% -2.08% (p=0.000 n=24+25)
name old allocs/op new allocs/op delta
Template 681k ± 0% 574k ± 0% -15.71% (p=0.000 n=24+25)
Unicode 518k ± 0% 413k ± 0% -20.34% (p=0.000 n=25+24)
GoTypes 2.08M ± 0% 1.78M ± 0% -14.62% (p=0.000 n=25+25)
Compiler 9.26M ± 0% 7.64M ± 0% -17.48% (p=0.000 n=25+25)
name old text-bytes new text-bytes delta
HelloSize 578k ± 0% 578k ± 0% ~ (all samples are equal)
CmdGoSize 6.46M ± 0% 6.46M ± 0% ~ (all samples are equal)
name old data-bytes new data-bytes delta
HelloSize 128k ± 0% 128k ± 0% ~ (all samples are equal)
CmdGoSize 281k ± 0% 281k ± 0% ~ (all samples are equal)
name old exe-bytes new exe-bytes delta
HelloSize 921k ± 0% 921k ± 0% ~ (all samples are equal)
CmdGoSize 9.86M ± 0% 9.86M ± 0% ~ (all samples are equal)
Change-Id: I277d95bd56d51c166ef7f560647aeaa092f3f475
Reviewed-on: https://go-review.googlesource.com/20959
Reviewed-by: Dave Cheney <dave@cheney.net>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-03-20 08:03:31 -07:00
|
|
|
return n
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func copyval(v Val) Val {
|
2016-04-22 12:27:29 -07:00
|
|
|
switch u := v.U.(type) {
|
|
|
|
|
case *Mpint:
|
2015-02-23 16:07:24 -05:00
|
|
|
i := new(Mpint)
|
2016-04-22 12:27:29 -07:00
|
|
|
i.Set(u)
|
|
|
|
|
i.Rune = u.Rune
|
2015-05-14 17:57:42 -07:00
|
|
|
v.U = i
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2016-04-22 12:27:29 -07:00
|
|
|
case *Mpflt:
|
2015-03-20 16:59:08 -07:00
|
|
|
f := newMpflt()
|
2016-04-22 12:27:29 -07:00
|
|
|
f.Set(u)
|
2015-05-14 17:57:42 -07:00
|
|
|
v.U = f
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2016-04-22 12:27:29 -07:00
|
|
|
case *Mpcplx:
|
2015-02-23 16:07:24 -05:00
|
|
|
c := new(Mpcplx)
|
2016-04-22 12:27:29 -07:00
|
|
|
c.Real.Set(&u.Real)
|
|
|
|
|
c.Imag.Set(&u.Imag)
|
2015-05-14 17:57:42 -07:00
|
|
|
v.U = c
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return v
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func tocplx(v Val) Val {
|
2016-04-22 12:27:29 -07:00
|
|
|
switch u := v.U.(type) {
|
|
|
|
|
case *Mpint:
|
2015-02-23 16:07:24 -05:00
|
|
|
c := new(Mpcplx)
|
2016-04-22 12:27:29 -07:00
|
|
|
c.Real.SetInt(u)
|
2016-03-20 13:55:42 -07:00
|
|
|
c.Imag.SetFloat64(0.0)
|
2015-05-14 17:57:42 -07:00
|
|
|
v.U = c
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2016-04-22 12:27:29 -07:00
|
|
|
case *Mpflt:
|
2015-02-23 16:07:24 -05:00
|
|
|
c := new(Mpcplx)
|
2016-04-22 12:27:29 -07:00
|
|
|
c.Real.Set(u)
|
2016-03-20 13:55:42 -07:00
|
|
|
c.Imag.SetFloat64(0.0)
|
2015-05-14 17:57:42 -07:00
|
|
|
v.U = c
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return v
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func toflt(v Val) Val {
|
2016-04-22 12:27:29 -07:00
|
|
|
switch u := v.U.(type) {
|
|
|
|
|
case *Mpint:
|
2015-03-20 16:59:08 -07:00
|
|
|
f := newMpflt()
|
2016-04-22 12:27:29 -07:00
|
|
|
f.SetInt(u)
|
2015-05-14 17:57:42 -07:00
|
|
|
v.U = f
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2016-04-22 12:27:29 -07:00
|
|
|
case *Mpcplx:
|
2015-03-20 16:59:08 -07:00
|
|
|
f := newMpflt()
|
2016-04-22 12:27:29 -07:00
|
|
|
f.Set(&u.Real)
|
|
|
|
|
if u.Imag.CmpFloat64(0) != 0 {
|
2018-09-18 21:55:35 -07:00
|
|
|
yyerror("constant %v truncated to real", u.GoString())
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
2015-05-14 17:57:42 -07:00
|
|
|
v.U = f
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return v
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func toint(v Val) Val {
|
2016-04-22 12:27:29 -07:00
|
|
|
switch u := v.U.(type) {
|
|
|
|
|
case *Mpint:
|
|
|
|
|
if u.Rune {
|
|
|
|
|
i := new(Mpint)
|
|
|
|
|
i.Set(u)
|
|
|
|
|
v.U = i
|
|
|
|
|
}
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2016-04-22 12:27:29 -07:00
|
|
|
case *Mpflt:
|
2015-02-23 16:07:24 -05:00
|
|
|
i := new(Mpint)
|
cmd/compile: fix misleading "truncated to int" messages
When defining an int const, the compiler tries to cast the RHS
expression to int. The cast may fail for three reasons:
1. expr is an integer constant that overflows int
2. expr is a floating point constant
3. expr is a complex constant, or not a number
In the second case, in order to print a sensible error message, we
must distinguish between a floating point constant that should be
included in the error message and a floating point constant that
cannot be reasonably formatted for inclusion in an error message.
For example, in:
const a int = 1.1
const b int = 1 + 1e-100
a is in the former group, while b is in the latter, since the floating
point value resulting from the evaluation of the rhs of the assignment
(1.00...01) is too long to be fully printed in an error message, and
cannot be shortened without making the error message misleading
(rounding or truncating it would result in a "1", which looks like an
integer constant, and it makes little sense in an error message about
an invalid floating point expression).
To fix this problem, we try to format the float value using fconv
(which is used by the error reporting mechanism to format float
arguments), and then parse the resulting string back to a
big.Float. If the result is an integer, we assume that expr is a float
value that cannot be reasonably be formatted as a string, and we emit
an error message that does not include its string representation.
Also, change the error message for overflows to a more conservative
"integer too large", which does not mention overflows that are only
caused by an internal implementation restriction.
Also, change (*Mpint) SetFloat so that it returns a bool (instead of
0/-1 for success/failure).
Fixes #11371
Change-Id: Ibbc73e2ed2eaf41f07827b0649d0eb637150ecaa
Reviewed-on: https://go-review.googlesource.com/35411
Run-TryBot: Alberto Donizetti <alb.donizetti@gmail.com>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2017-01-18 11:48:14 +01:00
|
|
|
if !i.SetFloat(u) {
|
2017-04-07 09:09:17 +02:00
|
|
|
if i.checkOverflow(0) {
|
cmd/compile: fix misleading "truncated to int" messages
When defining an int const, the compiler tries to cast the RHS
expression to int. The cast may fail for three reasons:
1. expr is an integer constant that overflows int
2. expr is a floating point constant
3. expr is a complex constant, or not a number
In the second case, in order to print a sensible error message, we
must distinguish between a floating point constant that should be
included in the error message and a floating point constant that
cannot be reasonably formatted for inclusion in an error message.
For example, in:
const a int = 1.1
const b int = 1 + 1e-100
a is in the former group, while b is in the latter, since the floating
point value resulting from the evaluation of the rhs of the assignment
(1.00...01) is too long to be fully printed in an error message, and
cannot be shortened without making the error message misleading
(rounding or truncating it would result in a "1", which looks like an
integer constant, and it makes little sense in an error message about
an invalid floating point expression).
To fix this problem, we try to format the float value using fconv
(which is used by the error reporting mechanism to format float
arguments), and then parse the resulting string back to a
big.Float. If the result is an integer, we assume that expr is a float
value that cannot be reasonably be formatted as a string, and we emit
an error message that does not include its string representation.
Also, change the error message for overflows to a more conservative
"integer too large", which does not mention overflows that are only
caused by an internal implementation restriction.
Also, change (*Mpint) SetFloat so that it returns a bool (instead of
0/-1 for success/failure).
Fixes #11371
Change-Id: Ibbc73e2ed2eaf41f07827b0649d0eb637150ecaa
Reviewed-on: https://go-review.googlesource.com/35411
Run-TryBot: Alberto Donizetti <alb.donizetti@gmail.com>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2017-01-18 11:48:14 +01:00
|
|
|
yyerror("integer too large")
|
|
|
|
|
} else {
|
|
|
|
|
// The value of u cannot be represented as an integer;
|
|
|
|
|
// so we need to print an error message.
|
|
|
|
|
// Unfortunately some float values cannot be
|
|
|
|
|
// reasonably formatted for inclusion in an error
|
|
|
|
|
// message (example: 1 + 1e-100), so first we try to
|
|
|
|
|
// format the float; if the truncation resulted in
|
|
|
|
|
// something that looks like an integer we omit the
|
|
|
|
|
// value from the error message.
|
|
|
|
|
// (See issue #11371).
|
|
|
|
|
var t big.Float
|
2018-09-18 21:55:35 -07:00
|
|
|
t.Parse(u.GoString(), 10)
|
cmd/compile: fix misleading "truncated to int" messages
When defining an int const, the compiler tries to cast the RHS
expression to int. The cast may fail for three reasons:
1. expr is an integer constant that overflows int
2. expr is a floating point constant
3. expr is a complex constant, or not a number
In the second case, in order to print a sensible error message, we
must distinguish between a floating point constant that should be
included in the error message and a floating point constant that
cannot be reasonably formatted for inclusion in an error message.
For example, in:
const a int = 1.1
const b int = 1 + 1e-100
a is in the former group, while b is in the latter, since the floating
point value resulting from the evaluation of the rhs of the assignment
(1.00...01) is too long to be fully printed in an error message, and
cannot be shortened without making the error message misleading
(rounding or truncating it would result in a "1", which looks like an
integer constant, and it makes little sense in an error message about
an invalid floating point expression).
To fix this problem, we try to format the float value using fconv
(which is used by the error reporting mechanism to format float
arguments), and then parse the resulting string back to a
big.Float. If the result is an integer, we assume that expr is a float
value that cannot be reasonably be formatted as a string, and we emit
an error message that does not include its string representation.
Also, change the error message for overflows to a more conservative
"integer too large", which does not mention overflows that are only
caused by an internal implementation restriction.
Also, change (*Mpint) SetFloat so that it returns a bool (instead of
0/-1 for success/failure).
Fixes #11371
Change-Id: Ibbc73e2ed2eaf41f07827b0649d0eb637150ecaa
Reviewed-on: https://go-review.googlesource.com/35411
Run-TryBot: Alberto Donizetti <alb.donizetti@gmail.com>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2017-01-18 11:48:14 +01:00
|
|
|
if t.IsInt() {
|
|
|
|
|
yyerror("constant truncated to integer")
|
|
|
|
|
} else {
|
2018-09-18 21:55:35 -07:00
|
|
|
yyerror("constant %v truncated to integer", u.GoString())
|
cmd/compile: fix misleading "truncated to int" messages
When defining an int const, the compiler tries to cast the RHS
expression to int. The cast may fail for three reasons:
1. expr is an integer constant that overflows int
2. expr is a floating point constant
3. expr is a complex constant, or not a number
In the second case, in order to print a sensible error message, we
must distinguish between a floating point constant that should be
included in the error message and a floating point constant that
cannot be reasonably formatted for inclusion in an error message.
For example, in:
const a int = 1.1
const b int = 1 + 1e-100
a is in the former group, while b is in the latter, since the floating
point value resulting from the evaluation of the rhs of the assignment
(1.00...01) is too long to be fully printed in an error message, and
cannot be shortened without making the error message misleading
(rounding or truncating it would result in a "1", which looks like an
integer constant, and it makes little sense in an error message about
an invalid floating point expression).
To fix this problem, we try to format the float value using fconv
(which is used by the error reporting mechanism to format float
arguments), and then parse the resulting string back to a
big.Float. If the result is an integer, we assume that expr is a float
value that cannot be reasonably be formatted as a string, and we emit
an error message that does not include its string representation.
Also, change the error message for overflows to a more conservative
"integer too large", which does not mention overflows that are only
caused by an internal implementation restriction.
Also, change (*Mpint) SetFloat so that it returns a bool (instead of
0/-1 for success/failure).
Fixes #11371
Change-Id: Ibbc73e2ed2eaf41f07827b0649d0eb637150ecaa
Reviewed-on: https://go-review.googlesource.com/35411
Run-TryBot: Alberto Donizetti <alb.donizetti@gmail.com>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2017-01-18 11:48:14 +01:00
|
|
|
}
|
2015-12-03 15:51:03 -08:00
|
|
|
}
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
2015-05-14 17:57:42 -07:00
|
|
|
v.U = i
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2016-04-22 12:27:29 -07:00
|
|
|
case *Mpcplx:
|
2015-02-23 16:07:24 -05:00
|
|
|
i := new(Mpint)
|
cmd/compile: fix misleading "truncated to int" messages
When defining an int const, the compiler tries to cast the RHS
expression to int. The cast may fail for three reasons:
1. expr is an integer constant that overflows int
2. expr is a floating point constant
3. expr is a complex constant, or not a number
In the second case, in order to print a sensible error message, we
must distinguish between a floating point constant that should be
included in the error message and a floating point constant that
cannot be reasonably formatted for inclusion in an error message.
For example, in:
const a int = 1.1
const b int = 1 + 1e-100
a is in the former group, while b is in the latter, since the floating
point value resulting from the evaluation of the rhs of the assignment
(1.00...01) is too long to be fully printed in an error message, and
cannot be shortened without making the error message misleading
(rounding or truncating it would result in a "1", which looks like an
integer constant, and it makes little sense in an error message about
an invalid floating point expression).
To fix this problem, we try to format the float value using fconv
(which is used by the error reporting mechanism to format float
arguments), and then parse the resulting string back to a
big.Float. If the result is an integer, we assume that expr is a float
value that cannot be reasonably be formatted as a string, and we emit
an error message that does not include its string representation.
Also, change the error message for overflows to a more conservative
"integer too large", which does not mention overflows that are only
caused by an internal implementation restriction.
Also, change (*Mpint) SetFloat so that it returns a bool (instead of
0/-1 for success/failure).
Fixes #11371
Change-Id: Ibbc73e2ed2eaf41f07827b0649d0eb637150ecaa
Reviewed-on: https://go-review.googlesource.com/35411
Run-TryBot: Alberto Donizetti <alb.donizetti@gmail.com>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2017-01-18 11:48:14 +01:00
|
|
|
if !i.SetFloat(&u.Real) || u.Imag.CmpFloat64(0) != 0 {
|
2018-09-18 21:55:35 -07:00
|
|
|
yyerror("constant %v truncated to integer", u.GoString())
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
2016-12-21 11:07:11 +01:00
|
|
|
|
2015-05-14 17:57:42 -07:00
|
|
|
v.U = i
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return v
|
|
|
|
|
}
|
|
|
|
|
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
func doesoverflow(v Val, t *types.Type) bool {
|
2016-04-22 12:27:29 -07:00
|
|
|
switch u := v.U.(type) {
|
|
|
|
|
case *Mpint:
|
2016-03-30 15:09:25 -07:00
|
|
|
if !t.IsInteger() {
|
2015-08-30 23:10:03 +02:00
|
|
|
Fatalf("overflow: %v integer constant", t)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
2016-09-16 00:33:29 +10:00
|
|
|
return u.Cmp(minintval[t.Etype]) < 0 || u.Cmp(maxintval[t.Etype]) > 0
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2016-04-22 12:27:29 -07:00
|
|
|
case *Mpflt:
|
2016-03-30 15:09:25 -07:00
|
|
|
if !t.IsFloat() {
|
2015-08-30 23:10:03 +02:00
|
|
|
Fatalf("overflow: %v floating-point constant", t)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
2016-04-22 12:27:29 -07:00
|
|
|
return u.Cmp(minfltval[t.Etype]) <= 0 || u.Cmp(maxfltval[t.Etype]) >= 0
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2016-04-22 12:27:29 -07:00
|
|
|
case *Mpcplx:
|
2016-03-30 15:09:25 -07:00
|
|
|
if !t.IsComplex() {
|
2015-08-30 23:10:03 +02:00
|
|
|
Fatalf("overflow: %v complex constant", t)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
2016-04-22 12:27:29 -07:00
|
|
|
return u.Real.Cmp(minfltval[t.Etype]) <= 0 || u.Real.Cmp(maxfltval[t.Etype]) >= 0 ||
|
|
|
|
|
u.Imag.Cmp(minfltval[t.Etype]) <= 0 || u.Imag.Cmp(maxfltval[t.Etype]) >= 0
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2015-02-17 22:13:49 -05:00
|
|
|
return false
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2017-03-07 11:54:29 +01:00
|
|
|
func overflow(v Val, t *types.Type) bool {
|
2015-02-13 14:40:36 -05:00
|
|
|
// v has already been converted
|
|
|
|
|
// to appropriate form for t.
|
|
|
|
|
if t == nil || t.Etype == TIDEAL {
|
2017-03-07 11:54:29 +01:00
|
|
|
return false
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2018-03-31 16:49:07 -07:00
|
|
|
// Only uintptrs may be converted to pointers, which cannot overflow.
|
|
|
|
|
if t.IsPtr() || t.IsUnsafePtr() {
|
2017-03-07 11:54:29 +01:00
|
|
|
return false
|
2015-05-01 19:50:27 -07:00
|
|
|
}
|
|
|
|
|
|
2015-09-15 11:16:58 -07:00
|
|
|
if doesoverflow(v, t) {
|
2016-09-15 15:45:10 +10:00
|
|
|
yyerror("constant %v overflows %v", v, t)
|
2017-03-07 11:54:29 +01:00
|
|
|
return true
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
2017-03-07 11:54:29 +01:00
|
|
|
|
|
|
|
|
return false
|
|
|
|
|
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func tostr(v Val) Val {
|
2016-04-22 12:27:29 -07:00
|
|
|
switch u := v.U.(type) {
|
|
|
|
|
case *Mpint:
|
2016-03-31 02:04:12 -07:00
|
|
|
var i int64 = 0xFFFD
|
2016-09-16 00:33:29 +10:00
|
|
|
if u.Cmp(minintval[TUINT32]) >= 0 && u.Cmp(maxintval[TUINT32]) <= 0 {
|
2016-03-31 02:04:12 -07:00
|
|
|
i = u.Int64()
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
2016-03-31 02:04:12 -07:00
|
|
|
v.U = string(i)
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2016-04-22 12:27:29 -07:00
|
|
|
case *NilVal:
|
|
|
|
|
// Can happen because of string([]byte(nil)).
|
2015-05-14 17:57:42 -07:00
|
|
|
v.U = ""
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return v
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-26 16:00:59 -07:00
|
|
|
func consttype(n *Node) Ctype {
|
2015-02-13 14:40:36 -05:00
|
|
|
if n == nil || n.Op != OLITERAL {
|
2017-10-10 17:36:03 +01:00
|
|
|
return 0
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
2015-10-26 16:00:59 -07:00
|
|
|
return n.Val().Ctype()
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2015-10-26 16:00:59 -07:00
|
|
|
func Isconst(n *Node, ct Ctype) bool {
|
2015-02-23 16:07:24 -05:00
|
|
|
t := consttype(n)
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
// If the caller is asking for CTINT, allow CTRUNE too.
|
|
|
|
|
// Makes life easier for back ends.
|
2015-02-17 22:13:49 -05:00
|
|
|
return t == ct || (ct == CTINT && t == CTRUNE)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2015-10-22 09:51:12 +09:00
|
|
|
// if n is constant, rewrite as OLITERAL node.
|
2015-02-13 14:40:36 -05:00
|
|
|
func evconst(n *Node) {
|
|
|
|
|
// pick off just the opcodes that can be
|
|
|
|
|
// constant evaluated.
|
|
|
|
|
switch n.Op {
|
|
|
|
|
default:
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
case OADD,
|
|
|
|
|
OAND,
|
|
|
|
|
OANDAND,
|
|
|
|
|
OANDNOT,
|
|
|
|
|
OARRAYBYTESTR,
|
|
|
|
|
OCOM,
|
|
|
|
|
ODIV,
|
|
|
|
|
OEQ,
|
|
|
|
|
OGE,
|
|
|
|
|
OGT,
|
|
|
|
|
OLE,
|
|
|
|
|
OLSH,
|
|
|
|
|
OLT,
|
|
|
|
|
OMINUS,
|
|
|
|
|
OMOD,
|
|
|
|
|
OMUL,
|
|
|
|
|
ONE,
|
|
|
|
|
ONOT,
|
|
|
|
|
OOR,
|
|
|
|
|
OOROR,
|
|
|
|
|
OPLUS,
|
|
|
|
|
ORSH,
|
|
|
|
|
OSUB,
|
|
|
|
|
OXOR:
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
case OCONV:
|
|
|
|
|
if n.Type == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
2015-03-01 07:54:01 +00:00
|
|
|
if !okforconst[n.Type.Etype] && n.Type.Etype != TNIL {
|
2015-02-13 14:40:36 -05:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// merge adjacent constants in the argument list.
|
|
|
|
|
case OADDSTR:
|
2016-03-08 15:10:26 -08:00
|
|
|
s := n.List.Slice()
|
2016-03-07 09:36:24 -08:00
|
|
|
for i1 := 0; i1 < len(s); i1++ {
|
|
|
|
|
if Isconst(s[i1], CTSTR) && i1+1 < len(s) && Isconst(s[i1+1], CTSTR) {
|
|
|
|
|
// merge from i1 up to but not including i2
|
|
|
|
|
var strs []string
|
|
|
|
|
i2 := i1
|
|
|
|
|
for i2 < len(s) && Isconst(s[i2], CTSTR) {
|
|
|
|
|
strs = append(strs, s[i2].Val().U.(string))
|
|
|
|
|
i2++
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-23 16:01:15 +11:00
|
|
|
nl := *s[i1]
|
|
|
|
|
nl.Orig = &nl
|
2016-03-07 09:36:24 -08:00
|
|
|
nl.SetVal(Val{strings.Join(strs, "")})
|
2016-03-23 16:01:15 +11:00
|
|
|
s[i1] = &nl
|
2016-03-07 09:36:24 -08:00
|
|
|
s = append(s[:i1+1], s[i2:]...)
|
2015-06-09 18:37:26 -07:00
|
|
|
}
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2016-03-07 09:36:24 -08:00
|
|
|
if len(s) == 1 && Isconst(s[0], CTSTR) {
|
2015-02-13 14:40:36 -05:00
|
|
|
n.Op = OLITERAL
|
2016-03-07 09:36:24 -08:00
|
|
|
n.SetVal(s[0].Val())
|
|
|
|
|
} else {
|
2016-03-08 15:10:26 -08:00
|
|
|
n.List.Set(s)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-23 16:07:24 -05:00
|
|
|
nl := n.Left
|
2015-02-13 14:40:36 -05:00
|
|
|
if nl == nil || nl.Type == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
2017-10-10 17:36:03 +01:00
|
|
|
if consttype(nl) == 0 {
|
2015-02-13 14:40:36 -05:00
|
|
|
return
|
|
|
|
|
}
|
2016-02-29 20:07:09 -08:00
|
|
|
wl := nl.Type.Etype
|
2016-09-16 00:33:29 +10:00
|
|
|
if isInt[wl] || isFloat[wl] || isComplex[wl] {
|
2015-02-13 14:40:36 -05:00
|
|
|
wl = TIDEAL
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-26 16:00:59 -07:00
|
|
|
// avoid constant conversions in switches below
|
|
|
|
|
const (
|
2015-09-24 23:21:18 +02:00
|
|
|
CTINT_ = uint32(CTINT)
|
|
|
|
|
CTRUNE_ = uint32(CTRUNE)
|
|
|
|
|
CTFLT_ = uint32(CTFLT)
|
|
|
|
|
CTCPLX_ = uint32(CTCPLX)
|
|
|
|
|
CTSTR_ = uint32(CTSTR)
|
|
|
|
|
CTBOOL_ = uint32(CTBOOL)
|
|
|
|
|
CTNIL_ = uint32(CTNIL)
|
|
|
|
|
OCONV_ = uint32(OCONV) << 16
|
|
|
|
|
OARRAYBYTESTR_ = uint32(OARRAYBYTESTR) << 16
|
|
|
|
|
OPLUS_ = uint32(OPLUS) << 16
|
|
|
|
|
OMINUS_ = uint32(OMINUS) << 16
|
|
|
|
|
OCOM_ = uint32(OCOM) << 16
|
|
|
|
|
ONOT_ = uint32(ONOT) << 16
|
|
|
|
|
OLSH_ = uint32(OLSH) << 16
|
|
|
|
|
ORSH_ = uint32(ORSH) << 16
|
|
|
|
|
OADD_ = uint32(OADD) << 16
|
|
|
|
|
OSUB_ = uint32(OSUB) << 16
|
|
|
|
|
OMUL_ = uint32(OMUL) << 16
|
|
|
|
|
ODIV_ = uint32(ODIV) << 16
|
|
|
|
|
OMOD_ = uint32(OMOD) << 16
|
|
|
|
|
OOR_ = uint32(OOR) << 16
|
|
|
|
|
OAND_ = uint32(OAND) << 16
|
|
|
|
|
OANDNOT_ = uint32(OANDNOT) << 16
|
|
|
|
|
OXOR_ = uint32(OXOR) << 16
|
|
|
|
|
OEQ_ = uint32(OEQ) << 16
|
|
|
|
|
ONE_ = uint32(ONE) << 16
|
|
|
|
|
OLT_ = uint32(OLT) << 16
|
|
|
|
|
OLE_ = uint32(OLE) << 16
|
|
|
|
|
OGE_ = uint32(OGE) << 16
|
|
|
|
|
OGT_ = uint32(OGT) << 16
|
|
|
|
|
OOROR_ = uint32(OOROR) << 16
|
|
|
|
|
OANDAND_ = uint32(OANDAND) << 16
|
2015-10-26 16:00:59 -07:00
|
|
|
)
|
|
|
|
|
|
2015-02-23 16:07:24 -05:00
|
|
|
nr := n.Right
|
|
|
|
|
var rv Val
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
var wr types.EType
|
2017-04-07 08:31:52 +02:00
|
|
|
var ctype uint32
|
2015-02-23 16:07:24 -05:00
|
|
|
var v Val
|
2015-02-13 14:40:36 -05:00
|
|
|
if nr == nil {
|
2015-03-02 12:35:15 -05:00
|
|
|
// copy numeric value to avoid modifying
|
|
|
|
|
// nl, in case someone still refers to it (e.g. iota).
|
2018-03-31 16:49:07 -07:00
|
|
|
v = copyval(nl.Val())
|
2015-03-02 12:35:15 -05:00
|
|
|
|
2017-04-07 08:31:52 +02:00
|
|
|
// rune values are int values for the purpose of constant folding.
|
|
|
|
|
ctype = uint32(v.Ctype())
|
|
|
|
|
if ctype == CTRUNE_ {
|
|
|
|
|
ctype = CTINT_
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch uint32(n.Op)<<16 | ctype {
|
2015-03-02 12:35:15 -05:00
|
|
|
default:
|
2017-02-27 19:56:38 +02:00
|
|
|
if !n.Diag() {
|
2016-09-15 15:45:10 +10:00
|
|
|
yyerror("illegal constant expression %v %v", n.Op, nl.Type)
|
2017-02-27 19:56:38 +02:00
|
|
|
n.SetDiag(true)
|
2015-03-02 12:35:15 -05:00
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
|
2015-09-24 23:21:18 +02:00
|
|
|
case OCONV_ | CTNIL_,
|
|
|
|
|
OARRAYBYTESTR_ | CTNIL_:
|
2016-03-30 14:56:08 -07:00
|
|
|
if n.Type.IsString() {
|
2015-03-02 12:35:15 -05:00
|
|
|
v = tostr(v)
|
|
|
|
|
nl.Type = n.Type
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
fallthrough
|
2015-09-24 23:21:18 +02:00
|
|
|
case OCONV_ | CTINT_,
|
|
|
|
|
OCONV_ | CTFLT_,
|
2017-02-12 22:12:12 -05:00
|
|
|
OCONV_ | CTCPLX_,
|
2016-01-05 12:26:55 -08:00
|
|
|
OCONV_ | CTSTR_,
|
|
|
|
|
OCONV_ | CTBOOL_:
|
2016-03-17 12:24:11 -07:00
|
|
|
nl = convlit1(nl, n.Type, true, false)
|
2015-05-27 00:47:05 -04:00
|
|
|
v = nl.Val()
|
2015-03-02 12:35:15 -05:00
|
|
|
|
2017-04-07 08:31:52 +02:00
|
|
|
case OPLUS_ | CTINT_:
|
2015-03-02 12:35:15 -05:00
|
|
|
break
|
|
|
|
|
|
2017-04-07 08:31:52 +02:00
|
|
|
case OMINUS_ | CTINT_:
|
2016-03-20 13:55:42 -07:00
|
|
|
v.U.(*Mpint).Neg()
|
2015-03-02 12:35:15 -05:00
|
|
|
|
2017-04-07 08:31:52 +02:00
|
|
|
case OCOM_ | CTINT_:
|
2018-06-11 09:11:29 +01:00
|
|
|
et := Txxx
|
2015-03-02 12:35:15 -05:00
|
|
|
if nl.Type != nil {
|
2016-02-29 20:07:09 -08:00
|
|
|
et = nl.Type.Etype
|
2015-03-02 12:35:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// calculate the mask in b
|
|
|
|
|
// result will be (a ^ mask)
|
|
|
|
|
var b Mpint
|
|
|
|
|
switch et {
|
|
|
|
|
// signed guys change sign
|
|
|
|
|
default:
|
2016-03-20 13:55:42 -07:00
|
|
|
b.SetInt64(-1)
|
2015-03-02 12:35:15 -05:00
|
|
|
|
|
|
|
|
// unsigned guys invert their bits
|
|
|
|
|
case TUINT8,
|
|
|
|
|
TUINT16,
|
|
|
|
|
TUINT32,
|
|
|
|
|
TUINT64,
|
|
|
|
|
TUINT,
|
|
|
|
|
TUINTPTR:
|
2016-09-16 00:33:29 +10:00
|
|
|
b.Set(maxintval[et])
|
2015-03-02 12:35:15 -05:00
|
|
|
}
|
|
|
|
|
|
2016-03-20 13:55:42 -07:00
|
|
|
v.U.(*Mpint).Xor(&b)
|
2015-03-02 12:35:15 -05:00
|
|
|
|
2015-09-24 23:21:18 +02:00
|
|
|
case OPLUS_ | CTFLT_:
|
2015-03-02 12:35:15 -05:00
|
|
|
break
|
|
|
|
|
|
2015-09-24 23:21:18 +02:00
|
|
|
case OMINUS_ | CTFLT_:
|
2016-03-20 13:55:42 -07:00
|
|
|
v.U.(*Mpflt).Neg()
|
2015-03-02 12:35:15 -05:00
|
|
|
|
2015-09-24 23:21:18 +02:00
|
|
|
case OPLUS_ | CTCPLX_:
|
2015-03-02 12:35:15 -05:00
|
|
|
break
|
|
|
|
|
|
2015-09-24 23:21:18 +02:00
|
|
|
case OMINUS_ | CTCPLX_:
|
2016-03-20 13:55:42 -07:00
|
|
|
v.U.(*Mpcplx).Real.Neg()
|
|
|
|
|
v.U.(*Mpcplx).Imag.Neg()
|
2015-03-02 12:35:15 -05:00
|
|
|
|
2015-09-24 23:21:18 +02:00
|
|
|
case ONOT_ | CTBOOL_:
|
2015-05-14 17:57:42 -07:00
|
|
|
if !v.U.(bool) {
|
2015-03-02 12:35:15 -05:00
|
|
|
goto settrue
|
|
|
|
|
}
|
|
|
|
|
goto setfalse
|
|
|
|
|
}
|
|
|
|
|
goto ret
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
if nr.Type == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
2017-10-10 17:36:03 +01:00
|
|
|
if consttype(nr) == 0 {
|
2015-02-13 14:40:36 -05:00
|
|
|
return
|
|
|
|
|
}
|
2016-02-29 20:07:09 -08:00
|
|
|
wr = nr.Type.Etype
|
2016-09-16 00:33:29 +10:00
|
|
|
if isInt[wr] || isFloat[wr] || isComplex[wr] {
|
2015-02-13 14:40:36 -05:00
|
|
|
wr = TIDEAL
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// check for compatible general types (numeric, string, etc)
|
|
|
|
|
if wl != wr {
|
2016-08-23 16:43:43 -04:00
|
|
|
if wl == TINTER || wr == TINTER {
|
2017-04-10 12:42:52 -07:00
|
|
|
if n.Op == ONE {
|
|
|
|
|
goto settrue
|
|
|
|
|
}
|
2016-08-23 16:43:43 -04:00
|
|
|
goto setfalse
|
|
|
|
|
}
|
2015-02-13 14:40:36 -05:00
|
|
|
goto illegal
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// check for compatible types.
|
|
|
|
|
switch n.Op {
|
|
|
|
|
// ideal const mixes with anything but otherwise must match.
|
|
|
|
|
default:
|
|
|
|
|
if nl.Type.Etype != TIDEAL {
|
cmd/compile: reduce use of **Node parameters
Escape analysis has a hard time with tree-like
structures (see #13493 and #14858).
This is unlikely to change.
As a result, when invoking a function that accepts
a **Node parameter, we usually allocate a *Node
on the heap. This happens a whole lot.
This CL changes functions from taking a **Node
to acting more like append: It both modifies
the input and returns a replacement for it.
Because of the cascading nature of escape analysis,
in order to get the benefits, I had to modify
almost all such functions. The remaining functions
are in racewalk and the backend. I would be happy
to update them as well in a separate CL.
This CL was created by manually updating the
function signatures and the directly impacted
bits of code. The callsites were then automatically
updated using a bespoke script:
https://gist.github.com/josharian/046b1be7aceae244de39
For ease of reviewing and future understanding,
this CL is also broken down into four CLs,
mailed separately, which show the manual
and the automated changes separately.
They are CLs 20990, 20991, 20992, and 20993.
Passes toolstash -cmp.
name old time/op new time/op delta
Template 335ms ± 5% 324ms ± 5% -3.35% (p=0.000 n=23+24)
Unicode 176ms ± 9% 165ms ± 6% -6.12% (p=0.000 n=23+24)
GoTypes 1.10s ± 4% 1.07s ± 2% -2.77% (p=0.000 n=24+24)
Compiler 5.31s ± 3% 5.15s ± 3% -2.95% (p=0.000 n=24+24)
MakeBash 41.6s ± 1% 41.7s ± 2% ~ (p=0.586 n=23+23)
name old alloc/op new alloc/op delta
Template 63.3MB ± 0% 62.4MB ± 0% -1.36% (p=0.000 n=25+23)
Unicode 42.4MB ± 0% 41.6MB ± 0% -1.99% (p=0.000 n=24+25)
GoTypes 220MB ± 0% 217MB ± 0% -1.11% (p=0.000 n=25+25)
Compiler 994MB ± 0% 973MB ± 0% -2.08% (p=0.000 n=24+25)
name old allocs/op new allocs/op delta
Template 681k ± 0% 574k ± 0% -15.71% (p=0.000 n=24+25)
Unicode 518k ± 0% 413k ± 0% -20.34% (p=0.000 n=25+24)
GoTypes 2.08M ± 0% 1.78M ± 0% -14.62% (p=0.000 n=25+25)
Compiler 9.26M ± 0% 7.64M ± 0% -17.48% (p=0.000 n=25+25)
name old text-bytes new text-bytes delta
HelloSize 578k ± 0% 578k ± 0% ~ (all samples are equal)
CmdGoSize 6.46M ± 0% 6.46M ± 0% ~ (all samples are equal)
name old data-bytes new data-bytes delta
HelloSize 128k ± 0% 128k ± 0% ~ (all samples are equal)
CmdGoSize 281k ± 0% 281k ± 0% ~ (all samples are equal)
name old exe-bytes new exe-bytes delta
HelloSize 921k ± 0% 921k ± 0% ~ (all samples are equal)
CmdGoSize 9.86M ± 0% 9.86M ± 0% ~ (all samples are equal)
Change-Id: I277d95bd56d51c166ef7f560647aeaa092f3f475
Reviewed-on: https://go-review.googlesource.com/20959
Reviewed-by: Dave Cheney <dave@cheney.net>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-03-20 08:03:31 -07:00
|
|
|
nr = defaultlit(nr, nl.Type)
|
2015-02-13 14:40:36 -05:00
|
|
|
n.Right = nr
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if nr.Type.Etype != TIDEAL {
|
cmd/compile: reduce use of **Node parameters
Escape analysis has a hard time with tree-like
structures (see #13493 and #14858).
This is unlikely to change.
As a result, when invoking a function that accepts
a **Node parameter, we usually allocate a *Node
on the heap. This happens a whole lot.
This CL changes functions from taking a **Node
to acting more like append: It both modifies
the input and returns a replacement for it.
Because of the cascading nature of escape analysis,
in order to get the benefits, I had to modify
almost all such functions. The remaining functions
are in racewalk and the backend. I would be happy
to update them as well in a separate CL.
This CL was created by manually updating the
function signatures and the directly impacted
bits of code. The callsites were then automatically
updated using a bespoke script:
https://gist.github.com/josharian/046b1be7aceae244de39
For ease of reviewing and future understanding,
this CL is also broken down into four CLs,
mailed separately, which show the manual
and the automated changes separately.
They are CLs 20990, 20991, 20992, and 20993.
Passes toolstash -cmp.
name old time/op new time/op delta
Template 335ms ± 5% 324ms ± 5% -3.35% (p=0.000 n=23+24)
Unicode 176ms ± 9% 165ms ± 6% -6.12% (p=0.000 n=23+24)
GoTypes 1.10s ± 4% 1.07s ± 2% -2.77% (p=0.000 n=24+24)
Compiler 5.31s ± 3% 5.15s ± 3% -2.95% (p=0.000 n=24+24)
MakeBash 41.6s ± 1% 41.7s ± 2% ~ (p=0.586 n=23+23)
name old alloc/op new alloc/op delta
Template 63.3MB ± 0% 62.4MB ± 0% -1.36% (p=0.000 n=25+23)
Unicode 42.4MB ± 0% 41.6MB ± 0% -1.99% (p=0.000 n=24+25)
GoTypes 220MB ± 0% 217MB ± 0% -1.11% (p=0.000 n=25+25)
Compiler 994MB ± 0% 973MB ± 0% -2.08% (p=0.000 n=24+25)
name old allocs/op new allocs/op delta
Template 681k ± 0% 574k ± 0% -15.71% (p=0.000 n=24+25)
Unicode 518k ± 0% 413k ± 0% -20.34% (p=0.000 n=25+24)
GoTypes 2.08M ± 0% 1.78M ± 0% -14.62% (p=0.000 n=25+25)
Compiler 9.26M ± 0% 7.64M ± 0% -17.48% (p=0.000 n=25+25)
name old text-bytes new text-bytes delta
HelloSize 578k ± 0% 578k ± 0% ~ (all samples are equal)
CmdGoSize 6.46M ± 0% 6.46M ± 0% ~ (all samples are equal)
name old data-bytes new data-bytes delta
HelloSize 128k ± 0% 128k ± 0% ~ (all samples are equal)
CmdGoSize 281k ± 0% 281k ± 0% ~ (all samples are equal)
name old exe-bytes new exe-bytes delta
HelloSize 921k ± 0% 921k ± 0% ~ (all samples are equal)
CmdGoSize 9.86M ± 0% 9.86M ± 0% ~ (all samples are equal)
Change-Id: I277d95bd56d51c166ef7f560647aeaa092f3f475
Reviewed-on: https://go-review.googlesource.com/20959
Reviewed-by: Dave Cheney <dave@cheney.net>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-03-20 08:03:31 -07:00
|
|
|
nl = defaultlit(nl, nr.Type)
|
2015-02-13 14:40:36 -05:00
|
|
|
n.Left = nl
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if nl.Type.Etype != nr.Type.Etype {
|
|
|
|
|
goto illegal
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-24 21:38:58 +02:00
|
|
|
// right must be unsigned.
|
2015-02-13 14:40:36 -05:00
|
|
|
// left can be ideal.
|
2015-04-01 09:38:44 -07:00
|
|
|
case OLSH, ORSH:
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
nr = defaultlit(nr, types.Types[TUINT])
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
n.Right = nr
|
2016-03-30 15:09:25 -07:00
|
|
|
if nr.Type != nil && (nr.Type.IsSigned() || !nr.Type.IsInteger()) {
|
2015-02-13 14:40:36 -05:00
|
|
|
goto illegal
|
|
|
|
|
}
|
2015-05-27 00:47:05 -04:00
|
|
|
if nl.Val().Ctype() != CTRUNE {
|
|
|
|
|
nl.SetVal(toint(nl.Val()))
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
2015-05-27 00:47:05 -04:00
|
|
|
nr.SetVal(toint(nr.Val()))
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// copy numeric value to avoid modifying
|
|
|
|
|
// n->left, in case someone still refers to it (e.g. iota).
|
2018-03-31 16:49:07 -07:00
|
|
|
v = copyval(nl.Val())
|
2015-05-27 00:47:05 -04:00
|
|
|
rv = nr.Val()
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
// convert to common ideal
|
2015-05-26 22:50:45 -04:00
|
|
|
if v.Ctype() == CTCPLX || rv.Ctype() == CTCPLX {
|
2015-02-13 14:40:36 -05:00
|
|
|
v = tocplx(v)
|
|
|
|
|
rv = tocplx(rv)
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-26 22:50:45 -04:00
|
|
|
if v.Ctype() == CTFLT || rv.Ctype() == CTFLT {
|
2015-02-13 14:40:36 -05:00
|
|
|
v = toflt(v)
|
|
|
|
|
rv = toflt(rv)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Rune and int turns into rune.
|
2015-05-26 22:50:45 -04:00
|
|
|
if v.Ctype() == CTRUNE && rv.Ctype() == CTINT {
|
|
|
|
|
i := new(Mpint)
|
2016-03-20 13:55:42 -07:00
|
|
|
i.Set(rv.U.(*Mpint))
|
2015-05-26 22:50:45 -04:00
|
|
|
i.Rune = true
|
|
|
|
|
rv.U = i
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
2015-05-26 22:50:45 -04:00
|
|
|
if v.Ctype() == CTINT && rv.Ctype() == CTRUNE {
|
2015-02-13 14:40:36 -05:00
|
|
|
if n.Op == OLSH || n.Op == ORSH {
|
2015-05-26 22:50:45 -04:00
|
|
|
i := new(Mpint)
|
2016-03-20 13:55:42 -07:00
|
|
|
i.Set(rv.U.(*Mpint))
|
2015-05-26 22:50:45 -04:00
|
|
|
rv.U = i
|
2015-02-13 14:40:36 -05:00
|
|
|
} else {
|
2015-05-26 22:50:45 -04:00
|
|
|
i := new(Mpint)
|
2016-03-20 13:55:42 -07:00
|
|
|
i.Set(v.U.(*Mpint))
|
2015-05-26 22:50:45 -04:00
|
|
|
i.Rune = true
|
|
|
|
|
v.U = i
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-26 22:50:45 -04:00
|
|
|
if v.Ctype() != rv.Ctype() {
|
2015-02-13 14:40:36 -05:00
|
|
|
// Use of undefined name as constant?
|
2015-05-26 22:50:45 -04:00
|
|
|
if (v.Ctype() == 0 || rv.Ctype() == 0) && nerrors > 0 {
|
2015-02-13 14:40:36 -05:00
|
|
|
return
|
|
|
|
|
}
|
2015-08-30 23:10:03 +02:00
|
|
|
Fatalf("constant type mismatch %v(%d) %v(%d)", nl.Type, v.Ctype(), nr.Type, rv.Ctype())
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2017-04-07 08:31:52 +02:00
|
|
|
// rune values are int values for the purpose of constant folding.
|
|
|
|
|
ctype = uint32(v.Ctype())
|
|
|
|
|
if ctype == CTRUNE_ {
|
|
|
|
|
ctype = CTINT_
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-13 14:40:36 -05:00
|
|
|
// run op
|
2017-04-07 08:31:52 +02:00
|
|
|
switch uint32(n.Op)<<16 | ctype {
|
2015-02-13 14:40:36 -05:00
|
|
|
default:
|
|
|
|
|
goto illegal
|
|
|
|
|
|
2017-04-07 08:31:52 +02:00
|
|
|
case OADD_ | CTINT_:
|
2016-03-23 11:07:20 -07:00
|
|
|
v.U.(*Mpint).Add(rv.U.(*Mpint))
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2017-04-07 08:31:52 +02:00
|
|
|
case OSUB_ | CTINT_:
|
2016-03-20 13:55:42 -07:00
|
|
|
v.U.(*Mpint).Sub(rv.U.(*Mpint))
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2017-04-07 08:31:52 +02:00
|
|
|
case OMUL_ | CTINT_:
|
2016-03-20 13:55:42 -07:00
|
|
|
v.U.(*Mpint).Mul(rv.U.(*Mpint))
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2017-04-07 08:31:52 +02:00
|
|
|
case ODIV_ | CTINT_:
|
2016-03-20 13:55:42 -07:00
|
|
|
if rv.U.(*Mpint).CmpInt64(0) == 0 {
|
2016-09-15 15:45:10 +10:00
|
|
|
yyerror("division by zero")
|
2016-03-20 13:55:42 -07:00
|
|
|
v.U.(*Mpint).SetOverflow()
|
2015-02-13 14:40:36 -05:00
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-20 13:55:42 -07:00
|
|
|
v.U.(*Mpint).Quo(rv.U.(*Mpint))
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2017-04-07 08:31:52 +02:00
|
|
|
case OMOD_ | CTINT_:
|
2016-03-20 13:55:42 -07:00
|
|
|
if rv.U.(*Mpint).CmpInt64(0) == 0 {
|
2016-09-15 15:45:10 +10:00
|
|
|
yyerror("division by zero")
|
2016-03-20 13:55:42 -07:00
|
|
|
v.U.(*Mpint).SetOverflow()
|
2015-02-13 14:40:36 -05:00
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-20 13:55:42 -07:00
|
|
|
v.U.(*Mpint).Rem(rv.U.(*Mpint))
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2017-04-07 08:31:52 +02:00
|
|
|
case OLSH_ | CTINT_:
|
2016-03-20 13:55:42 -07:00
|
|
|
v.U.(*Mpint).Lsh(rv.U.(*Mpint))
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2017-04-07 08:31:52 +02:00
|
|
|
case ORSH_ | CTINT_:
|
2016-03-20 13:55:42 -07:00
|
|
|
v.U.(*Mpint).Rsh(rv.U.(*Mpint))
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2017-04-07 08:31:52 +02:00
|
|
|
case OOR_ | CTINT_:
|
2016-03-20 13:55:42 -07:00
|
|
|
v.U.(*Mpint).Or(rv.U.(*Mpint))
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2017-04-07 08:31:52 +02:00
|
|
|
case OAND_ | CTINT_:
|
2016-03-20 13:55:42 -07:00
|
|
|
v.U.(*Mpint).And(rv.U.(*Mpint))
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2017-04-07 08:31:52 +02:00
|
|
|
case OANDNOT_ | CTINT_:
|
2016-03-20 13:55:42 -07:00
|
|
|
v.U.(*Mpint).AndNot(rv.U.(*Mpint))
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2017-04-07 08:31:52 +02:00
|
|
|
case OXOR_ | CTINT_:
|
2016-03-20 13:55:42 -07:00
|
|
|
v.U.(*Mpint).Xor(rv.U.(*Mpint))
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2015-09-24 23:21:18 +02:00
|
|
|
case OADD_ | CTFLT_:
|
2016-03-20 13:55:42 -07:00
|
|
|
v.U.(*Mpflt).Add(rv.U.(*Mpflt))
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2015-09-24 23:21:18 +02:00
|
|
|
case OSUB_ | CTFLT_:
|
2016-03-20 13:55:42 -07:00
|
|
|
v.U.(*Mpflt).Sub(rv.U.(*Mpflt))
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2015-09-24 23:21:18 +02:00
|
|
|
case OMUL_ | CTFLT_:
|
2016-03-20 13:55:42 -07:00
|
|
|
v.U.(*Mpflt).Mul(rv.U.(*Mpflt))
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2015-09-24 23:21:18 +02:00
|
|
|
case ODIV_ | CTFLT_:
|
2016-03-20 13:55:42 -07:00
|
|
|
if rv.U.(*Mpflt).CmpFloat64(0) == 0 {
|
2016-09-15 15:45:10 +10:00
|
|
|
yyerror("division by zero")
|
2016-03-20 13:55:42 -07:00
|
|
|
v.U.(*Mpflt).SetFloat64(1.0)
|
2015-02-13 14:40:36 -05:00
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-20 13:55:42 -07:00
|
|
|
v.U.(*Mpflt).Quo(rv.U.(*Mpflt))
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2016-09-24 21:38:58 +02:00
|
|
|
// The default case above would print 'ideal % ideal',
|
2015-02-13 14:40:36 -05:00
|
|
|
// which is not quite an ideal error.
|
2015-09-24 23:21:18 +02:00
|
|
|
case OMOD_ | CTFLT_:
|
2017-02-27 19:56:38 +02:00
|
|
|
if !n.Diag() {
|
2016-09-15 15:45:10 +10:00
|
|
|
yyerror("illegal constant expression: floating-point %% operation")
|
2017-02-27 19:56:38 +02:00
|
|
|
n.SetDiag(true)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
2015-09-24 23:21:18 +02:00
|
|
|
case OADD_ | CTCPLX_:
|
2016-03-20 13:55:42 -07:00
|
|
|
v.U.(*Mpcplx).Real.Add(&rv.U.(*Mpcplx).Real)
|
|
|
|
|
v.U.(*Mpcplx).Imag.Add(&rv.U.(*Mpcplx).Imag)
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2015-09-24 23:21:18 +02:00
|
|
|
case OSUB_ | CTCPLX_:
|
2016-03-20 13:55:42 -07:00
|
|
|
v.U.(*Mpcplx).Real.Sub(&rv.U.(*Mpcplx).Real)
|
|
|
|
|
v.U.(*Mpcplx).Imag.Sub(&rv.U.(*Mpcplx).Imag)
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2015-09-24 23:21:18 +02:00
|
|
|
case OMUL_ | CTCPLX_:
|
2018-04-06 09:44:29 -07:00
|
|
|
v.U.(*Mpcplx).Mul(rv.U.(*Mpcplx))
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2015-09-24 23:21:18 +02:00
|
|
|
case ODIV_ | CTCPLX_:
|
2018-04-06 09:44:29 -07:00
|
|
|
if !v.U.(*Mpcplx).Div(rv.U.(*Mpcplx)) {
|
2016-09-15 15:45:10 +10:00
|
|
|
yyerror("complex division by zero")
|
2016-03-20 13:55:42 -07:00
|
|
|
rv.U.(*Mpcplx).Real.SetFloat64(1.0)
|
|
|
|
|
rv.U.(*Mpcplx).Imag.SetFloat64(0.0)
|
2015-02-13 14:40:36 -05:00
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-24 23:21:18 +02:00
|
|
|
case OEQ_ | CTNIL_:
|
2015-02-13 14:40:36 -05:00
|
|
|
goto settrue
|
|
|
|
|
|
2015-09-24 23:21:18 +02:00
|
|
|
case ONE_ | CTNIL_:
|
2015-02-13 14:40:36 -05:00
|
|
|
goto setfalse
|
|
|
|
|
|
2017-04-07 08:31:52 +02:00
|
|
|
case OEQ_ | CTINT_:
|
2016-03-20 13:55:42 -07:00
|
|
|
if v.U.(*Mpint).Cmp(rv.U.(*Mpint)) == 0 {
|
2015-02-13 14:40:36 -05:00
|
|
|
goto settrue
|
|
|
|
|
}
|
|
|
|
|
goto setfalse
|
|
|
|
|
|
2017-04-07 08:31:52 +02:00
|
|
|
case ONE_ | CTINT_:
|
2016-03-20 13:55:42 -07:00
|
|
|
if v.U.(*Mpint).Cmp(rv.U.(*Mpint)) != 0 {
|
2015-02-13 14:40:36 -05:00
|
|
|
goto settrue
|
|
|
|
|
}
|
|
|
|
|
goto setfalse
|
|
|
|
|
|
2017-04-07 08:31:52 +02:00
|
|
|
case OLT_ | CTINT_:
|
2016-03-20 13:55:42 -07:00
|
|
|
if v.U.(*Mpint).Cmp(rv.U.(*Mpint)) < 0 {
|
2015-02-13 14:40:36 -05:00
|
|
|
goto settrue
|
|
|
|
|
}
|
|
|
|
|
goto setfalse
|
|
|
|
|
|
2017-04-07 08:31:52 +02:00
|
|
|
case OLE_ | CTINT_:
|
2016-03-20 13:55:42 -07:00
|
|
|
if v.U.(*Mpint).Cmp(rv.U.(*Mpint)) <= 0 {
|
2015-02-13 14:40:36 -05:00
|
|
|
goto settrue
|
|
|
|
|
}
|
|
|
|
|
goto setfalse
|
|
|
|
|
|
2017-04-07 08:31:52 +02:00
|
|
|
case OGE_ | CTINT_:
|
2016-03-20 13:55:42 -07:00
|
|
|
if v.U.(*Mpint).Cmp(rv.U.(*Mpint)) >= 0 {
|
2015-02-13 14:40:36 -05:00
|
|
|
goto settrue
|
|
|
|
|
}
|
|
|
|
|
goto setfalse
|
|
|
|
|
|
2017-04-07 08:31:52 +02:00
|
|
|
case OGT_ | CTINT_:
|
2016-03-20 13:55:42 -07:00
|
|
|
if v.U.(*Mpint).Cmp(rv.U.(*Mpint)) > 0 {
|
2015-02-13 14:40:36 -05:00
|
|
|
goto settrue
|
|
|
|
|
}
|
|
|
|
|
goto setfalse
|
|
|
|
|
|
2015-09-24 23:21:18 +02:00
|
|
|
case OEQ_ | CTFLT_:
|
2016-03-20 13:55:42 -07:00
|
|
|
if v.U.(*Mpflt).Cmp(rv.U.(*Mpflt)) == 0 {
|
2015-02-13 14:40:36 -05:00
|
|
|
goto settrue
|
|
|
|
|
}
|
|
|
|
|
goto setfalse
|
|
|
|
|
|
2015-09-24 23:21:18 +02:00
|
|
|
case ONE_ | CTFLT_:
|
2016-03-20 13:55:42 -07:00
|
|
|
if v.U.(*Mpflt).Cmp(rv.U.(*Mpflt)) != 0 {
|
2015-02-13 14:40:36 -05:00
|
|
|
goto settrue
|
|
|
|
|
}
|
|
|
|
|
goto setfalse
|
|
|
|
|
|
2015-09-24 23:21:18 +02:00
|
|
|
case OLT_ | CTFLT_:
|
2016-03-20 13:55:42 -07:00
|
|
|
if v.U.(*Mpflt).Cmp(rv.U.(*Mpflt)) < 0 {
|
2015-02-13 14:40:36 -05:00
|
|
|
goto settrue
|
|
|
|
|
}
|
|
|
|
|
goto setfalse
|
|
|
|
|
|
2015-09-24 23:21:18 +02:00
|
|
|
case OLE_ | CTFLT_:
|
2016-03-20 13:55:42 -07:00
|
|
|
if v.U.(*Mpflt).Cmp(rv.U.(*Mpflt)) <= 0 {
|
2015-02-13 14:40:36 -05:00
|
|
|
goto settrue
|
|
|
|
|
}
|
|
|
|
|
goto setfalse
|
|
|
|
|
|
2015-09-24 23:21:18 +02:00
|
|
|
case OGE_ | CTFLT_:
|
2016-03-20 13:55:42 -07:00
|
|
|
if v.U.(*Mpflt).Cmp(rv.U.(*Mpflt)) >= 0 {
|
2015-02-13 14:40:36 -05:00
|
|
|
goto settrue
|
|
|
|
|
}
|
|
|
|
|
goto setfalse
|
|
|
|
|
|
2015-09-24 23:21:18 +02:00
|
|
|
case OGT_ | CTFLT_:
|
2016-03-20 13:55:42 -07:00
|
|
|
if v.U.(*Mpflt).Cmp(rv.U.(*Mpflt)) > 0 {
|
2015-02-13 14:40:36 -05:00
|
|
|
goto settrue
|
|
|
|
|
}
|
|
|
|
|
goto setfalse
|
|
|
|
|
|
2015-09-24 23:21:18 +02:00
|
|
|
case OEQ_ | CTCPLX_:
|
2016-03-20 13:55:42 -07:00
|
|
|
if v.U.(*Mpcplx).Real.Cmp(&rv.U.(*Mpcplx).Real) == 0 && v.U.(*Mpcplx).Imag.Cmp(&rv.U.(*Mpcplx).Imag) == 0 {
|
2015-02-13 14:40:36 -05:00
|
|
|
goto settrue
|
|
|
|
|
}
|
|
|
|
|
goto setfalse
|
|
|
|
|
|
2015-09-24 23:21:18 +02:00
|
|
|
case ONE_ | CTCPLX_:
|
2016-03-20 13:55:42 -07:00
|
|
|
if v.U.(*Mpcplx).Real.Cmp(&rv.U.(*Mpcplx).Real) != 0 || v.U.(*Mpcplx).Imag.Cmp(&rv.U.(*Mpcplx).Imag) != 0 {
|
2015-02-13 14:40:36 -05:00
|
|
|
goto settrue
|
|
|
|
|
}
|
|
|
|
|
goto setfalse
|
|
|
|
|
|
2015-09-24 23:21:18 +02:00
|
|
|
case OEQ_ | CTSTR_:
|
2015-09-17 21:01:29 +02:00
|
|
|
if strlit(nl) == strlit(nr) {
|
2015-02-13 14:40:36 -05:00
|
|
|
goto settrue
|
|
|
|
|
}
|
|
|
|
|
goto setfalse
|
|
|
|
|
|
2015-09-24 23:21:18 +02:00
|
|
|
case ONE_ | CTSTR_:
|
2015-09-17 21:01:29 +02:00
|
|
|
if strlit(nl) != strlit(nr) {
|
2015-02-13 14:40:36 -05:00
|
|
|
goto settrue
|
|
|
|
|
}
|
|
|
|
|
goto setfalse
|
|
|
|
|
|
2015-09-24 23:21:18 +02:00
|
|
|
case OLT_ | CTSTR_:
|
2015-09-17 21:01:29 +02:00
|
|
|
if strlit(nl) < strlit(nr) {
|
2015-02-13 14:40:36 -05:00
|
|
|
goto settrue
|
|
|
|
|
}
|
|
|
|
|
goto setfalse
|
|
|
|
|
|
2015-09-24 23:21:18 +02:00
|
|
|
case OLE_ | CTSTR_:
|
2015-09-17 21:01:29 +02:00
|
|
|
if strlit(nl) <= strlit(nr) {
|
2015-02-13 14:40:36 -05:00
|
|
|
goto settrue
|
|
|
|
|
}
|
|
|
|
|
goto setfalse
|
|
|
|
|
|
2015-09-24 23:21:18 +02:00
|
|
|
case OGE_ | CTSTR_:
|
2015-09-17 21:01:29 +02:00
|
|
|
if strlit(nl) >= strlit(nr) {
|
2015-02-13 14:40:36 -05:00
|
|
|
goto settrue
|
|
|
|
|
}
|
|
|
|
|
goto setfalse
|
|
|
|
|
|
2015-09-24 23:21:18 +02:00
|
|
|
case OGT_ | CTSTR_:
|
2015-09-17 21:01:29 +02:00
|
|
|
if strlit(nl) > strlit(nr) {
|
2015-02-13 14:40:36 -05:00
|
|
|
goto settrue
|
|
|
|
|
}
|
|
|
|
|
goto setfalse
|
|
|
|
|
|
2015-09-24 23:21:18 +02:00
|
|
|
case OOROR_ | CTBOOL_:
|
2015-05-14 17:57:42 -07:00
|
|
|
if v.U.(bool) || rv.U.(bool) {
|
2015-02-13 14:40:36 -05:00
|
|
|
goto settrue
|
|
|
|
|
}
|
|
|
|
|
goto setfalse
|
|
|
|
|
|
2015-09-24 23:21:18 +02:00
|
|
|
case OANDAND_ | CTBOOL_:
|
2015-05-14 17:57:42 -07:00
|
|
|
if v.U.(bool) && rv.U.(bool) {
|
2015-02-13 14:40:36 -05:00
|
|
|
goto settrue
|
|
|
|
|
}
|
|
|
|
|
goto setfalse
|
|
|
|
|
|
2015-09-24 23:21:18 +02:00
|
|
|
case OEQ_ | CTBOOL_:
|
2015-05-14 17:57:42 -07:00
|
|
|
if v.U.(bool) == rv.U.(bool) {
|
2015-02-13 14:40:36 -05:00
|
|
|
goto settrue
|
|
|
|
|
}
|
|
|
|
|
goto setfalse
|
|
|
|
|
|
2015-09-24 23:21:18 +02:00
|
|
|
case ONE_ | CTBOOL_:
|
2015-05-14 17:57:42 -07:00
|
|
|
if v.U.(bool) != rv.U.(bool) {
|
2015-02-13 14:40:36 -05:00
|
|
|
goto settrue
|
|
|
|
|
}
|
|
|
|
|
goto setfalse
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ret:
|
2018-03-31 16:49:07 -07:00
|
|
|
setconst(n, v)
|
2015-02-13 14:40:36 -05:00
|
|
|
return
|
|
|
|
|
|
|
|
|
|
settrue:
|
2018-03-31 16:49:07 -07:00
|
|
|
setconst(n, Val{true})
|
2015-02-13 14:40:36 -05:00
|
|
|
return
|
|
|
|
|
|
|
|
|
|
setfalse:
|
2018-03-31 16:49:07 -07:00
|
|
|
setconst(n, Val{false})
|
2015-02-13 14:40:36 -05:00
|
|
|
return
|
|
|
|
|
|
|
|
|
|
illegal:
|
2017-02-27 19:56:38 +02:00
|
|
|
if !n.Diag() {
|
2016-09-15 15:45:10 +10:00
|
|
|
yyerror("illegal constant expression: %v %v %v", nl.Type, n.Op, nr.Type)
|
2017-02-27 19:56:38 +02:00
|
|
|
n.SetDiag(true)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-31 16:49:07 -07:00
|
|
|
// setconst rewrites n as an OLITERAL with value v.
|
|
|
|
|
func setconst(n *Node, v Val) {
|
|
|
|
|
// Ensure n.Orig still points to a semantically-equivalent
|
|
|
|
|
// expression after we rewrite n into a constant.
|
|
|
|
|
if n.Orig == n {
|
2018-09-20 15:22:33 -07:00
|
|
|
n.Orig = n.sepcopy()
|
2018-03-31 16:49:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*n = Node{
|
|
|
|
|
Op: OLITERAL,
|
|
|
|
|
Pos: n.Pos,
|
|
|
|
|
Orig: n.Orig,
|
|
|
|
|
Type: n.Type,
|
|
|
|
|
Xoffset: BADWIDTH,
|
|
|
|
|
}
|
|
|
|
|
n.SetVal(v)
|
|
|
|
|
|
|
|
|
|
// Check range.
|
|
|
|
|
lno := setlineno(n)
|
|
|
|
|
overflow(v, n.Type)
|
|
|
|
|
lineno = lno
|
|
|
|
|
|
|
|
|
|
// Truncate precision for non-ideal float.
|
|
|
|
|
if v.Ctype() == CTFLT && n.Type.Etype != TIDEAL {
|
|
|
|
|
n.SetVal(Val{truncfltlit(v.U.(*Mpflt), n.Type)})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func setintconst(n *Node, v int64) {
|
|
|
|
|
u := new(Mpint)
|
|
|
|
|
u.SetInt64(v)
|
|
|
|
|
setconst(n, Val{u})
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-31 15:53:21 -07:00
|
|
|
// nodlit returns a new untyped constant with value v.
|
2015-02-13 14:40:36 -05:00
|
|
|
func nodlit(v Val) *Node {
|
2016-09-16 11:00:54 +10:00
|
|
|
n := nod(OLITERAL, nil, nil)
|
2015-05-27 00:47:05 -04:00
|
|
|
n.SetVal(v)
|
2015-05-26 22:50:45 -04:00
|
|
|
switch v.Ctype() {
|
2015-02-13 14:40:36 -05:00
|
|
|
default:
|
2015-08-30 23:10:03 +02:00
|
|
|
Fatalf("nodlit ctype %d", v.Ctype())
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
case CTSTR:
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
n.Type = types.Idealstring
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
case CTBOOL:
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
n.Type = types.Idealbool
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2015-04-01 09:38:44 -07:00
|
|
|
case CTINT, CTRUNE, CTFLT, CTCPLX:
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
n.Type = types.Types[TIDEAL]
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
case CTNIL:
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
n.Type = types.Types[TNIL]
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return n
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// idealkind returns a constant kind like consttype
|
|
|
|
|
// but for an arbitrary "ideal" (untyped constant) expression.
|
2015-10-26 16:00:59 -07:00
|
|
|
func idealkind(n *Node) Ctype {
|
2016-04-01 13:36:24 -07:00
|
|
|
if n == nil || !n.Type.IsUntyped() {
|
2015-02-13 14:40:36 -05:00
|
|
|
return CTxxx
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch n.Op {
|
|
|
|
|
default:
|
|
|
|
|
return CTxxx
|
|
|
|
|
|
|
|
|
|
case OLITERAL:
|
2015-10-26 16:00:59 -07:00
|
|
|
return n.Val().Ctype()
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
// numeric kinds.
|
|
|
|
|
case OADD,
|
|
|
|
|
OAND,
|
|
|
|
|
OANDNOT,
|
|
|
|
|
OCOM,
|
|
|
|
|
ODIV,
|
|
|
|
|
OMINUS,
|
|
|
|
|
OMOD,
|
|
|
|
|
OMUL,
|
|
|
|
|
OSUB,
|
|
|
|
|
OXOR,
|
|
|
|
|
OOR,
|
|
|
|
|
OPLUS:
|
2015-02-23 16:07:24 -05:00
|
|
|
k1 := idealkind(n.Left)
|
|
|
|
|
k2 := idealkind(n.Right)
|
2015-02-13 14:40:36 -05:00
|
|
|
if k1 > k2 {
|
|
|
|
|
return k1
|
|
|
|
|
} else {
|
|
|
|
|
return k2
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-01 09:38:44 -07:00
|
|
|
case OREAL, OIMAG:
|
2015-02-13 14:40:36 -05:00
|
|
|
return CTFLT
|
|
|
|
|
|
|
|
|
|
case OCOMPLEX:
|
|
|
|
|
return CTCPLX
|
|
|
|
|
|
|
|
|
|
case OADDSTR:
|
|
|
|
|
return CTSTR
|
|
|
|
|
|
|
|
|
|
case OANDAND,
|
|
|
|
|
OEQ,
|
|
|
|
|
OGE,
|
|
|
|
|
OGT,
|
|
|
|
|
OLE,
|
|
|
|
|
OLT,
|
|
|
|
|
ONE,
|
|
|
|
|
ONOT,
|
|
|
|
|
OOROR,
|
|
|
|
|
OCMPSTR,
|
|
|
|
|
OCMPIFACE:
|
|
|
|
|
return CTBOOL
|
|
|
|
|
|
|
|
|
|
// shifts (beware!).
|
2015-04-01 09:38:44 -07:00
|
|
|
case OLSH, ORSH:
|
2015-02-13 14:40:36 -05:00
|
|
|
return idealkind(n.Left)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
cmd/compile: reduce use of **Node parameters
Escape analysis has a hard time with tree-like
structures (see #13493 and #14858).
This is unlikely to change.
As a result, when invoking a function that accepts
a **Node parameter, we usually allocate a *Node
on the heap. This happens a whole lot.
This CL changes functions from taking a **Node
to acting more like append: It both modifies
the input and returns a replacement for it.
Because of the cascading nature of escape analysis,
in order to get the benefits, I had to modify
almost all such functions. The remaining functions
are in racewalk and the backend. I would be happy
to update them as well in a separate CL.
This CL was created by manually updating the
function signatures and the directly impacted
bits of code. The callsites were then automatically
updated using a bespoke script:
https://gist.github.com/josharian/046b1be7aceae244de39
For ease of reviewing and future understanding,
this CL is also broken down into four CLs,
mailed separately, which show the manual
and the automated changes separately.
They are CLs 20990, 20991, 20992, and 20993.
Passes toolstash -cmp.
name old time/op new time/op delta
Template 335ms ± 5% 324ms ± 5% -3.35% (p=0.000 n=23+24)
Unicode 176ms ± 9% 165ms ± 6% -6.12% (p=0.000 n=23+24)
GoTypes 1.10s ± 4% 1.07s ± 2% -2.77% (p=0.000 n=24+24)
Compiler 5.31s ± 3% 5.15s ± 3% -2.95% (p=0.000 n=24+24)
MakeBash 41.6s ± 1% 41.7s ± 2% ~ (p=0.586 n=23+23)
name old alloc/op new alloc/op delta
Template 63.3MB ± 0% 62.4MB ± 0% -1.36% (p=0.000 n=25+23)
Unicode 42.4MB ± 0% 41.6MB ± 0% -1.99% (p=0.000 n=24+25)
GoTypes 220MB ± 0% 217MB ± 0% -1.11% (p=0.000 n=25+25)
Compiler 994MB ± 0% 973MB ± 0% -2.08% (p=0.000 n=24+25)
name old allocs/op new allocs/op delta
Template 681k ± 0% 574k ± 0% -15.71% (p=0.000 n=24+25)
Unicode 518k ± 0% 413k ± 0% -20.34% (p=0.000 n=25+24)
GoTypes 2.08M ± 0% 1.78M ± 0% -14.62% (p=0.000 n=25+25)
Compiler 9.26M ± 0% 7.64M ± 0% -17.48% (p=0.000 n=25+25)
name old text-bytes new text-bytes delta
HelloSize 578k ± 0% 578k ± 0% ~ (all samples are equal)
CmdGoSize 6.46M ± 0% 6.46M ± 0% ~ (all samples are equal)
name old data-bytes new data-bytes delta
HelloSize 128k ± 0% 128k ± 0% ~ (all samples are equal)
CmdGoSize 281k ± 0% 281k ± 0% ~ (all samples are equal)
name old exe-bytes new exe-bytes delta
HelloSize 921k ± 0% 921k ± 0% ~ (all samples are equal)
CmdGoSize 9.86M ± 0% 9.86M ± 0% ~ (all samples are equal)
Change-Id: I277d95bd56d51c166ef7f560647aeaa092f3f475
Reviewed-on: https://go-review.googlesource.com/20959
Reviewed-by: Dave Cheney <dave@cheney.net>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-03-20 08:03:31 -07:00
|
|
|
// The result of defaultlit MUST be assigned back to n, e.g.
|
|
|
|
|
// n.Left = defaultlit(n.Left, t)
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
func defaultlit(n *Node, t *types.Type) *Node {
|
2016-03-17 12:24:11 -07:00
|
|
|
return defaultlitreuse(n, t, noReuse)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The result of defaultlitreuse MUST be assigned back to n, e.g.
|
|
|
|
|
// n.Left = defaultlitreuse(n.Left, t, reuse)
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
func defaultlitreuse(n *Node, t *types.Type, reuse canReuseNode) *Node {
|
2016-04-01 13:36:24 -07:00
|
|
|
if n == nil || !n.Type.IsUntyped() {
|
cmd/compile: reduce use of **Node parameters
Escape analysis has a hard time with tree-like
structures (see #13493 and #14858).
This is unlikely to change.
As a result, when invoking a function that accepts
a **Node parameter, we usually allocate a *Node
on the heap. This happens a whole lot.
This CL changes functions from taking a **Node
to acting more like append: It both modifies
the input and returns a replacement for it.
Because of the cascading nature of escape analysis,
in order to get the benefits, I had to modify
almost all such functions. The remaining functions
are in racewalk and the backend. I would be happy
to update them as well in a separate CL.
This CL was created by manually updating the
function signatures and the directly impacted
bits of code. The callsites were then automatically
updated using a bespoke script:
https://gist.github.com/josharian/046b1be7aceae244de39
For ease of reviewing and future understanding,
this CL is also broken down into four CLs,
mailed separately, which show the manual
and the automated changes separately.
They are CLs 20990, 20991, 20992, and 20993.
Passes toolstash -cmp.
name old time/op new time/op delta
Template 335ms ± 5% 324ms ± 5% -3.35% (p=0.000 n=23+24)
Unicode 176ms ± 9% 165ms ± 6% -6.12% (p=0.000 n=23+24)
GoTypes 1.10s ± 4% 1.07s ± 2% -2.77% (p=0.000 n=24+24)
Compiler 5.31s ± 3% 5.15s ± 3% -2.95% (p=0.000 n=24+24)
MakeBash 41.6s ± 1% 41.7s ± 2% ~ (p=0.586 n=23+23)
name old alloc/op new alloc/op delta
Template 63.3MB ± 0% 62.4MB ± 0% -1.36% (p=0.000 n=25+23)
Unicode 42.4MB ± 0% 41.6MB ± 0% -1.99% (p=0.000 n=24+25)
GoTypes 220MB ± 0% 217MB ± 0% -1.11% (p=0.000 n=25+25)
Compiler 994MB ± 0% 973MB ± 0% -2.08% (p=0.000 n=24+25)
name old allocs/op new allocs/op delta
Template 681k ± 0% 574k ± 0% -15.71% (p=0.000 n=24+25)
Unicode 518k ± 0% 413k ± 0% -20.34% (p=0.000 n=25+24)
GoTypes 2.08M ± 0% 1.78M ± 0% -14.62% (p=0.000 n=25+25)
Compiler 9.26M ± 0% 7.64M ± 0% -17.48% (p=0.000 n=25+25)
name old text-bytes new text-bytes delta
HelloSize 578k ± 0% 578k ± 0% ~ (all samples are equal)
CmdGoSize 6.46M ± 0% 6.46M ± 0% ~ (all samples are equal)
name old data-bytes new data-bytes delta
HelloSize 128k ± 0% 128k ± 0% ~ (all samples are equal)
CmdGoSize 281k ± 0% 281k ± 0% ~ (all samples are equal)
name old exe-bytes new exe-bytes delta
HelloSize 921k ± 0% 921k ± 0% ~ (all samples are equal)
CmdGoSize 9.86M ± 0% 9.86M ± 0% ~ (all samples are equal)
Change-Id: I277d95bd56d51c166ef7f560647aeaa092f3f475
Reviewed-on: https://go-review.googlesource.com/20959
Reviewed-by: Dave Cheney <dave@cheney.net>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-03-20 08:03:31 -07:00
|
|
|
return n
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2016-03-17 12:24:11 -07:00
|
|
|
if n.Op == OLITERAL && !reuse {
|
2018-09-20 15:22:33 -07:00
|
|
|
n = n.rawcopy()
|
2016-03-17 12:24:11 -07:00
|
|
|
reuse = true
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2016-03-02 17:34:42 -08:00
|
|
|
lno := setlineno(n)
|
2015-02-23 16:07:24 -05:00
|
|
|
ctype := idealkind(n)
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
var t1 *types.Type
|
2015-02-13 14:40:36 -05:00
|
|
|
switch ctype {
|
|
|
|
|
default:
|
|
|
|
|
if t != nil {
|
2016-03-23 08:51:38 -07:00
|
|
|
return convlit(n, t)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2017-10-20 11:56:31 +01:00
|
|
|
switch n.Val().Ctype() {
|
|
|
|
|
case CTNIL:
|
2016-03-02 17:34:42 -08:00
|
|
|
lineno = lno
|
2017-02-27 19:56:38 +02:00
|
|
|
if !n.Diag() {
|
2016-09-15 15:45:10 +10:00
|
|
|
yyerror("use of untyped nil")
|
2017-02-27 19:56:38 +02:00
|
|
|
n.SetDiag(true)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
n.Type = nil
|
2017-10-20 11:56:31 +01:00
|
|
|
case CTSTR:
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
t1 := types.Types[TSTRING]
|
2016-03-17 12:24:11 -07:00
|
|
|
n = convlit1(n, t1, false, reuse)
|
2017-10-20 11:56:31 +01:00
|
|
|
default:
|
|
|
|
|
yyerror("defaultlit: unknown literal: %v", n)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
2018-04-29 22:17:23 +09:00
|
|
|
lineno = lno
|
|
|
|
|
return n
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
case CTxxx:
|
2016-08-31 15:22:36 -07:00
|
|
|
Fatalf("defaultlit: idealkind is CTxxx: %+v", n)
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
case CTBOOL:
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
t1 := types.Types[TBOOL]
|
2016-03-30 14:56:08 -07:00
|
|
|
if t != nil && t.IsBoolean() {
|
2015-02-13 14:40:36 -05:00
|
|
|
t1 = t
|
|
|
|
|
}
|
2016-03-17 12:24:11 -07:00
|
|
|
n = convlit1(n, t1, false, reuse)
|
2018-04-29 22:17:23 +09:00
|
|
|
lineno = lno
|
|
|
|
|
return n
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
case CTINT:
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
t1 = types.Types[TINT]
|
2015-02-13 14:40:36 -05:00
|
|
|
case CTRUNE:
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
t1 = types.Runetype
|
2015-02-13 14:40:36 -05:00
|
|
|
case CTFLT:
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
t1 = types.Types[TFLOAT64]
|
2015-02-13 14:40:36 -05:00
|
|
|
case CTCPLX:
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
t1 = types.Types[TCOMPLEX128]
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2015-11-17 16:34:06 -05:00
|
|
|
// Note: n.Val().Ctype() can be CTxxx (not a constant) here
|
|
|
|
|
// in the case of an untyped non-constant value, like 1<<i.
|
|
|
|
|
v1 := n.Val()
|
2015-02-13 14:40:36 -05:00
|
|
|
if t != nil {
|
2016-03-30 15:09:25 -07:00
|
|
|
if t.IsInteger() {
|
2015-02-13 14:40:36 -05:00
|
|
|
t1 = t
|
2015-11-17 16:34:06 -05:00
|
|
|
v1 = toint(n.Val())
|
2016-03-30 15:09:25 -07:00
|
|
|
} else if t.IsFloat() {
|
2015-02-13 14:40:36 -05:00
|
|
|
t1 = t
|
2015-11-17 16:34:06 -05:00
|
|
|
v1 = toflt(n.Val())
|
2016-03-30 15:09:25 -07:00
|
|
|
} else if t.IsComplex() {
|
2015-02-13 14:40:36 -05:00
|
|
|
t1 = t
|
2015-11-17 16:34:06 -05:00
|
|
|
v1 = tocplx(n.Val())
|
|
|
|
|
}
|
|
|
|
|
if n.Val().Ctype() != CTxxx {
|
|
|
|
|
n.SetVal(v1)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-17 16:34:06 -05:00
|
|
|
if n.Val().Ctype() != CTxxx {
|
|
|
|
|
overflow(n.Val(), t1)
|
|
|
|
|
}
|
2016-03-17 12:24:11 -07:00
|
|
|
n = convlit1(n, t1, false, reuse)
|
2016-03-02 17:34:42 -08:00
|
|
|
lineno = lno
|
cmd/compile: reduce use of **Node parameters
Escape analysis has a hard time with tree-like
structures (see #13493 and #14858).
This is unlikely to change.
As a result, when invoking a function that accepts
a **Node parameter, we usually allocate a *Node
on the heap. This happens a whole lot.
This CL changes functions from taking a **Node
to acting more like append: It both modifies
the input and returns a replacement for it.
Because of the cascading nature of escape analysis,
in order to get the benefits, I had to modify
almost all such functions. The remaining functions
are in racewalk and the backend. I would be happy
to update them as well in a separate CL.
This CL was created by manually updating the
function signatures and the directly impacted
bits of code. The callsites were then automatically
updated using a bespoke script:
https://gist.github.com/josharian/046b1be7aceae244de39
For ease of reviewing and future understanding,
this CL is also broken down into four CLs,
mailed separately, which show the manual
and the automated changes separately.
They are CLs 20990, 20991, 20992, and 20993.
Passes toolstash -cmp.
name old time/op new time/op delta
Template 335ms ± 5% 324ms ± 5% -3.35% (p=0.000 n=23+24)
Unicode 176ms ± 9% 165ms ± 6% -6.12% (p=0.000 n=23+24)
GoTypes 1.10s ± 4% 1.07s ± 2% -2.77% (p=0.000 n=24+24)
Compiler 5.31s ± 3% 5.15s ± 3% -2.95% (p=0.000 n=24+24)
MakeBash 41.6s ± 1% 41.7s ± 2% ~ (p=0.586 n=23+23)
name old alloc/op new alloc/op delta
Template 63.3MB ± 0% 62.4MB ± 0% -1.36% (p=0.000 n=25+23)
Unicode 42.4MB ± 0% 41.6MB ± 0% -1.99% (p=0.000 n=24+25)
GoTypes 220MB ± 0% 217MB ± 0% -1.11% (p=0.000 n=25+25)
Compiler 994MB ± 0% 973MB ± 0% -2.08% (p=0.000 n=24+25)
name old allocs/op new allocs/op delta
Template 681k ± 0% 574k ± 0% -15.71% (p=0.000 n=24+25)
Unicode 518k ± 0% 413k ± 0% -20.34% (p=0.000 n=25+24)
GoTypes 2.08M ± 0% 1.78M ± 0% -14.62% (p=0.000 n=25+25)
Compiler 9.26M ± 0% 7.64M ± 0% -17.48% (p=0.000 n=25+25)
name old text-bytes new text-bytes delta
HelloSize 578k ± 0% 578k ± 0% ~ (all samples are equal)
CmdGoSize 6.46M ± 0% 6.46M ± 0% ~ (all samples are equal)
name old data-bytes new data-bytes delta
HelloSize 128k ± 0% 128k ± 0% ~ (all samples are equal)
CmdGoSize 281k ± 0% 281k ± 0% ~ (all samples are equal)
name old exe-bytes new exe-bytes delta
HelloSize 921k ± 0% 921k ± 0% ~ (all samples are equal)
CmdGoSize 9.86M ± 0% 9.86M ± 0% ~ (all samples are equal)
Change-Id: I277d95bd56d51c166ef7f560647aeaa092f3f475
Reviewed-on: https://go-review.googlesource.com/20959
Reviewed-by: Dave Cheney <dave@cheney.net>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-03-20 08:03:31 -07:00
|
|
|
return n
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2015-10-22 09:51:12 +09:00
|
|
|
// defaultlit on both nodes simultaneously;
|
|
|
|
|
// if they're both ideal going in they better
|
|
|
|
|
// get the same type going out.
|
|
|
|
|
// force means must assign concrete (non-ideal) type.
|
cmd/compile: reduce use of **Node parameters
Escape analysis has a hard time with tree-like
structures (see #13493 and #14858).
This is unlikely to change.
As a result, when invoking a function that accepts
a **Node parameter, we usually allocate a *Node
on the heap. This happens a whole lot.
This CL changes functions from taking a **Node
to acting more like append: It both modifies
the input and returns a replacement for it.
Because of the cascading nature of escape analysis,
in order to get the benefits, I had to modify
almost all such functions. The remaining functions
are in racewalk and the backend. I would be happy
to update them as well in a separate CL.
This CL was created by manually updating the
function signatures and the directly impacted
bits of code. The callsites were then automatically
updated using a bespoke script:
https://gist.github.com/josharian/046b1be7aceae244de39
For ease of reviewing and future understanding,
this CL is also broken down into four CLs,
mailed separately, which show the manual
and the automated changes separately.
They are CLs 20990, 20991, 20992, and 20993.
Passes toolstash -cmp.
name old time/op new time/op delta
Template 335ms ± 5% 324ms ± 5% -3.35% (p=0.000 n=23+24)
Unicode 176ms ± 9% 165ms ± 6% -6.12% (p=0.000 n=23+24)
GoTypes 1.10s ± 4% 1.07s ± 2% -2.77% (p=0.000 n=24+24)
Compiler 5.31s ± 3% 5.15s ± 3% -2.95% (p=0.000 n=24+24)
MakeBash 41.6s ± 1% 41.7s ± 2% ~ (p=0.586 n=23+23)
name old alloc/op new alloc/op delta
Template 63.3MB ± 0% 62.4MB ± 0% -1.36% (p=0.000 n=25+23)
Unicode 42.4MB ± 0% 41.6MB ± 0% -1.99% (p=0.000 n=24+25)
GoTypes 220MB ± 0% 217MB ± 0% -1.11% (p=0.000 n=25+25)
Compiler 994MB ± 0% 973MB ± 0% -2.08% (p=0.000 n=24+25)
name old allocs/op new allocs/op delta
Template 681k ± 0% 574k ± 0% -15.71% (p=0.000 n=24+25)
Unicode 518k ± 0% 413k ± 0% -20.34% (p=0.000 n=25+24)
GoTypes 2.08M ± 0% 1.78M ± 0% -14.62% (p=0.000 n=25+25)
Compiler 9.26M ± 0% 7.64M ± 0% -17.48% (p=0.000 n=25+25)
name old text-bytes new text-bytes delta
HelloSize 578k ± 0% 578k ± 0% ~ (all samples are equal)
CmdGoSize 6.46M ± 0% 6.46M ± 0% ~ (all samples are equal)
name old data-bytes new data-bytes delta
HelloSize 128k ± 0% 128k ± 0% ~ (all samples are equal)
CmdGoSize 281k ± 0% 281k ± 0% ~ (all samples are equal)
name old exe-bytes new exe-bytes delta
HelloSize 921k ± 0% 921k ± 0% ~ (all samples are equal)
CmdGoSize 9.86M ± 0% 9.86M ± 0% ~ (all samples are equal)
Change-Id: I277d95bd56d51c166ef7f560647aeaa092f3f475
Reviewed-on: https://go-review.googlesource.com/20959
Reviewed-by: Dave Cheney <dave@cheney.net>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-03-20 08:03:31 -07:00
|
|
|
// The results of defaultlit2 MUST be assigned back to l and r, e.g.
|
|
|
|
|
// n.Left, n.Right = defaultlit2(n.Left, n.Right, force)
|
|
|
|
|
func defaultlit2(l *Node, r *Node, force bool) (*Node, *Node) {
|
2015-02-13 14:40:36 -05:00
|
|
|
if l.Type == nil || r.Type == nil {
|
cmd/compile: reduce use of **Node parameters
Escape analysis has a hard time with tree-like
structures (see #13493 and #14858).
This is unlikely to change.
As a result, when invoking a function that accepts
a **Node parameter, we usually allocate a *Node
on the heap. This happens a whole lot.
This CL changes functions from taking a **Node
to acting more like append: It both modifies
the input and returns a replacement for it.
Because of the cascading nature of escape analysis,
in order to get the benefits, I had to modify
almost all such functions. The remaining functions
are in racewalk and the backend. I would be happy
to update them as well in a separate CL.
This CL was created by manually updating the
function signatures and the directly impacted
bits of code. The callsites were then automatically
updated using a bespoke script:
https://gist.github.com/josharian/046b1be7aceae244de39
For ease of reviewing and future understanding,
this CL is also broken down into four CLs,
mailed separately, which show the manual
and the automated changes separately.
They are CLs 20990, 20991, 20992, and 20993.
Passes toolstash -cmp.
name old time/op new time/op delta
Template 335ms ± 5% 324ms ± 5% -3.35% (p=0.000 n=23+24)
Unicode 176ms ± 9% 165ms ± 6% -6.12% (p=0.000 n=23+24)
GoTypes 1.10s ± 4% 1.07s ± 2% -2.77% (p=0.000 n=24+24)
Compiler 5.31s ± 3% 5.15s ± 3% -2.95% (p=0.000 n=24+24)
MakeBash 41.6s ± 1% 41.7s ± 2% ~ (p=0.586 n=23+23)
name old alloc/op new alloc/op delta
Template 63.3MB ± 0% 62.4MB ± 0% -1.36% (p=0.000 n=25+23)
Unicode 42.4MB ± 0% 41.6MB ± 0% -1.99% (p=0.000 n=24+25)
GoTypes 220MB ± 0% 217MB ± 0% -1.11% (p=0.000 n=25+25)
Compiler 994MB ± 0% 973MB ± 0% -2.08% (p=0.000 n=24+25)
name old allocs/op new allocs/op delta
Template 681k ± 0% 574k ± 0% -15.71% (p=0.000 n=24+25)
Unicode 518k ± 0% 413k ± 0% -20.34% (p=0.000 n=25+24)
GoTypes 2.08M ± 0% 1.78M ± 0% -14.62% (p=0.000 n=25+25)
Compiler 9.26M ± 0% 7.64M ± 0% -17.48% (p=0.000 n=25+25)
name old text-bytes new text-bytes delta
HelloSize 578k ± 0% 578k ± 0% ~ (all samples are equal)
CmdGoSize 6.46M ± 0% 6.46M ± 0% ~ (all samples are equal)
name old data-bytes new data-bytes delta
HelloSize 128k ± 0% 128k ± 0% ~ (all samples are equal)
CmdGoSize 281k ± 0% 281k ± 0% ~ (all samples are equal)
name old exe-bytes new exe-bytes delta
HelloSize 921k ± 0% 921k ± 0% ~ (all samples are equal)
CmdGoSize 9.86M ± 0% 9.86M ± 0% ~ (all samples are equal)
Change-Id: I277d95bd56d51c166ef7f560647aeaa092f3f475
Reviewed-on: https://go-review.googlesource.com/20959
Reviewed-by: Dave Cheney <dave@cheney.net>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-03-20 08:03:31 -07:00
|
|
|
return l, r
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
2016-04-01 13:36:24 -07:00
|
|
|
if !l.Type.IsUntyped() {
|
cmd/compile: reduce use of **Node parameters
Escape analysis has a hard time with tree-like
structures (see #13493 and #14858).
This is unlikely to change.
As a result, when invoking a function that accepts
a **Node parameter, we usually allocate a *Node
on the heap. This happens a whole lot.
This CL changes functions from taking a **Node
to acting more like append: It both modifies
the input and returns a replacement for it.
Because of the cascading nature of escape analysis,
in order to get the benefits, I had to modify
almost all such functions. The remaining functions
are in racewalk and the backend. I would be happy
to update them as well in a separate CL.
This CL was created by manually updating the
function signatures and the directly impacted
bits of code. The callsites were then automatically
updated using a bespoke script:
https://gist.github.com/josharian/046b1be7aceae244de39
For ease of reviewing and future understanding,
this CL is also broken down into four CLs,
mailed separately, which show the manual
and the automated changes separately.
They are CLs 20990, 20991, 20992, and 20993.
Passes toolstash -cmp.
name old time/op new time/op delta
Template 335ms ± 5% 324ms ± 5% -3.35% (p=0.000 n=23+24)
Unicode 176ms ± 9% 165ms ± 6% -6.12% (p=0.000 n=23+24)
GoTypes 1.10s ± 4% 1.07s ± 2% -2.77% (p=0.000 n=24+24)
Compiler 5.31s ± 3% 5.15s ± 3% -2.95% (p=0.000 n=24+24)
MakeBash 41.6s ± 1% 41.7s ± 2% ~ (p=0.586 n=23+23)
name old alloc/op new alloc/op delta
Template 63.3MB ± 0% 62.4MB ± 0% -1.36% (p=0.000 n=25+23)
Unicode 42.4MB ± 0% 41.6MB ± 0% -1.99% (p=0.000 n=24+25)
GoTypes 220MB ± 0% 217MB ± 0% -1.11% (p=0.000 n=25+25)
Compiler 994MB ± 0% 973MB ± 0% -2.08% (p=0.000 n=24+25)
name old allocs/op new allocs/op delta
Template 681k ± 0% 574k ± 0% -15.71% (p=0.000 n=24+25)
Unicode 518k ± 0% 413k ± 0% -20.34% (p=0.000 n=25+24)
GoTypes 2.08M ± 0% 1.78M ± 0% -14.62% (p=0.000 n=25+25)
Compiler 9.26M ± 0% 7.64M ± 0% -17.48% (p=0.000 n=25+25)
name old text-bytes new text-bytes delta
HelloSize 578k ± 0% 578k ± 0% ~ (all samples are equal)
CmdGoSize 6.46M ± 0% 6.46M ± 0% ~ (all samples are equal)
name old data-bytes new data-bytes delta
HelloSize 128k ± 0% 128k ± 0% ~ (all samples are equal)
CmdGoSize 281k ± 0% 281k ± 0% ~ (all samples are equal)
name old exe-bytes new exe-bytes delta
HelloSize 921k ± 0% 921k ± 0% ~ (all samples are equal)
CmdGoSize 9.86M ± 0% 9.86M ± 0% ~ (all samples are equal)
Change-Id: I277d95bd56d51c166ef7f560647aeaa092f3f475
Reviewed-on: https://go-review.googlesource.com/20959
Reviewed-by: Dave Cheney <dave@cheney.net>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-03-20 08:03:31 -07:00
|
|
|
r = convlit(r, l.Type)
|
|
|
|
|
return l, r
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2016-04-01 13:36:24 -07:00
|
|
|
if !r.Type.IsUntyped() {
|
cmd/compile: reduce use of **Node parameters
Escape analysis has a hard time with tree-like
structures (see #13493 and #14858).
This is unlikely to change.
As a result, when invoking a function that accepts
a **Node parameter, we usually allocate a *Node
on the heap. This happens a whole lot.
This CL changes functions from taking a **Node
to acting more like append: It both modifies
the input and returns a replacement for it.
Because of the cascading nature of escape analysis,
in order to get the benefits, I had to modify
almost all such functions. The remaining functions
are in racewalk and the backend. I would be happy
to update them as well in a separate CL.
This CL was created by manually updating the
function signatures and the directly impacted
bits of code. The callsites were then automatically
updated using a bespoke script:
https://gist.github.com/josharian/046b1be7aceae244de39
For ease of reviewing and future understanding,
this CL is also broken down into four CLs,
mailed separately, which show the manual
and the automated changes separately.
They are CLs 20990, 20991, 20992, and 20993.
Passes toolstash -cmp.
name old time/op new time/op delta
Template 335ms ± 5% 324ms ± 5% -3.35% (p=0.000 n=23+24)
Unicode 176ms ± 9% 165ms ± 6% -6.12% (p=0.000 n=23+24)
GoTypes 1.10s ± 4% 1.07s ± 2% -2.77% (p=0.000 n=24+24)
Compiler 5.31s ± 3% 5.15s ± 3% -2.95% (p=0.000 n=24+24)
MakeBash 41.6s ± 1% 41.7s ± 2% ~ (p=0.586 n=23+23)
name old alloc/op new alloc/op delta
Template 63.3MB ± 0% 62.4MB ± 0% -1.36% (p=0.000 n=25+23)
Unicode 42.4MB ± 0% 41.6MB ± 0% -1.99% (p=0.000 n=24+25)
GoTypes 220MB ± 0% 217MB ± 0% -1.11% (p=0.000 n=25+25)
Compiler 994MB ± 0% 973MB ± 0% -2.08% (p=0.000 n=24+25)
name old allocs/op new allocs/op delta
Template 681k ± 0% 574k ± 0% -15.71% (p=0.000 n=24+25)
Unicode 518k ± 0% 413k ± 0% -20.34% (p=0.000 n=25+24)
GoTypes 2.08M ± 0% 1.78M ± 0% -14.62% (p=0.000 n=25+25)
Compiler 9.26M ± 0% 7.64M ± 0% -17.48% (p=0.000 n=25+25)
name old text-bytes new text-bytes delta
HelloSize 578k ± 0% 578k ± 0% ~ (all samples are equal)
CmdGoSize 6.46M ± 0% 6.46M ± 0% ~ (all samples are equal)
name old data-bytes new data-bytes delta
HelloSize 128k ± 0% 128k ± 0% ~ (all samples are equal)
CmdGoSize 281k ± 0% 281k ± 0% ~ (all samples are equal)
name old exe-bytes new exe-bytes delta
HelloSize 921k ± 0% 921k ± 0% ~ (all samples are equal)
CmdGoSize 9.86M ± 0% 9.86M ± 0% ~ (all samples are equal)
Change-Id: I277d95bd56d51c166ef7f560647aeaa092f3f475
Reviewed-on: https://go-review.googlesource.com/20959
Reviewed-by: Dave Cheney <dave@cheney.net>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-03-20 08:03:31 -07:00
|
|
|
l = convlit(l, r.Type)
|
|
|
|
|
return l, r
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2016-03-01 00:15:27 -08:00
|
|
|
if !force {
|
cmd/compile: reduce use of **Node parameters
Escape analysis has a hard time with tree-like
structures (see #13493 and #14858).
This is unlikely to change.
As a result, when invoking a function that accepts
a **Node parameter, we usually allocate a *Node
on the heap. This happens a whole lot.
This CL changes functions from taking a **Node
to acting more like append: It both modifies
the input and returns a replacement for it.
Because of the cascading nature of escape analysis,
in order to get the benefits, I had to modify
almost all such functions. The remaining functions
are in racewalk and the backend. I would be happy
to update them as well in a separate CL.
This CL was created by manually updating the
function signatures and the directly impacted
bits of code. The callsites were then automatically
updated using a bespoke script:
https://gist.github.com/josharian/046b1be7aceae244de39
For ease of reviewing and future understanding,
this CL is also broken down into four CLs,
mailed separately, which show the manual
and the automated changes separately.
They are CLs 20990, 20991, 20992, and 20993.
Passes toolstash -cmp.
name old time/op new time/op delta
Template 335ms ± 5% 324ms ± 5% -3.35% (p=0.000 n=23+24)
Unicode 176ms ± 9% 165ms ± 6% -6.12% (p=0.000 n=23+24)
GoTypes 1.10s ± 4% 1.07s ± 2% -2.77% (p=0.000 n=24+24)
Compiler 5.31s ± 3% 5.15s ± 3% -2.95% (p=0.000 n=24+24)
MakeBash 41.6s ± 1% 41.7s ± 2% ~ (p=0.586 n=23+23)
name old alloc/op new alloc/op delta
Template 63.3MB ± 0% 62.4MB ± 0% -1.36% (p=0.000 n=25+23)
Unicode 42.4MB ± 0% 41.6MB ± 0% -1.99% (p=0.000 n=24+25)
GoTypes 220MB ± 0% 217MB ± 0% -1.11% (p=0.000 n=25+25)
Compiler 994MB ± 0% 973MB ± 0% -2.08% (p=0.000 n=24+25)
name old allocs/op new allocs/op delta
Template 681k ± 0% 574k ± 0% -15.71% (p=0.000 n=24+25)
Unicode 518k ± 0% 413k ± 0% -20.34% (p=0.000 n=25+24)
GoTypes 2.08M ± 0% 1.78M ± 0% -14.62% (p=0.000 n=25+25)
Compiler 9.26M ± 0% 7.64M ± 0% -17.48% (p=0.000 n=25+25)
name old text-bytes new text-bytes delta
HelloSize 578k ± 0% 578k ± 0% ~ (all samples are equal)
CmdGoSize 6.46M ± 0% 6.46M ± 0% ~ (all samples are equal)
name old data-bytes new data-bytes delta
HelloSize 128k ± 0% 128k ± 0% ~ (all samples are equal)
CmdGoSize 281k ± 0% 281k ± 0% ~ (all samples are equal)
name old exe-bytes new exe-bytes delta
HelloSize 921k ± 0% 921k ± 0% ~ (all samples are equal)
CmdGoSize 9.86M ± 0% 9.86M ± 0% ~ (all samples are equal)
Change-Id: I277d95bd56d51c166ef7f560647aeaa092f3f475
Reviewed-on: https://go-review.googlesource.com/20959
Reviewed-by: Dave Cheney <dave@cheney.net>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-03-20 08:03:31 -07:00
|
|
|
return l, r
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
2016-03-01 00:15:27 -08:00
|
|
|
|
2016-03-30 14:56:08 -07:00
|
|
|
if l.Type.IsBoolean() {
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
l = convlit(l, types.Types[TBOOL])
|
|
|
|
|
r = convlit(r, types.Types[TBOOL])
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2015-02-23 16:07:24 -05:00
|
|
|
lkind := idealkind(l)
|
|
|
|
|
rkind := idealkind(r)
|
2015-02-13 14:40:36 -05:00
|
|
|
if lkind == CTCPLX || rkind == CTCPLX {
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
l = convlit(l, types.Types[TCOMPLEX128])
|
|
|
|
|
r = convlit(r, types.Types[TCOMPLEX128])
|
cmd/compile: reduce use of **Node parameters
Escape analysis has a hard time with tree-like
structures (see #13493 and #14858).
This is unlikely to change.
As a result, when invoking a function that accepts
a **Node parameter, we usually allocate a *Node
on the heap. This happens a whole lot.
This CL changes functions from taking a **Node
to acting more like append: It both modifies
the input and returns a replacement for it.
Because of the cascading nature of escape analysis,
in order to get the benefits, I had to modify
almost all such functions. The remaining functions
are in racewalk and the backend. I would be happy
to update them as well in a separate CL.
This CL was created by manually updating the
function signatures and the directly impacted
bits of code. The callsites were then automatically
updated using a bespoke script:
https://gist.github.com/josharian/046b1be7aceae244de39
For ease of reviewing and future understanding,
this CL is also broken down into four CLs,
mailed separately, which show the manual
and the automated changes separately.
They are CLs 20990, 20991, 20992, and 20993.
Passes toolstash -cmp.
name old time/op new time/op delta
Template 335ms ± 5% 324ms ± 5% -3.35% (p=0.000 n=23+24)
Unicode 176ms ± 9% 165ms ± 6% -6.12% (p=0.000 n=23+24)
GoTypes 1.10s ± 4% 1.07s ± 2% -2.77% (p=0.000 n=24+24)
Compiler 5.31s ± 3% 5.15s ± 3% -2.95% (p=0.000 n=24+24)
MakeBash 41.6s ± 1% 41.7s ± 2% ~ (p=0.586 n=23+23)
name old alloc/op new alloc/op delta
Template 63.3MB ± 0% 62.4MB ± 0% -1.36% (p=0.000 n=25+23)
Unicode 42.4MB ± 0% 41.6MB ± 0% -1.99% (p=0.000 n=24+25)
GoTypes 220MB ± 0% 217MB ± 0% -1.11% (p=0.000 n=25+25)
Compiler 994MB ± 0% 973MB ± 0% -2.08% (p=0.000 n=24+25)
name old allocs/op new allocs/op delta
Template 681k ± 0% 574k ± 0% -15.71% (p=0.000 n=24+25)
Unicode 518k ± 0% 413k ± 0% -20.34% (p=0.000 n=25+24)
GoTypes 2.08M ± 0% 1.78M ± 0% -14.62% (p=0.000 n=25+25)
Compiler 9.26M ± 0% 7.64M ± 0% -17.48% (p=0.000 n=25+25)
name old text-bytes new text-bytes delta
HelloSize 578k ± 0% 578k ± 0% ~ (all samples are equal)
CmdGoSize 6.46M ± 0% 6.46M ± 0% ~ (all samples are equal)
name old data-bytes new data-bytes delta
HelloSize 128k ± 0% 128k ± 0% ~ (all samples are equal)
CmdGoSize 281k ± 0% 281k ± 0% ~ (all samples are equal)
name old exe-bytes new exe-bytes delta
HelloSize 921k ± 0% 921k ± 0% ~ (all samples are equal)
CmdGoSize 9.86M ± 0% 9.86M ± 0% ~ (all samples are equal)
Change-Id: I277d95bd56d51c166ef7f560647aeaa092f3f475
Reviewed-on: https://go-review.googlesource.com/20959
Reviewed-by: Dave Cheney <dave@cheney.net>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-03-20 08:03:31 -07:00
|
|
|
return l, r
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if lkind == CTFLT || rkind == CTFLT {
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
l = convlit(l, types.Types[TFLOAT64])
|
|
|
|
|
r = convlit(r, types.Types[TFLOAT64])
|
cmd/compile: reduce use of **Node parameters
Escape analysis has a hard time with tree-like
structures (see #13493 and #14858).
This is unlikely to change.
As a result, when invoking a function that accepts
a **Node parameter, we usually allocate a *Node
on the heap. This happens a whole lot.
This CL changes functions from taking a **Node
to acting more like append: It both modifies
the input and returns a replacement for it.
Because of the cascading nature of escape analysis,
in order to get the benefits, I had to modify
almost all such functions. The remaining functions
are in racewalk and the backend. I would be happy
to update them as well in a separate CL.
This CL was created by manually updating the
function signatures and the directly impacted
bits of code. The callsites were then automatically
updated using a bespoke script:
https://gist.github.com/josharian/046b1be7aceae244de39
For ease of reviewing and future understanding,
this CL is also broken down into four CLs,
mailed separately, which show the manual
and the automated changes separately.
They are CLs 20990, 20991, 20992, and 20993.
Passes toolstash -cmp.
name old time/op new time/op delta
Template 335ms ± 5% 324ms ± 5% -3.35% (p=0.000 n=23+24)
Unicode 176ms ± 9% 165ms ± 6% -6.12% (p=0.000 n=23+24)
GoTypes 1.10s ± 4% 1.07s ± 2% -2.77% (p=0.000 n=24+24)
Compiler 5.31s ± 3% 5.15s ± 3% -2.95% (p=0.000 n=24+24)
MakeBash 41.6s ± 1% 41.7s ± 2% ~ (p=0.586 n=23+23)
name old alloc/op new alloc/op delta
Template 63.3MB ± 0% 62.4MB ± 0% -1.36% (p=0.000 n=25+23)
Unicode 42.4MB ± 0% 41.6MB ± 0% -1.99% (p=0.000 n=24+25)
GoTypes 220MB ± 0% 217MB ± 0% -1.11% (p=0.000 n=25+25)
Compiler 994MB ± 0% 973MB ± 0% -2.08% (p=0.000 n=24+25)
name old allocs/op new allocs/op delta
Template 681k ± 0% 574k ± 0% -15.71% (p=0.000 n=24+25)
Unicode 518k ± 0% 413k ± 0% -20.34% (p=0.000 n=25+24)
GoTypes 2.08M ± 0% 1.78M ± 0% -14.62% (p=0.000 n=25+25)
Compiler 9.26M ± 0% 7.64M ± 0% -17.48% (p=0.000 n=25+25)
name old text-bytes new text-bytes delta
HelloSize 578k ± 0% 578k ± 0% ~ (all samples are equal)
CmdGoSize 6.46M ± 0% 6.46M ± 0% ~ (all samples are equal)
name old data-bytes new data-bytes delta
HelloSize 128k ± 0% 128k ± 0% ~ (all samples are equal)
CmdGoSize 281k ± 0% 281k ± 0% ~ (all samples are equal)
name old exe-bytes new exe-bytes delta
HelloSize 921k ± 0% 921k ± 0% ~ (all samples are equal)
CmdGoSize 9.86M ± 0% 9.86M ± 0% ~ (all samples are equal)
Change-Id: I277d95bd56d51c166ef7f560647aeaa092f3f475
Reviewed-on: https://go-review.googlesource.com/20959
Reviewed-by: Dave Cheney <dave@cheney.net>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-03-20 08:03:31 -07:00
|
|
|
return l, r
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if lkind == CTRUNE || rkind == CTRUNE {
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
l = convlit(l, types.Runetype)
|
|
|
|
|
r = convlit(r, types.Runetype)
|
cmd/compile: reduce use of **Node parameters
Escape analysis has a hard time with tree-like
structures (see #13493 and #14858).
This is unlikely to change.
As a result, when invoking a function that accepts
a **Node parameter, we usually allocate a *Node
on the heap. This happens a whole lot.
This CL changes functions from taking a **Node
to acting more like append: It both modifies
the input and returns a replacement for it.
Because of the cascading nature of escape analysis,
in order to get the benefits, I had to modify
almost all such functions. The remaining functions
are in racewalk and the backend. I would be happy
to update them as well in a separate CL.
This CL was created by manually updating the
function signatures and the directly impacted
bits of code. The callsites were then automatically
updated using a bespoke script:
https://gist.github.com/josharian/046b1be7aceae244de39
For ease of reviewing and future understanding,
this CL is also broken down into four CLs,
mailed separately, which show the manual
and the automated changes separately.
They are CLs 20990, 20991, 20992, and 20993.
Passes toolstash -cmp.
name old time/op new time/op delta
Template 335ms ± 5% 324ms ± 5% -3.35% (p=0.000 n=23+24)
Unicode 176ms ± 9% 165ms ± 6% -6.12% (p=0.000 n=23+24)
GoTypes 1.10s ± 4% 1.07s ± 2% -2.77% (p=0.000 n=24+24)
Compiler 5.31s ± 3% 5.15s ± 3% -2.95% (p=0.000 n=24+24)
MakeBash 41.6s ± 1% 41.7s ± 2% ~ (p=0.586 n=23+23)
name old alloc/op new alloc/op delta
Template 63.3MB ± 0% 62.4MB ± 0% -1.36% (p=0.000 n=25+23)
Unicode 42.4MB ± 0% 41.6MB ± 0% -1.99% (p=0.000 n=24+25)
GoTypes 220MB ± 0% 217MB ± 0% -1.11% (p=0.000 n=25+25)
Compiler 994MB ± 0% 973MB ± 0% -2.08% (p=0.000 n=24+25)
name old allocs/op new allocs/op delta
Template 681k ± 0% 574k ± 0% -15.71% (p=0.000 n=24+25)
Unicode 518k ± 0% 413k ± 0% -20.34% (p=0.000 n=25+24)
GoTypes 2.08M ± 0% 1.78M ± 0% -14.62% (p=0.000 n=25+25)
Compiler 9.26M ± 0% 7.64M ± 0% -17.48% (p=0.000 n=25+25)
name old text-bytes new text-bytes delta
HelloSize 578k ± 0% 578k ± 0% ~ (all samples are equal)
CmdGoSize 6.46M ± 0% 6.46M ± 0% ~ (all samples are equal)
name old data-bytes new data-bytes delta
HelloSize 128k ± 0% 128k ± 0% ~ (all samples are equal)
CmdGoSize 281k ± 0% 281k ± 0% ~ (all samples are equal)
name old exe-bytes new exe-bytes delta
HelloSize 921k ± 0% 921k ± 0% ~ (all samples are equal)
CmdGoSize 9.86M ± 0% 9.86M ± 0% ~ (all samples are equal)
Change-Id: I277d95bd56d51c166ef7f560647aeaa092f3f475
Reviewed-on: https://go-review.googlesource.com/20959
Reviewed-by: Dave Cheney <dave@cheney.net>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-03-20 08:03:31 -07:00
|
|
|
return l, r
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
l = convlit(l, types.Types[TINT])
|
|
|
|
|
r = convlit(r, types.Types[TINT])
|
cmd/compile: reduce use of **Node parameters
Escape analysis has a hard time with tree-like
structures (see #13493 and #14858).
This is unlikely to change.
As a result, when invoking a function that accepts
a **Node parameter, we usually allocate a *Node
on the heap. This happens a whole lot.
This CL changes functions from taking a **Node
to acting more like append: It both modifies
the input and returns a replacement for it.
Because of the cascading nature of escape analysis,
in order to get the benefits, I had to modify
almost all such functions. The remaining functions
are in racewalk and the backend. I would be happy
to update them as well in a separate CL.
This CL was created by manually updating the
function signatures and the directly impacted
bits of code. The callsites were then automatically
updated using a bespoke script:
https://gist.github.com/josharian/046b1be7aceae244de39
For ease of reviewing and future understanding,
this CL is also broken down into four CLs,
mailed separately, which show the manual
and the automated changes separately.
They are CLs 20990, 20991, 20992, and 20993.
Passes toolstash -cmp.
name old time/op new time/op delta
Template 335ms ± 5% 324ms ± 5% -3.35% (p=0.000 n=23+24)
Unicode 176ms ± 9% 165ms ± 6% -6.12% (p=0.000 n=23+24)
GoTypes 1.10s ± 4% 1.07s ± 2% -2.77% (p=0.000 n=24+24)
Compiler 5.31s ± 3% 5.15s ± 3% -2.95% (p=0.000 n=24+24)
MakeBash 41.6s ± 1% 41.7s ± 2% ~ (p=0.586 n=23+23)
name old alloc/op new alloc/op delta
Template 63.3MB ± 0% 62.4MB ± 0% -1.36% (p=0.000 n=25+23)
Unicode 42.4MB ± 0% 41.6MB ± 0% -1.99% (p=0.000 n=24+25)
GoTypes 220MB ± 0% 217MB ± 0% -1.11% (p=0.000 n=25+25)
Compiler 994MB ± 0% 973MB ± 0% -2.08% (p=0.000 n=24+25)
name old allocs/op new allocs/op delta
Template 681k ± 0% 574k ± 0% -15.71% (p=0.000 n=24+25)
Unicode 518k ± 0% 413k ± 0% -20.34% (p=0.000 n=25+24)
GoTypes 2.08M ± 0% 1.78M ± 0% -14.62% (p=0.000 n=25+25)
Compiler 9.26M ± 0% 7.64M ± 0% -17.48% (p=0.000 n=25+25)
name old text-bytes new text-bytes delta
HelloSize 578k ± 0% 578k ± 0% ~ (all samples are equal)
CmdGoSize 6.46M ± 0% 6.46M ± 0% ~ (all samples are equal)
name old data-bytes new data-bytes delta
HelloSize 128k ± 0% 128k ± 0% ~ (all samples are equal)
CmdGoSize 281k ± 0% 281k ± 0% ~ (all samples are equal)
name old exe-bytes new exe-bytes delta
HelloSize 921k ± 0% 921k ± 0% ~ (all samples are equal)
CmdGoSize 9.86M ± 0% 9.86M ± 0% ~ (all samples are equal)
Change-Id: I277d95bd56d51c166ef7f560647aeaa092f3f475
Reviewed-on: https://go-review.googlesource.com/20959
Reviewed-by: Dave Cheney <dave@cheney.net>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-03-20 08:03:31 -07:00
|
|
|
|
|
|
|
|
return l, r
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2015-09-17 21:01:29 +02:00
|
|
|
// strlit returns the value of a literal string Node as a string.
|
|
|
|
|
func strlit(n *Node) string {
|
|
|
|
|
return n.Val().U.(string)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2016-09-15 14:34:20 +10:00
|
|
|
func smallintconst(n *Node) bool {
|
2015-02-17 22:13:49 -05:00
|
|
|
if n.Op == OLITERAL && Isconst(n, CTINT) && n.Type != nil {
|
2016-09-16 00:33:29 +10:00
|
|
|
switch simtype[n.Type.Etype] {
|
2015-02-13 14:40:36 -05:00
|
|
|
case TINT8,
|
|
|
|
|
TUINT8,
|
|
|
|
|
TINT16,
|
|
|
|
|
TUINT16,
|
|
|
|
|
TINT32,
|
|
|
|
|
TUINT32,
|
2018-10-03 15:47:16 -07:00
|
|
|
TBOOL:
|
2015-02-17 22:13:49 -05:00
|
|
|
return true
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2018-10-03 15:47:16 -07:00
|
|
|
case TIDEAL, TINT64, TUINT64, TPTR32, TPTR64:
|
2016-09-10 13:24:35 +02:00
|
|
|
v, ok := n.Val().U.(*Mpint)
|
|
|
|
|
if ok && v.Cmp(minintval[TINT32]) > 0 && v.Cmp(maxintval[TINT32]) < 0 {
|
|
|
|
|
return true
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-17 22:13:49 -05:00
|
|
|
return false
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2016-09-10 13:24:35 +02:00
|
|
|
// nonnegintconst checks if Node n contains a constant expression
|
|
|
|
|
// representable as a non-negative small integer, and returns its
|
|
|
|
|
// (integer) value if that's the case. Otherwise, it returns -1.
|
|
|
|
|
func nonnegintconst(n *Node) int64 {
|
|
|
|
|
if n.Op != OLITERAL {
|
|
|
|
|
return -1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// toint will leave n.Val unchanged if it's not castable to an
|
|
|
|
|
// Mpint, so we still have to guard the conversion.
|
|
|
|
|
v := toint(n.Val())
|
|
|
|
|
vi, ok := v.U.(*Mpint)
|
2017-04-07 09:09:17 +02:00
|
|
|
if !ok || vi.CmpInt64(0) < 0 || vi.Cmp(maxintval[TINT32]) > 0 {
|
2016-09-10 13:24:35 +02:00
|
|
|
return -1
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2016-09-10 13:24:35 +02:00
|
|
|
return vi.Int64()
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2018-04-08 13:39:10 +01:00
|
|
|
// isGoConst reports whether n is a Go language constant (as opposed to a
|
|
|
|
|
// compile-time constant).
|
|
|
|
|
//
|
2015-02-13 14:40:36 -05:00
|
|
|
// Expressions derived from nil, like string([]byte(nil)), while they
|
|
|
|
|
// may be known at compile time, are not Go language constants.
|
|
|
|
|
// Only called for expressions known to evaluated to compile-time
|
|
|
|
|
// constants.
|
2018-04-08 13:39:10 +01:00
|
|
|
func (n *Node) isGoConst() bool {
|
2015-02-13 14:40:36 -05:00
|
|
|
if n.Orig != nil {
|
|
|
|
|
n = n.Orig
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch n.Op {
|
|
|
|
|
case OADD,
|
|
|
|
|
OADDSTR,
|
|
|
|
|
OAND,
|
|
|
|
|
OANDAND,
|
|
|
|
|
OANDNOT,
|
|
|
|
|
OCOM,
|
|
|
|
|
ODIV,
|
|
|
|
|
OEQ,
|
|
|
|
|
OGE,
|
|
|
|
|
OGT,
|
|
|
|
|
OLE,
|
|
|
|
|
OLSH,
|
|
|
|
|
OLT,
|
|
|
|
|
OMINUS,
|
|
|
|
|
OMOD,
|
|
|
|
|
OMUL,
|
|
|
|
|
ONE,
|
|
|
|
|
ONOT,
|
|
|
|
|
OOR,
|
|
|
|
|
OOROR,
|
|
|
|
|
OPLUS,
|
|
|
|
|
ORSH,
|
|
|
|
|
OSUB,
|
|
|
|
|
OXOR,
|
|
|
|
|
OIOTA,
|
|
|
|
|
OCOMPLEX,
|
|
|
|
|
OREAL,
|
|
|
|
|
OIMAG:
|
2018-04-08 13:39:10 +01:00
|
|
|
if n.Left.isGoConst() && (n.Right == nil || n.Right.isGoConst()) {
|
2015-02-17 22:13:49 -05:00
|
|
|
return true
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case OCONV:
|
2018-04-08 13:39:10 +01:00
|
|
|
if okforconst[n.Type.Etype] && n.Left.isGoConst() {
|
2015-02-17 22:13:49 -05:00
|
|
|
return true
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2015-04-01 09:38:44 -07:00
|
|
|
case OLEN, OCAP:
|
2015-02-23 16:07:24 -05:00
|
|
|
l := n.Left
|
2018-04-08 13:39:10 +01:00
|
|
|
if l.isGoConst() {
|
2015-02-17 22:13:49 -05:00
|
|
|
return true
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Special case: len/cap is constant when applied to array or
|
|
|
|
|
// pointer to array when the expression does not contain
|
|
|
|
|
// function calls or channel receive operations.
|
2015-02-23 16:07:24 -05:00
|
|
|
t := l.Type
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2016-03-30 15:09:25 -07:00
|
|
|
if t != nil && t.IsPtr() {
|
2016-03-30 10:57:47 -07:00
|
|
|
t = t.Elem()
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
2016-03-30 14:45:47 -07:00
|
|
|
if t != nil && t.IsArray() && !hascallchan(l) {
|
2015-02-17 22:13:49 -05:00
|
|
|
return true
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case OLITERAL:
|
2015-05-27 00:47:05 -04:00
|
|
|
if n.Val().Ctype() != CTNIL {
|
2015-02-17 22:13:49 -05:00
|
|
|
return true
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case ONAME:
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
l := asNode(n.Sym.Def)
|
2015-05-27 00:47:05 -04:00
|
|
|
if l != nil && l.Op == OLITERAL && n.Val().Ctype() != CTNIL {
|
2015-02-17 22:13:49 -05:00
|
|
|
return true
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case ONONAME:
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
if asNode(n.Sym.Def) != nil && asNode(n.Sym.Def).Op == OIOTA {
|
2015-02-17 22:13:49 -05:00
|
|
|
return true
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2016-10-18 14:17:05 -07:00
|
|
|
case OALIGNOF, OOFFSETOF, OSIZEOF:
|
|
|
|
|
return true
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//dump("nonconst", n);
|
2015-02-17 22:13:49 -05:00
|
|
|
return false
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2015-02-17 22:13:49 -05:00
|
|
|
func hascallchan(n *Node) bool {
|
2015-02-13 14:40:36 -05:00
|
|
|
if n == nil {
|
2015-02-17 22:13:49 -05:00
|
|
|
return false
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
switch n.Op {
|
|
|
|
|
case OAPPEND,
|
|
|
|
|
OCALL,
|
|
|
|
|
OCALLFUNC,
|
|
|
|
|
OCALLINTER,
|
|
|
|
|
OCALLMETH,
|
|
|
|
|
OCAP,
|
|
|
|
|
OCLOSE,
|
|
|
|
|
OCOMPLEX,
|
|
|
|
|
OCOPY,
|
|
|
|
|
ODELETE,
|
|
|
|
|
OIMAG,
|
|
|
|
|
OLEN,
|
|
|
|
|
OMAKE,
|
|
|
|
|
ONEW,
|
|
|
|
|
OPANIC,
|
|
|
|
|
OPRINT,
|
|
|
|
|
OPRINTN,
|
|
|
|
|
OREAL,
|
|
|
|
|
ORECOVER,
|
|
|
|
|
ORECV:
|
2015-02-17 22:13:49 -05:00
|
|
|
return true
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2015-02-17 22:13:49 -05:00
|
|
|
if hascallchan(n.Left) || hascallchan(n.Right) {
|
|
|
|
|
return true
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
2016-03-08 15:10:26 -08:00
|
|
|
for _, n1 := range n.List.Slice() {
|
|
|
|
|
if hascallchan(n1) {
|
2015-02-17 22:13:49 -05:00
|
|
|
return true
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
}
|
2016-03-08 15:10:26 -08:00
|
|
|
for _, n2 := range n.Rlist.Slice() {
|
|
|
|
|
if hascallchan(n2) {
|
2015-02-17 22:13:49 -05:00
|
|
|
return true
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-17 22:13:49 -05:00
|
|
|
return false
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|