1
0
mirror of https://github.com/golang/go synced 2024-11-17 14:44:44 -07:00
Commit Graph

49175 Commits

Author SHA1 Message Date
Robert Griesemer
bf0bc4122f go/types, types2: don't re-evaluate context string for each function argument (optimization)
Change-Id: Ie1b4d5b64350ea42484adea14df84cacd1d2653b
Reviewed-on: https://go-review.googlesource.com/c/go/+/344576
Trust: Robert Griesemer <gri@golang.org>
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
2021-08-25 23:43:42 +00:00
Robert Griesemer
4158e88f64 cmd/compile/internal/syntax: fix position of type parameter field
Change-Id: I8bca01b935301e7bd4efa55ed21921dbf31a75b9
Reviewed-on: https://go-review.googlesource.com/c/go/+/344575
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-08-25 23:43:41 +00:00
Robert Griesemer
647bef6c59 go/types: implement NewTypeList and use it instead of composite literals
Also, simplify a bit of code in predicates.go.

This is a backport of changes in CL 344615 that were made in addition
to the changes of the original CL 343933; it brings go/types in sync
with types2.

Change-Id: I14cd4d4704d29894d0fbb8d129744d65e332ad22
Reviewed-on: https://go-review.googlesource.com/c/go/+/344570
Trust: Robert Griesemer <gri@golang.org>
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
2021-08-25 23:43:40 +00:00
Jake Ciolek
6cf1d5d0fa cmd/compile: generic SSA rules for simplifying 2 and 3 operand integer arithmetic expressions
This applies the following generic integer addition/subtraction transformations:

x - (x + y) = -y
(x - y) - x = -y
y + (x - y) = x
y + (z + (x - y) = x + z

There's over 40 unique functions matching in Go. Hits 2 funcs in the runtime itself:

runtime.stackfree()
runtime.runqdrain()

Go binary size reduced by 0.05% on Linux x86_64.

StackCopy bench (perflocked Cascade Lake x86):

name                old time/op  new time/op  delta
StackCopyPtr-8      87.3ms ± 1%  86.9ms ± 0%  -0.45%  (p=0.000 n=20+20)
StackCopy-8         77.6ms ± 1%  77.0ms ± 0%  -0.76%  (p=0.000 n=20+20)
StackCopyNoCache-8  2.28ms ± 2%  2.26ms ± 2%  -0.93%  (p=0.008 n=19+20)

test/bench/go1 benchmarks (perflocked Cascade Lake x86):

name                     old time/op    new time/op    delta
BinaryTree17-8              1.88s ± 1%     1.88s ± 0%    ~     (p=0.373 n=15+12)
Fannkuch11-8                2.31s ± 0%     2.35s ± 0%  +1.52%  (p=0.000 n=15+14)
FmtFprintfEmpty-8          26.6ns ± 0%    26.6ns ± 0%    ~     (p=0.081 n=14+13)
FmtFprintfString-8         48.6ns ± 0%    50.0ns ± 0%  +2.86%  (p=0.000 n=15+14)
FmtFprintfInt-8            56.9ns ± 0%    54.8ns ± 0%  -3.70%  (p=0.000 n=15+15)
FmtFprintfIntInt-8         90.4ns ± 0%    88.8ns ± 0%  -1.78%  (p=0.000 n=15+15)
FmtFprintfPrefixedInt-8     104ns ± 0%     104ns ± 0%    ~     (p=0.905 n=14+13)
FmtFprintfFloat-8           148ns ± 0%     144ns ± 0%  -2.19%  (p=0.000 n=14+15)
FmtManyArgs-8               389ns ± 0%     390ns ± 0%  +0.35%  (p=0.000 n=12+15)
GobDecode-8                3.90ms ± 1%    3.88ms ± 0%  -0.49%  (p=0.000 n=15+14)
GobEncode-8                2.73ms ± 0%    2.73ms ± 0%    ~     (p=0.425 n=15+14)
Gzip-8                      169ms ± 0%     168ms ± 0%  -0.52%  (p=0.000 n=13+13)
Gunzip-8                   24.7ms ± 0%    24.8ms ± 0%  +0.61%  (p=0.000 n=15+15)
HTTPClientServer-8         60.5µs ± 6%    60.4µs ± 7%    ~     (p=0.595 n=15+15)
JSONEncode-8               6.97ms ± 1%    6.93ms ± 0%  -0.69%  (p=0.000 n=14+14)
JSONDecode-8               31.2ms ± 1%    30.8ms ± 1%  -1.27%  (p=0.000 n=14+14)
Mandelbrot200-8            3.87ms ± 0%    3.87ms ± 0%    ~     (p=0.652 n=15+14)
GoParse-8                  2.65ms ± 2%    2.64ms ± 1%    ~     (p=0.202 n=15+15)
RegexpMatchEasy0_32-8      45.1ns ± 0%    45.9ns ± 0%  +1.68%  (p=0.000 n=14+15)
RegexpMatchEasy0_1K-8       140ns ± 0%     139ns ± 0%  -0.44%  (p=0.000 n=15+14)
RegexpMatchEasy1_32-8      40.9ns ± 3%    40.5ns ± 0%  -0.88%  (p=0.000 n=15+13)
RegexpMatchEasy1_1K-8       215ns ± 1%     220ns ± 1%  +2.27%  (p=0.000 n=15+15)
RegexpMatchMedium_32-8      783ns ± 7%     738ns ± 0%    ~     (p=0.361 n=15+15)
RegexpMatchMedium_1K-8     24.1µs ± 6%    23.4µs ± 6%  -2.94%  (p=0.004 n=15+15)
RegexpMatchHard_32-8       1.10µs ± 1%    1.09µs ± 1%  -0.40%  (p=0.006 n=15+14)
RegexpMatchHard_1K-8       33.0µs ± 0%    33.0µs ± 0%    ~     (p=0.535 n=12+14)
Revcomp-8                   354ms ± 0%     353ms ± 0%  -0.23%  (p=0.002 n=15+13)
Template-8                 42.0ms ± 1%    41.8ms ± 2%  -0.37%  (p=0.023 n=14+15)
TimeParse-8                 181ns ± 0%     180ns ± 1%  -0.18%  (p=0.014 n=12+13)
TimeFormat-8                240ns ± 0%     242ns ± 1%  +0.69%  (p=0.000 n=12+15)
[Geo mean]                 35.2µs         35.1µs       -0.43%

name                     old speed      new speed      delta
GobDecode-8               197MB/s ± 1%   198MB/s ± 0%  +0.49%  (p=0.000 n=15+14)
GobEncode-8               281MB/s ± 0%   281MB/s ± 0%    ~     (p=0.419 n=15+14)
Gzip-8                    115MB/s ± 0%   115MB/s ± 0%  +0.52%  (p=0.000 n=13+13)
Gunzip-8                  786MB/s ± 0%   781MB/s ± 0%  -0.60%  (p=0.000 n=15+15)
JSONEncode-8              278MB/s ± 1%   280MB/s ± 0%  +0.69%  (p=0.000 n=14+14)
JSONDecode-8             62.3MB/s ± 1%  63.1MB/s ± 1%  +1.29%  (p=0.000 n=14+14)
GoParse-8                21.9MB/s ± 2%  22.0MB/s ± 1%    ~     (p=0.205 n=15+15)
RegexpMatchEasy0_32-8     709MB/s ± 0%   697MB/s ± 0%  -1.65%  (p=0.000 n=14+15)
RegexpMatchEasy0_1K-8    7.34GB/s ± 0%  7.37GB/s ± 0%  +0.43%  (p=0.000 n=15+15)
RegexpMatchEasy1_32-8     783MB/s ± 2%   790MB/s ± 0%  +0.88%  (p=0.000 n=15+13)
RegexpMatchEasy1_1K-8    4.77GB/s ± 1%  4.66GB/s ± 1%  -2.23%  (p=0.000 n=15+15)
RegexpMatchMedium_32-8   41.0MB/s ± 7%  43.3MB/s ± 0%    ~     (p=0.360 n=15+15)
RegexpMatchMedium_1K-8   42.5MB/s ± 6%  43.8MB/s ± 6%  +3.07%  (p=0.004 n=15+15)
RegexpMatchHard_32-8     29.2MB/s ± 1%  29.3MB/s ± 1%  +0.41%  (p=0.006 n=15+14)
RegexpMatchHard_1K-8     31.1MB/s ± 0%  31.1MB/s ± 0%    ~     (p=0.495 n=12+14)
Revcomp-8                 718MB/s ± 0%   720MB/s ± 0%  +0.23%  (p=0.002 n=15+13)
Template-8               46.3MB/s ± 1%  46.4MB/s ± 2%  +0.38%  (p=0.021 n=14+15)
[Geo mean]                205MB/s        206MB/s       +0.57%

Change-Id: Ibd1afdf8b6c0b08087dcc3acd8f943637eb95ac0
Reviewed-on: https://go-review.googlesource.com/c/go/+/344930
Reviewed-by: Keith Randall <khr@golang.org>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Josh Bleecher Snyder <josharian@gmail.com>
2021-08-25 19:45:20 +00:00
Joe Tsai
5baf60d472 bytes, strings: optimize Trim for single byte cutsets
Using the latest version of all modules known by the module proxy,
we determine that for all Trim usages (and related functionality):
* 76.6% have cutsets of len=1, and
* 13.4% have cutsets of len=2.

Given that a vast majority of usages only have a cutset of len=1,
we should more heavily optimize for that situation.
Previously, there was some optimization for cutsets of len=1,
but it's within the internal makeCutsetFunc function.
This is sub-optimal as it incurs an allocation in makeCutsetFunc
for the closure over that single byte.

This CL removes special-casing of one-byte cutsets from makeCutsetFunc
and instead distributes it directly in Trim, TrimRight, and TrimLeft.
Whether we should distribute the entire ASCII cutset logic into Trim
is a future CL that should be discussed and handled separately.
The evidence for multibyte cutsets is not as obviously compelling.

name                old time/op  new time/op  delta
bytes/TrimByte-4    84.1ns ± 2%   7.5ns ± 1%  -91.10%  (p=0.000 n=9+7)
strings/TrimByte-4  86.2ns ± 3%   8.3ns ± 1%  -90.33%  (p=0.000 n=9+10)

Fixes #46446

Change-Id: Ia0e31a8384c3ce111ae35465605bcec45df2ebec
Reviewed-on: https://go-review.googlesource.com/c/go/+/323318
Trust: Joe Tsai <joetsai@digital-static.net>
Run-TryBot: Joe Tsai <joetsai@digital-static.net>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
2021-08-25 19:29:15 +00:00
korzhao
3d667671ad cmd/compile: fix function contains no TParam in generic function
Fixes #47948

Change-Id: I446a9548265d195ae4d88aff6b1361474d1b6214
Reviewed-on: https://go-review.googlesource.com/c/go/+/344910
Trust: Alexander Rakoczy <alex@golang.org>
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Alexander Rakoczy <alex@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
2021-08-25 19:06:16 +00:00
korzhao
4f2ebfe34b cmd/compile: allow embed into any byte slice type
Fixes #47735

Change-Id: Ia21ea9a67f36a3edfef1b299ae4f3b00c306cd68
Reviewed-on: https://go-review.googlesource.com/c/go/+/342851
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Alexander Rakoczy <alex@golang.org>
2021-08-25 18:31:07 +00:00
korzhao
d2f002cb39 time/format: avoid growslice in time.String()/time.GoString()
Pre-allocate the slice of buf with enough capacity
to avoid growslice calls.

benchmark                   old ns/op     new ns/op     delta
BenchmarkTimeString-4       493           409           -17.12%
BenchmarkTimeGoString-4     309           182           -41.30%

benchmark                   old allocs     new allocs     delta
BenchmarkTimeString-4       5              3              -40.00%
BenchmarkTimeGoString-4     4              1              -75.00%

benchmark                   old bytes     new bytes     delta
BenchmarkTimeString-4       152           128           -15.79%
BenchmarkTimeGoString-4     248           80            -67.74%

Change-Id: I64eabe2ab0b3d4a846453c2e8e548a831d720b8c
Reviewed-on: https://go-review.googlesource.com/c/go/+/343971
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Alexander Rakoczy <alex@golang.org>
2021-08-25 18:27:41 +00:00
wdvxdr
08d4cc20ca cmd/compile: fix stencil call expression.
Fixes: #47878

Change-Id: I369350813726fd518b4eab2b98f43bf031a6dee6
Reviewed-on: https://go-review.googlesource.com/c/go/+/344210
Reviewed-by: Dan Scales <danscales@google.com>
Trust: Dan Scales <danscales@google.com>
Trust: Keith Randall <khr@golang.org>
Run-TryBot: Dan Scales <danscales@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-08-25 16:37:31 +00:00
Dan Scales
099b819085 cmd/compile: fix CheckSize() calculation for -G=3 and stencils
Because the Align/Width of pointer types are always set when created,
CalcSize() never descends past a pointer. Therefore, we need to do
CheckSize() at every level when creating type. We need to do this for
types creates by types2-to-types1 conversion and also by type
substitution (mostly for stenciling). We also need to do
Defer/ResumeCheckSize() at the top level in each of these cases to deal
with potentially recursive types.

These changes fix issue #47929 and also allow us to remove the
special-case CheckSize() call that causes the problem for issue #47901.

Fixes #47901
Fixes #47929

Change-Id: Icd8192431c145009cd6df2f4ade6db7da0f4dd3e
Reviewed-on: https://go-review.googlesource.com/c/go/+/344829
Trust: Dan Scales <danscales@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
2021-08-25 15:30:19 +00:00
Ian Lance Taylor
e1fcf8857e test: add test that caused gofrontend compiler crash
Updates https://gcc.gnu.org/PR101994

Change-Id: I50dcb90e315792efd7d83b496034ad33b5f199e9
Reviewed-on: https://go-review.googlesource.com/c/go/+/343874
Trust: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
2021-08-25 03:13:06 +00:00
Ian Lance Taylor
d37b8dedf7 test: add test case that gofrontend miscompiled
For #47771

Change-Id: I99dfdd48def756bde68445b50741afd6d86b6cf2
Reviewed-on: https://go-review.googlesource.com/c/go/+/344169
Trust: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
2021-08-25 03:12:43 +00:00
Kir Kolyshkin
41b99dab0f os/user: don't skip TestLookupGroup if supported
CL 37664 implemented this functionality, yet the tests were skipped.

Introduce and use additional variable groupListImplemented to
distinguish between these cases and enable TestLookupGroup for
supported configurations (which looks like all but plan9).

Change-Id: Iabaa7f08b4551dc67e67bdb6e715f15bb20d6218
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Reviewed-on: https://go-review.googlesource.com/c/go/+/330751
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
2021-08-25 03:07:54 +00:00
Cuong Manh Le
de1c934b97 cmd/compile: fix checkptr false positive for (*[Big]T)(ptr)[:n:n] pattern
The checkptr instrumentation is currently inserted before slice
operation has validated that n <= Big. So instead of panic, checkptr
have false positive throws.

To fix this, just insert the checkptr instrumentation after the bound
checking during SSA generation.

Fixes #46938

Change-Id: I9dbf84441c711842ccc883f3654ca8766ac696d8
Reviewed-on: https://go-review.googlesource.com/c/go/+/343972
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-08-25 01:57:42 +00:00
Josh Bleecher Snyder
54cdef1f10 reflect: add MapIter.SetKey and MapIter.SetValue
These augment the existing MapIter.Key and MapIter.Value methods.
The existing methods return new Values.
Constructing these new Values often requires allocating.
These methods allow the caller to bring their own storage.

The naming is somewhat unfortunate, in that the spec
uses the word "element" instead of "value",
as do the reflect.Type methods.
In a vacuum, MapIter.SetElem would be preferable.
However, matching the existing methods is more important.

Fixes #32424
Fixes #46131

Change-Id: I19c4d95c432f63dfe52cde96d2125abd021f24fa
Reviewed-on: https://go-review.googlesource.com/c/go/+/320929
Trust: Josh Bleecher Snyder <josharian@gmail.com>
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Keith Randall <khr@golang.org>
2021-08-24 22:23:12 +00:00
Keith Randall
5d863f89fe cmd/compile: simplify bad conversion check
Now that we're using OCONVIDATA(x) everywhere we formerly used
OIDATA(OCONVIFACE(x)), there should be no OCONVIFACE operations that
take a shape type.

Change-Id: I4fb056456c60481c6dfe7bc111fca6223567e6a8
Reviewed-on: https://go-review.googlesource.com/c/go/+/344577
Trust: Keith Randall <khr@golang.org>
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
2021-08-24 22:10:11 +00:00
Keith Randall
c2f96e686f cmd/compile: mark ODYNAMICDOTTYPE as an expression that can panic
Fixes #47924

Change-Id: I4325b3c4ed9d369d9ea778478285436e1b2ab08a
Reviewed-on: https://go-review.googlesource.com/c/go/+/344571
Trust: Keith Randall <khr@golang.org>
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
2021-08-24 18:31:34 +00:00
Dan Scales
5b64381155 cmd/compile: fix naming of types inside instantiations
Issues 47713 and 47877 were both due to problems with the names used for
instantiated functions/methods, which must be in sync with the names
used by types2.

 - Switched to using NameString() for writing out type arguments in
   instantiation names. This ensures that we are always adding the
   package to type names even for the local package. Previously, we were
   explicitly adding the package name for local packages, but that
   doesn't handle the case when the local type is embedded inside a
   pointer or slice type. By switching to NameString(), we fix #47713.

 - types1 and types2 write out 'interface {' differently (vs.
   'interface{') and we were already handling that. But we needed to add
   similar code to handle 'struct {' vs 'struct{'. This fixes issue
   #47877.

While fixing these bugs, I also moved some duplicated code (which
include some of the changes above) into a common function addTargs(). I
also moved InstType() name to subr.go, and renamed: MakeInstName ->
MakeFuncInstSym and MakeDictName -> MakeDictSym.

Also removed a couple of ".inst..inst." prefix checks which are
irrelvant now, since we don't add ".inst." anymore to function
instantiations.

Fixes #47713
Fixes #47877
Fixes #47922

Change-Id: I19e9a073451f3ababd8ec31b6608cd79ba8cba36
Reviewed-on: https://go-review.googlesource.com/c/go/+/344613
Trust: Dan Scales <danscales@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
2021-08-24 18:30:13 +00:00
Matthew Dempsky
4a9f0cec29 cmd/compile: change irgen to generate exprs/stmts after decls processed
This CL changes irgen to wait until all top-level declarations have
been processed before constructing any expressions or statements that
reference them. This is the same approach that typecheck used.

Mechanically, it splits varDecl and funcDecl (the two top-level
declarations that can generate/contain code) into a part that runs
immediately for constructing the ir.ONAME, and then a separate task
that runs later to handle the code.

It also adds an exprStmtOK flag to indicate when it's actually safe to
start constructing (non-trivial) expressions and statements.

Fixes #47928.

Change-Id: I51942af6823aa561d341e2ffc1142948da025fa2
Reviewed-on: https://go-review.googlesource.com/c/go/+/344649
Trust: Matthew Dempsky <mdempsky@google.com>
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Dan Scales <danscales@google.com>
2021-08-24 18:02:21 +00:00
crazycomputer
daa55b21d1 cmd/link: guarantee "section .debug_gdb_scripts" is always "$GOROOT/src/runtime/runtime-gdb.py".
to guarantee the "section .debug_gdb_scripts" is  always "$GOROOT/src/runtime/runtime-gdb.py" , a check for package name is needed when search "runtime/proc.go".

Fixes #47881

Change-Id: Ib471314ca1a6777f625b488e5ae3790457540ef9
Reviewed-on: https://go-review.googlesource.com/c/go/+/344229
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
Trust: Michael Knyszek <mknyszek@google.com>
2021-08-24 16:55:17 +00:00
Robert Griesemer
e6798795ff cmd/compile/internal/types2: use TypeList in the Inferred struct
This is a port of CL 343934 from go/types with the necessary
adjustments to the compiler.

Change-Id: I810144e6e2eb2bc8fa0d34dc206403c993cbbe7a
Reviewed-on: https://go-review.googlesource.com/c/go/+/344616
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Dan Scales <danscales@google.com>
2021-08-24 16:36:59 +00:00
Robert Griesemer
b1cdf860dd cmd/compile/internal/types2: use a TypeList type to hold type arguments
This is a port of CL 343933 from go/types with the necessary
adjustments in the compiler.

With this CL type parameters and type lists are now held in
TParamList and TypeList data types which don't expose the
internal representation.

Change-Id: I6d60881b5db995dbc04ed3f4a96e8b5d41f83969
Reviewed-on: https://go-review.googlesource.com/c/go/+/344615
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Dan Scales <danscales@google.com>
2021-08-24 16:36:55 +00:00
Robert Griesemer
1ff0554b53 cmd/compile/internal/types2: use []*TypeParam rather than []*TypeName for type param lists
This is a port of CL 343932 from go/types, with the necessary adjustments
to the compiler.

This change improves type safety slightly, avoids many internal type
assertions, and simplifies some code paths.

Change-Id: Ie9c4734814f49cd248927152d7b3264d3578428c
Reviewed-on: https://go-review.googlesource.com/c/go/+/344614
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Dan Scales <danscales@google.com>
2021-08-24 16:36:48 +00:00
Robert Griesemer
bd97763577 cmd/compile/internal/types2: use an opaque environment for Instantiate
This is a port of CL 343930 from go/types, adjusted to work for
the compiler: here Environment carries a *Checker, if available.

Change-Id: I44544fad7da870fa0c02832baa6abd2909d50304
Reviewed-on: https://go-review.googlesource.com/c/go/+/344612
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-08-24 16:36:47 +00:00
Robert Griesemer
bba460499c cmd/compile/internal/types2: don't export TypeSet
For now don't export TypeSet in the interest of
keeping the types2 API surface small(er).

This is a clean port of CL 341289 from go/types.

Change-Id: I50c747629f25472f2ec5ba59d7f543ee3c1c423b
Reviewed-on: https://go-review.googlesource.com/c/go/+/344610
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Dan Scales <danscales@google.com>
2021-08-24 16:36:46 +00:00
korzhao
d70c69d830 embed: document the maximum file size supported
Fixes #47627

Change-Id: Ia1edfb6249863ab055fab68a35666bc2bdf21dcb
Reviewed-on: https://go-review.googlesource.com/c/go/+/341689
Reviewed-by: Jay Conrod <jayconrod@google.com>
Trust: Michael Matloob <matloob@golang.org>
2021-08-24 15:55:38 +00:00
subham sarkar
f98b6111eb go/token: match the implementation of index selection with sort.Search
name          old time/op    new time/op    delta
SearchInts-8    15.5ns ± 2%    13.7ns ± 4%  -11.87%  (p=0.008 n=5+5)

(see CL 36332 for the original change to sort.Search)

Change-Id: If452818185b92b8b3548b066f475e493d604ea29
GitHub-Last-Rev: 32dd3cffa6
GitHub-Pull-Request: golang/go#47293
Reviewed-on: https://go-review.googlesource.com/c/go/+/335809
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Robert Griesemer <gri@golang.org>
Trust: Than McIntosh <thanm@google.com>
2021-08-24 15:52:22 +00:00
Dan Scales
8eeb1bff1d cmd/compile: reuse same node for global dictionaries
Change stencil.go:getDictionaryValue() and reflect.go:getDictionary() to
reuse any existing name node that has been created for the needed global
dictionary. Otherwise, these functions may set the Def on a specific
dictionary sym to two different name nodes, which means the first node
will not satisfy the invariant 'n.Sym().Def.(*ir.Name) == n' (which is
the assertion in this issue).

Fixes #47896

Change-Id: I1e7ae1efd077a83c7878b4342feb6d28d52476cc
Reviewed-on: https://go-review.googlesource.com/c/go/+/344609
Run-TryBot: Dan Scales <danscales@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Trust: Dan Scales <danscales@google.com>
2021-08-24 00:01:29 +00:00
Dan Scales
be1a693477 cmd/compile: fixes for non-constant Sizeof/Alignof/Offsetof
Includes Robert's suggested fix in validate.go to not fail on
non-constant alignof/offsetof/sizeof calls. Further changes to wait on
transforming these calls until stenciling time, when we can call
EvalConst() to evaluate them once all the relevant types are known.

Added a bunch of new tests for non-constant Sizeof/Alignof/Offsetof.

Fixes #47716

Change-Id: I469af888eb9ce3a853124d919eda753971009b3e
Reviewed-on: https://go-review.googlesource.com/c/go/+/344250
Run-TryBot: Dan Scales <danscales@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Dan Scales <danscales@google.com>
2021-08-23 22:55:34 +00:00
Martin Möhrmann
8157960d7f all: replace runtime SSE2 detection with GO386 setting
When GO386=sse2 we can assume sse2 to be present without
a runtime check. If GO386=softfloat is set we can avoid
the usage of SSE2 even if detected.

This might cause a memcpy, memclr and bytealg slowdown of Go
binaries compiled with softfloat on machines that support
SSE2. Such setups are rare and should use GO386=sse2 instead
if performance matters.

On targets that support SSE2 we avoid the runtime overhead of
dynamic cpu feature dispatch.

The removal of runtime sse2 checks also allows to simplify
internal/cpu further by removing handling of the required
feature option as a followup after this CL.

Change-Id: I90a853a8853a405cb665497c6d1a86556947ba17
Reviewed-on: https://go-review.googlesource.com/c/go/+/344350
Trust: Martin Möhrmann <martin@golang.org>
Run-TryBot: Martin Möhrmann <martin@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2021-08-23 21:22:58 +00:00
Martin Möhrmann
22540abf76 runtime: use RDTSCP for instruction stream serialized read of TSC
To measure all instructions having been completed before reading
the time stamp counter with RDTSC an instruction sequence that
has instruction stream serializing properties which guarantee
waiting until all previous instructions have been executed is
needed. This does not necessary mean to wait for all stores to
be globally visible.

This CL aims to remove vendor specific logic for determining the
instruction sequence with CPU feature flag checks that are
CPU vendor independent.

For intel LFENCE has the wanted properties at least
since it was introduced together with SSE2 support.

On AMD instruction stream serializing LFENCE is supported by setting
an MSR C001_1029[1]=1 on AMD family 10h/12h/14h/15h/16h/17h processors.
AMD family 0Fh/11h processors support LFENCE as serializing always.
AMD plans support for this MSR and access to this bit for all future processors.
Source: https://developer.amd.com/wp-content/resources/Managing-Speculation-on-AMD-Processors.pdf

Reading the MSR to determine LFENCE properties is not always possible
or reliable (hypervisors). The Linux kernel is relying on serializing
LFENCE on AMD CPUs since a commit in July 2019: https://lkml.org/lkml/2019/7/22/295
and the MSR C001_1029 to enable serialization has been set by default
with the Spectre v1 mitigations.

Using an MFENCE on AMD is waiting on previous instructions having been executed
but in addition also flushes store buffers.

To align the serialization properties without runtime detection
of CPU manufacturers we can use the newer RDTSCP instruction which
waits until all previous instructions have been executed.

RDTSCP is available on Intel since around 2008 and on AMD CPUs since
around 2006. Support for RDTSCP can be checked independently
of manufacturer by checking CPUID bits.

Using RDTSCP is the default in Linux to read TSC in program order
when the instruction is available.
e22ce8eb63/arch/x86/include/asm/msr.h (L231)

Change-Id: Ifa841843b9abb2816f8f0754a163ebf01385306d
Reviewed-on: https://go-review.googlesource.com/c/go/+/344429
Reviewed-by: Keith Randall <khr@golang.org>
Trust: Martin Möhrmann <martin@golang.org>
Run-TryBot: Martin Möhrmann <martin@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
2021-08-23 20:32:04 +00:00
Matthew Dempsky
fa34678c67 internal/buildcfg: change GOEXPERIMENT to always return non-empty string
Rather than returning "", we now return "," (which is a no-op). This
ensures that the returned string always overrides DefaultGOEXPERIMENT.

This fixes a bootstrapping issue where GOROOT_BOOTSTRAP was built with
"GOEXPERIMENT=fieldtrack ./make.bash". cmd/dist sets GOEXPERIMENT=none
during bootstrapping, which was causing cmd/go to set GOEXPERIMENT=""
when executing cmd/compile; but then cmd/compile ignores the
environment variable (because it's empty) and instead uses
DefaultGOEXPERIMENT.

Fixes #47921.

Change-Id: I657ff6cdfb294a94f6a2f58c306ceed7f104416b
Reviewed-on: https://go-review.googlesource.com/c/go/+/344511
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2021-08-23 20:04:34 +00:00
Martin Möhrmann
0a7f00ae23 cmd/compile: do not mark arrays used for map initialization noalg
Arrays marked noalg are created by the compiler to hold keys and values
to initialize map literals. The ssa backend creates a pointer type for
the array type when creating an OpAddr while processing the loop that
initializes the map from the arrays. The pointer type does not inherit
the noalg property but points to the noalg array type.

This causes values created through reflect of types that should be
equal to compare unequal because the noalg and alg type might be
compared and these are not the same.

A similar problem occurred in #32595 for argument arrays of defer structs.

Created #47904 to track improve noalg handling to be able to
reintroduce this optimization again.

Fixes #47068

Change-Id: I87549342bd404b98d71a3c0f33e3c169e9d4efc8
Reviewed-on: https://go-review.googlesource.com/c/go/+/344349
Trust: Martin Möhrmann <martin@golang.org>
Run-TryBot: Martin Möhrmann <martin@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-08-23 19:49:23 +00:00
zikaeroh
6b9e3f883e cmd/compile: don't emit write barriers for offsets of global addresses
Currently, write barriers aren't emitted for global addresses, but they
are emitted for addresses offset of global addresses.

This CL changes IsGlobalAddr to recognize offsets of global addresses
as globals too, removing write barriers for staticuint64s based
addresses. The logic added is the same as used in IsStackAddr.

Updates #37612

Change-Id: I537579f85b9ad02987d94f3ee0b4508b90097959
Reviewed-on: https://go-review.googlesource.com/c/go/+/342129
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Trust: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-08-23 19:46:36 +00:00
Keith Randall
3081f817da cmd/compile: always remove receiver type from instantiated method values
If a type T has a method foo, then

var t T
var i interface{} = t.foo

The type of foo is a method type, but the type of t.foo should be a
standard function type. Make sure we always do that conversion.

Fixes #47775

Change-Id: I464ec792196b050aba1914e070a4ede34bfd0bfa
Reviewed-on: https://go-review.googlesource.com/c/go/+/343881
Trust: Keith Randall <khr@golang.org>
Trust: Dan Scales <danscales@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Dan Scales <danscales@google.com>
2021-08-23 19:27:46 +00:00
Keith Randall
8486ced8b0 cmd/compile: copy captured dictionary var to local var
When starting a closure that needs a dictionary, copy the closure
variable to a local variable. This lets child closures capture that
dictionary variable correctly.

This is a better fix for #47684, which does not cause problems
like #47723.

Fixes #47723
Update #47684

Change-Id: Ib5d9ffc68a5142e28daa7d0d75683e7a35508540
Reviewed-on: https://go-review.googlesource.com/c/go/+/343871
Trust: Keith Randall <khr@golang.org>
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
2021-08-23 17:51:41 +00:00
Cuong Manh Le
aeec6dbfe0 spec: add example for method value in case of embedded method
So it's clear to the reader that if "M" is a promoted method from
embedded field "T", then "x.M" will be expanded to "x.T.M" during the
evaluation of the method value.

Fixes #47863

Change-Id: Id3b82127a2054584b6842c487f6e15c3102dc9fe
Reviewed-on: https://go-review.googlesource.com/c/go/+/344209
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-08-23 17:29:25 +00:00
Dan Scales
f457ecc7f0 cmd/compile: fixing 15.go for -G=3
Required two changes:

 - avoid creating a closure in the case where the actual receiver of an
   embedded method is not generic even though the base operand of the
   selector is generic. This is similar to the test suggested by wayne
   zuo - I thought it was clear in buildClosure, and easier to comment.

 - Propagate //go:nointerface to base generic methods and then to
   instantiations.

Change-Id: If30c834e4223c2639b7f7e74d44e6087aa9ccd76
Reviewed-on: https://go-review.googlesource.com/c/go/+/344251
Run-TryBot: Dan Scales <danscales@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Wayne Zuo <wdvxdr1123@gmail.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Trust: Dan Scales <danscales@google.com>
2021-08-23 16:57:27 +00:00
Lynn Boger
f1d8ea1da3 reflect: fix memmove for big endian cases with new ABI
Some memmoves in reflect/value.go for copying arguments
related to the new ABI were using the address of the target
or source instead of using IntArgRegAddr or FloatArgRegAddr
to adjust the address for big endian.

This was found when testing patches for ppc64 and fixes the
failures that were found.

Change-Id: I119aa090a2a8eb859020ff1a1736107a6d0b76f1
Reviewed-on: https://go-review.googlesource.com/c/go/+/343869
Run-TryBot: Lynn Boger <laboger@linux.vnet.ibm.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Trust: Michael Knyszek <mknyszek@google.com>
Trust: Lynn Boger <laboger@linux.vnet.ibm.com>
2021-08-23 15:27:42 +00:00
Robert Findley
4fbb5c8666 go/types: use TypeList in the Inferred struct
This is for consistency with how we report TArgs elsewhere, and in case
we ever want to share an internal slice with inference reporting.

Change-Id: Ia8b705a155f4f82bd8da8dc2457289810f875f5e
Reviewed-on: https://go-review.googlesource.com/c/go/+/343934
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-08-23 13:09:18 +00:00
Robert Findley
7a6d64fed6 go/types: use a TypeList type to hold type arguments
This resolves an asymmetry between the TParams and TArgs APIs, and
reduces the size of the Named struct at the cost of some additional nil
checks.

While at it, move TParamList and TypeList to a new file:typelists.go,
and change TParamList to access the tparams slice directly in At. There
is no reason to guard against a nil receiver, as accessing an index on
the empty slice will panic anyway.

Change-Id: I9b65247e06c697a57a4efe40c3390e0faff91441
Reviewed-on: https://go-review.googlesource.com/c/go/+/343933
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-08-23 13:09:11 +00:00
Robert Findley
2438660602 go/types: use []*TypeParam rather than []*TypeName type param lists
Making this change improves type safety slightly, and avoids many
internal type assertions.

Change-Id: I26519b0e57068e944e8243983ae90553d79e59c2
Reviewed-on: https://go-review.googlesource.com/c/go/+/343932
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-08-23 13:07:58 +00:00
Robert Findley
9fe5c7f122 go/types: add the TypeParam.Obj method
Users should be able to access the type name associated with a type
parameter.

Change-Id: I495c3b4377f9d4807b1e78ad341e573d4d3c7bff
Reviewed-on: https://go-review.googlesource.com/c/go/+/343931
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-08-23 13:07:43 +00:00
Robert Findley
baf2866956 go/types: move to an opaque environment for Instantiate
To match the API proposal, switch the first argument to Instantiate to
an opaque Environment handle, though for now this handle is
unimplemented.

Change-Id: I6207f0beafdf8497587abdad37db92f927db29b6
Reviewed-on: https://go-review.googlesource.com/c/go/+/343930
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-08-23 13:07:07 +00:00
Robert Findley
c7e354d9d1 go/types: return an error from Instantiate
This is a port of CL 342152 to go/types. Additionally, a panic was
removed from interface substitution, which is a fix from CL 333155 that
was previously missed.

A check for a nil Checker was also removed from types2.instantiate,
since check must not be nil in that method.

Change-Id: I4ea6bdccbd50ea2008ee6d870f702bee5cdd5a8e
Reviewed-on: https://go-review.googlesource.com/c/go/+/342671
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-08-23 12:26:30 +00:00
Martin Möhrmann
c1a14781ec runtime: remove unused cpu architecture feature variables from binaries
On amd64 this reduces go binary sizes by 176 bytes due to not referencing
internal/cpu.ARM64 and internal/cpu.ARM.

Change-Id: I8e4f31e2b1939b05eec2148b44d7cff7e0aeb30e
Reviewed-on: https://go-review.googlesource.com/c/go/+/344329
Trust: Martin Möhrmann <martin@golang.org>
Run-TryBot: Martin Möhrmann <martin@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-08-23 11:23:58 +00:00
Cuong Manh Le
457418b475 cmd/go: fix long test builders
CL 343732 enabled -G=3 by default. The types2 typechecker uses slighly
different error message format for language feature constraint.

The old typechecker format:

	vendor/example.net/need117/need117.go:5:16: cannot convert s (type []byte) to type *[4]byte:
		conversion of slices to array pointers only supported as of -lang=go1.17

The new format:

	vendor/example.net/need117/need117.go:5:17: conversion of slices to array pointers only supported as of -lang=go1.17

caused the long test builders failed.

This CL fixes the test by relaxing the regext pattern a bit, so it can
match both the format.

Change-Id: I1c4acaa9e34b6c08dccbbc3ce7a99d4cd79f748a
Reviewed-on: https://go-review.googlesource.com/c/go/+/344212
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-08-23 03:39:14 +00:00
Ignacio Hagopian
86ee89225a strings: smarter growth of temporal buffer and avoid copying on return
The implementation for single strings had two optimization opportunities:
1. Grow the temporary buffer by known size before appending.
2. Avoid a full copy of the result since the underlying buffer won't be mutated afterward.
Both things were leveraged by using a Builder instead of a byte slice.

Relevant benchmark results:

        name           old time/op    new time/op    delta
        SingleMatch-8    32.0µs ± 3%    26.1µs ± 3%  -18.41%  (p=0.000 n=9+10)

        name           old speed      new speed      delta
        SingleMatch-8   469MB/s ± 3%   574MB/s ± 3%  +22.56%  (p=0.000 n=9+10)

        name           old alloc/op   new alloc/op   delta
        SingleMatch-8    81.3kB ± 0%    49.0kB ± 0%  -39.67%  (p=0.000 n=10+10)

        name           old allocs/op  new allocs/op  delta
        SingleMatch-8      19.0 ± 0%      11.0 ± 0%  -42.11%  (p=0.000 n=10+10)

Change-Id: I23af56a15875206c0ff4ce29a51bec95fd48bb11
GitHub-Last-Rev: 403cfc3c27
GitHub-Pull-Request: golang/go#47766
Reviewed-on: https://go-review.googlesource.com/c/go/+/343089
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Robert Griesemer <gri@golang.org>
2021-08-22 23:49:55 +00:00
Robert Griesemer
29d7e5472b go/types: report argument type for unsafe.OffsetOf
This is a clean port of CL 344252 to go/types.

For #47895.

Change-Id: I48cbb97ec28fcfb4fdf483594be9d29426c117ac
Reviewed-on: https://go-review.googlesource.com/c/go/+/344254
Trust: Robert Griesemer <gri@golang.org>
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
2021-08-22 22:30:38 +00:00
Robert Griesemer
8fcc614360 cmd/compile/internal/types2: enable TestSelection API test
This test was never fully ported from go/types. Implement
a conversion function from syntax.Pos to string index so
that the test can be enabled again.

Also renamed the local variable syntax to segment to avoid
confusion with the syntax package.

Change-Id: I1b34e50ec138403798efb14c828545780f565507
Reviewed-on: https://go-review.googlesource.com/c/go/+/344253
Trust: Robert Griesemer <gri@golang.org>
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
2021-08-22 22:30:37 +00:00