Commit Graph

4234 Commits

Author SHA1 Message Date
Cuong Manh Le
1ae7ddc235 test: always run test in unified IR mode regardless of explicit -G flag
Currently, if a test explicitly specify -G flag, if that flag conflict
with compiler default -G flag, the test will be skipped. That's the
reason CL 346469 haven't fixed the unified IR stuff, but still make the
unified builder passed.

This CL makes run.go always run the test in unified IR mode, regardless
of the explicit -G flag specified.

Updates #48094

Change-Id: I959ecaff6aca07844f0ffcf36caa60cf0747e8ce
Reviewed-on: https://go-review.googlesource.com/c/go/+/347271
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Trust: Keith Randall <khr@golang.org>
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-09-02 06:44:04 +00:00
Robert Griesemer
df4c625d88 cmd/compile: disable type list syntax for the compiler
Add (temporary) syntax.AllowTypeLists mode to control the
acceptance of type lists; the compiler doesn't set it,
but existing syntax and types2 tests do so that the code
remains exercised while it exists.

Adjust various tests to use the type set notation.

Change-Id: I798e607912552db6bfe38a7cd4324b74c6bf4d95
Reviewed-on: https://go-review.googlesource.com/c/go/+/347249
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-09-02 01:06:17 +00:00
Michael Munday
ea51e223c2 cmd/{asm,compile}: add fused multiply-add support on riscv64
Add support to the assembler for F[N]M{ADD,SUB}[SD] instructions.
Argument order is:

  OP RS1, RS2, RS3, RD

Also, add support for the FMA intrinsic to the compiler. Automatic
FMA matching is left to a future CL.

Change-Id: I47166c7393b2ab6bfc2e42aa8c1a8997c3a071b3
Reviewed-on: https://go-review.googlesource.com/c/go/+/293030
Trust: Michael Munday <mike.munday@lowrisc.org>
Run-TryBot: Michael Munday <mike.munday@lowrisc.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Joel Sing <joel@sing.id.au>
2021-09-01 21:17:04 +00:00
Cuong Manh Le
711e1c8224 cmd/compile: fix irgen mis-handling invalid function declaration
In -G=3 mode, irgen use its own generated IR, which is mis-handling of
bodyless function and declared function with //go:noescape pragma.

Fix this by adopting the same logic in noder.funcDecl, which minor
change in linkname detection.

Fixes #48097

Change-Id: Ibef921c1f75e071ca61685e0cb4543f2ee5efc7f
Reviewed-on: https://go-review.googlesource.com/c/go/+/346470
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Dan Scales <danscales@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-09-01 19:51:25 +00:00
korzhao
5670ff4ae5 cmd/compile: fix conversions from TypeParam to interface
If the TypeParam has all the methods of an interface, allow conversions from TypeParam to interface

Fixes #47708

Change-Id: I40a82a31f6ea9354130dbe3bcfc83537094bf12c
Reviewed-on: https://go-review.googlesource.com/c/go/+/342509
Reviewed-by: Dan Scales <danscales@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Dan Scales <danscales@google.com>
Trust: Keith Randall <khr@golang.org>
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
2021-09-01 16:45:26 +00:00
Dan Scales
2dd7b770de cmd/compile: fix missing case for shape double-check function
Missing case types.TUNSAFEPTR in parameterizedBy().

Also realized there was the same missing case in the type substituter
(*Tsubster).Typ().

Fixes #48103

Change-Id: If71f1a6ef80932f0e2120d4c18b39a30189fd8fe
Reviewed-on: https://go-review.googlesource.com/c/go/+/346669
Reviewed-by: Keith Randall <khr@golang.org>
Trust: Dan Scales <danscales@google.com>
2021-09-01 02:51:18 +00:00
Cuong Manh Le
62ba72b353 cmd/compile: fix method expression lookup during import
CL 309831 fixed importing of method expressions, by re-using the same
code already have for ODOTMETH. But that code does not work with
embedded field.

To fix this, we need to calculate all methods of the receiver base type
of method expression, before looking up the selection.

Fixes #48088

Change-Id: Ia244d36a3ed0f989735eb57becdfa70a81912f57
Reviewed-on: https://go-review.googlesource.com/c/go/+/346489
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-09-01 02:16:30 +00:00
Keith Randall
1f83a8c16c cmd/compile: use the zero value for results of impossible indexing
type A [0]int
var a A
x := a[i]

Use the zero value for x instead of the "impossible" value. That lets
us at least compile code like this with -B, even though it can't
possibly run correctly.

Fixes #48092

Change-Id: Idad5cfab49e05f375c069b05addceed68a15299f
Reviewed-on: https://go-review.googlesource.com/c/go/+/346589
Trust: Keith Randall <khr@golang.org>
Run-TryBot: Keith Randall <khr@golang.org>
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-08-31 21:49:48 +00:00
Dan Scales
891470fbf7 cmd/compile: fix handling of Defn field during stenciling
When the Defn field of a name node is not an ONAME (for a closure
variable), then it points to a body node of the same function/closure.
Therefore, we should not attempt to substitute it at the time we are
substituting the local variables. Instead, we remember a mapping from the
Defn node to the nodes that reference it, and update the Defn fields of
the copied name nodes at the time that we create the new copy of the
Defn node.

Added some comments to the Defn field of ir.Name.

Moved the Defn (and Outer code, for consistency) from namelist() to
localvar(), since Defn needs to updated for all local variables, not
just those in a closure. Fixed case where .Defn was not being set
properly in noder2 for type switches. Fixed another case where the Defn
field had to be updated during transformSelect() because the Defn node
was being completely changed to a new node.

Fixed some spacing in typeswitch2.go

Fixes #47676
Fixes #48016

Change-Id: Iae70dd76575f4a647c1db79e1eba9bbe44bfc226
Reviewed-on: https://go-review.googlesource.com/c/go/+/346290
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Dan Scales <danscales@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2021-08-31 19:07:50 +00:00
Keith Randall
f27d6a23b0 cmd/compile: builtins may be in the unsafe package
Now that unsafe.Sizeof and friends can operate on generic parameters,
and evaluate to non-constants, we need to export/import them correctly.

Fixes #48094

Change-Id: If3ebf77255385cd5462e13fb7ced8b157ba3cf5b
Reviewed-on: https://go-review.googlesource.com/c/go/+/346469
Trust: Keith Randall <khr@golang.org>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2021-08-31 17:21:38 +00:00
Robert Griesemer
68152359fd cmd/compile/internal/types2: disallow aliases for generic types
The existing approach (alias name stands for generic type name)
is an exception: it's the only place where a generic type could
be used without explicit instantiation. The correct solution is
currently under discussion (see proposal issue #46477).

This CL requires that the RHS of an alias type declaration be
an instantiated non-generic type. If #46477 is accepted, the
implementation will require proper representation of alias
types.

Change-Id: Ie85b923213a64f39837e56e38e14757458272b93
Reviewed-on: https://go-review.googlesource.com/c/go/+/346294
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-08-31 16:43:46 +00:00
Dan Scales
8f4c020660 cmd/compile: fix bug with Inferred targs
We were using the type from the wrong Node (the partially filled-in
FUNCINST) rather than the original function node - which is pointed to
by the OFUNCINST)) to set the final fully-substituted type of the
OFUNCINST. So fixed the node reference. Also, added check so we don't do
any work at all if the OFUNCINST already has all type args filled in.

Added few extra cases to the test file issue48030.go, to cover
fully-specified type args, partially inferred type args, and fully
inferred type args.

Fixes #48030

Change-Id: If9e4f2e0514d68b9d241f30c423259133932b25b
Reviewed-on: https://go-review.googlesource.com/c/go/+/346229
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Dan Scales <danscales@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2021-08-30 21:22:35 +00:00
korzhao
b602daea1b cmd/compile: fix error when revcType is ptr in selectorExpr
Fixes #48056

Change-Id: I13ca4caadbabf02084f66ab28b4cf0c4a3705370
Reviewed-on: https://go-review.googlesource.com/c/go/+/346049
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-30 17:13:00 +00:00
citizen233
a29d9aad7a test/typeparam/sliceimp.dir: fix typo in a.go
Fixing a typo, comparision -> comparison

Change-Id: I369f95c251f155bc6a9a6b86077bcf1ab245fc3f
Reviewed-on: https://go-review.googlesource.com/c/go/+/345950
Reviewed-by: Alberto Donizetti <alb.donizetti@gmail.com>
Reviewed-by: Keith Randall <khr@golang.org>
Trust: Alberto Donizetti <alb.donizetti@gmail.com>
Trust: Keith Randall <khr@golang.org>
2021-08-30 01:55:58 +00:00
wdvxdr
f29abccd8a test: add test cases for issue47892.
This issue has been fixed in https://golang.org/cl/345411

Fixes: #47892

Change-Id: I13dd3814650913da065e5f24a0c61d30adb0633a
Reviewed-on: https://go-review.googlesource.com/c/go/+/345229
Reviewed-by: Dan Scales <danscales@google.com>
Trust: Dan Scales <danscales@google.com>
Trust: Keith Randall <khr@golang.org>
Trust: Alberto Donizetti <alb.donizetti@gmail.com>
Run-TryBot: Alberto Donizetti <alb.donizetti@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-08-29 14:10:21 +00:00
Cuong Manh Le
6df3aac4ae cmd/compile: fix offset-generator for storeOneLoad
storeOneLoad decompose Load that is then stored, the offset value must
be created on the same block with the Load to be dominated, otherwise,
it's unsafe if one does not dominate the other.

Fixes #48026

Change-Id: Iee5e6c5d3e1b09862afe4e65f7bcd771b4c57367
Reviewed-on: https://go-review.googlesource.com/c/go/+/345434
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: Keith Randall <khr@golang.org>
2021-08-28 17:05:43 +00:00
Dan Scales
d7a43e8912 cmd/compile: support type C comparable
Support 'type C comparable' properly by using the same logic as for
'type T error', since ErrorType and ComparableType are entirely
analogous.

Added support for 'any' type as well, as requested by Robert. (For the
future - we can't currently have 'any' anywhere other than in a
constraint.)

Fixes #47966

Change-Id: I68bd284ced9a8bfca7d2339cd576f3cb909b1b83
Reviewed-on: https://go-review.googlesource.com/c/go/+/345174
Trust: Dan Scales <danscales@google.com>
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Dan Scales <danscales@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-08-28 16:00:51 +00:00
Keith Randall
6a35e07512 cmd/compile: fix stenciling of conversions between interfaces
Conversions need to allow nil through.
We do that using a CONVIFACE instead of a DOTTYPE.

Also reorganize how nonempty interfaces are handled.
For nonempty to empty, a simple CONVIFACE suffices.
For nonempty to nonempty, we need to call the runtime to get the
new itab. Use the entry from the dictionary to identify the
target interface type (if parameterized).

Fixes #47925

Change-Id: I4ffeed964318bb3e270b06f558e6ab9c5bfc7188
Reviewed-on: https://go-review.googlesource.com/c/go/+/344830
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-27 16:41:29 +00:00
Keith Randall
4f0dedca71 cmd/compile: fix parameterized interfaces
type I[T any] interface{}

This is an interface, but it has a type parameter.
We need to distinguish that from an interface that is not parameterized.

That means when doing type substitution on an interface with
parameters, we need to make a new one.

Same for non-empty interfaces. Even if the type parameter is not
used in any method, we sill need to make a new type.

Similar case to tstruct, above.

Change-Id: I23ad9f21d2c4ef675bf3f7d84899d9e4919d05e7
Reviewed-on: https://go-review.googlesource.com/c/go/+/344578
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-27 15:03:09 +00:00
Dan Scales
d7e2e2ec2b cmd/compile: delay fillinMethods to deal with mutually-recursive types
We need to delay fillinMethods until we get to a top-level type, so we
know all the TFORW types have been filled in, and we can do the
substitutions required by fillinMethods.

Fixes #47710

Change-Id: I298de7e7753ed31a2c2b1ff04f35177a8afc7a66
Reviewed-on: https://go-review.googlesource.com/c/go/+/345149
Trust: Dan Scales <danscales@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
2021-08-27 01:42:38 +00:00
Dan Scales
c9e05fdcf7 cmd/compile: fix reference to generic type needed by crawler
This problem happens when you create a new local type that uses an
imported generic type (maybe just by instantiating it), and then that
local type needed to be included as part of an export. In that case, the
imported generic type is does not have a declaration in the local
package, so it is not necessarily created in types1, so the
crawler/export doesn't work.

To fix this issue, we just need to add a call to g.obj() for the base
generic type, to make sure that it will exist if needed later in the
compilation or for the crawler during export.

Fixes #47514

Change-Id: Ie756578f07ad0007de8a88ae909cf7534a22936e
Reviewed-on: https://go-review.googlesource.com/c/go/+/345411
Reviewed-by: Keith Randall <khr@golang.org>
Trust: Dan Scales <danscales@google.com>
2021-08-26 20:18:58 +00:00
Robert Griesemer
4068fb6c21 cmd/compile: always accept 1.18 syntax but complain if not 1.18
This CL configures the parser to always accept 1.18 syntax
(type parameters, type instantiations, interface elements),
even when -lang is set to an earlier release.

Instead, the type checker looks for 1.18 operations and
complains if the language version is set to an earlier
release.

Doing these checks during type checking is necessary because it
it is possible to write "generic" code using pre-1.18 syntax;
for instance, an imported generic function may be implicitly
instantiated (as in imported.Max(2, 3)), or an imported constraint
interface may be embedded in an "ordinary" interface.

Fixes #47818.

Change-Id: I83ec302b3f4ba7196c0a4743c03670cfb901310d
Reviewed-on: https://go-review.googlesource.com/c/go/+/344871
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-08-25 23:43:53 +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
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
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
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
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
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
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
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
Matthew Dempsky
c9912780ab cmd/compile: enable -G=3 by default
This CL changes cmd/compile's -G flag's default from 0 to 3, which
enables use of the new types2 type checker and support for type
parameters. The old type checker is still available with
-gcflags=all=-G=0.

The CL also updates the regress test harness to account for the change
in default behavior (e.g., to expect known types2 changes/failures).
However, the -G=0 mode is still being tested for now.

Copy of CL 340914 by danscales@, minus the cmd/internal/objabi.AbsFile
change (handled instead by CL 343731) and rebased to master branch.

Updates #43651.

Change-Id: I1f62d6c0a3ff245e15c5c0e8f3d922129fdd4f29
Reviewed-on: https://go-review.googlesource.com/c/go/+/343732
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2021-08-21 00:24:02 +00:00
korzhao
97d17dc023 test/typeparam: add a test case for issue46591
Fixes #46591

Change-Id: I4875092ecd7760b0cd487e793576ef7a9a569a0e
Reviewed-on: https://go-review.googlesource.com/c/go/+/343970
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
2021-08-20 21:00:08 +00:00
Cuong Manh Le
f67e31d643 test: enable regabi test on arm64
CL 324890 turned on register ABI by default on ARM64, causing neither
live.go nor live_regabi.go is run on ARM64.

This CL enables live_regabi.go test for ARM64.

Change-Id: I0c483a38b761c5a6f1fa9a5b3324b5da64907e61
Reviewed-on: https://go-review.googlesource.com/c/go/+/343531
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-20 19:58:13 +00:00
Matthew Dempsky
c85695a117 cmd/compile: add support for //go:nointerface for -G=3
This is used within Google's internal code repo, so getting it working
is a pre-req for enabling -G=3 by default.

Change-Id: Icbc570948c852ca09cdb2a59f778140f620244b2
Reviewed-on: https://go-review.googlesource.com/c/go/+/343429
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2021-08-19 00:26:22 +00:00
Keith Randall
687f2acf6a cmd/compile: only use dictionaries for conversions to type parameters
Conversions to regular concrete types should not be rewritten during
stenciling.

Fixes #47740

Change-Id: I2b45e22f962dcd2e18bd6cc876ebc0f850860822
Reviewed-on: https://go-review.googlesource.com/c/go/+/342989
Trust: Keith Randall <khr@golang.org>
Trust: Dan Scales <danscales@google.com>
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
2021-08-18 22:34:31 +00:00
Yasuhiro Matsumoto
4012fea822 all: fix typos
Change-Id: I83180c472db8795803c1b9be3a33f35959e4dcc2
Reviewed-on: https://go-review.googlesource.com/c/go/+/336889
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
2021-08-17 13:54:10 +00:00
Dan Scales
b7b790a71a cmd/compile: fix CONVIFACE case converting interface to empty interface
We need an extra case in convertToDictionary. In the case of an operand
which is an interface and converting to an empty interface, we don't
want to get the run-time type from the dictionary (which would be the
run-time type of the interface). We want to do a type-assert to the
empty interface.

Change-Id: I414247210168153151272fab198bfe82ad7b1567
Reviewed-on: https://go-review.googlesource.com/c/go/+/342009
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-17 13:23:13 +00:00
Cuong Manh Le
e61d1445ab cmd/compile: fix panic with dead hidden closures
Currently, for hidden closures, we always push them to compile queue
during typechecking. If the hidden closure is discarded from the outer
function body during deadcode, any desugaring phase after deadcode won't
be applied to the closure. Thus, some un-expected OPs are passed to
downstream passes, which they can't handle, the compiler goes boom!

To fix this, we keep track of discarded hidden closures during deadcode
pass, and won't compile them then.

Fixes #47712

Change-Id: I078717d5d1f4f2fa39cbaf610cfffbb042e70ceb
Reviewed-on: https://go-review.googlesource.com/c/go/+/342350
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-16 18:20:12 +00:00
Keith Randall
5a40100141 cmd/compile: fix dictionaries for nested closures
Capturing dictionary closure variables is ok.

Fixes #47684

Change-Id: I049c87117915e0c5a172b9665bfac2f91064b2d4
Reviewed-on: https://go-review.googlesource.com/c/go/+/342050
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-16 16:55:27 +00:00
Meng Zhuo
efd206eb40 cmd/compile: intrinsify Mul64 on riscv64
According to RISCV instruction set manual v2.2 Sec 6.1
MULHU followed by MUL will be fused into one multiply by microarchitecture

Benchstat on Hifive unmatched:
name          old time/op    new time/op    delta
Hash8Bytes       245ns ± 3%     186ns ± 4%  -23.99%  (p=0.000 n=10+10)
Hash320Bytes    1.94µs ± 1%    1.31µs ± 1%  -32.38%  (p=0.000 n=9+10)
Hash1K          5.84µs ± 0%    3.84µs ± 0%  -34.20%  (p=0.000 n=10+9)
Hash8K          45.3µs ± 0%    29.4µs ± 0%  -35.04%  (p=0.000 n=10+10)

name          old speed      new speed      delta
Hash8Bytes    32.7MB/s ± 3%  43.0MB/s ± 4%  +31.61%  (p=0.000 n=10+10)
Hash320Bytes   165MB/s ± 1%   244MB/s ± 1%  +47.88%  (p=0.000 n=9+10)
Hash1K         175MB/s ± 0%   266MB/s ± 0%  +51.98%  (p=0.000 n=10+9)
Hash8K         181MB/s ± 0%   279MB/s ± 0%  +53.94%  (p=0.000 n=10+10)

Change-Id: I3561495d02a4a0ad8578e9b9819bf0a4eaca5d12
Reviewed-on: https://go-review.googlesource.com/c/go/+/329970
Reviewed-by: Joel Sing <joel@sing.id.au>
Run-TryBot: Joel Sing <joel@sing.id.au>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Meng Zhuo <mzh@golangcn.org>
2021-08-16 13:50:11 +00:00
Ian Lance Taylor
a95f1b51be test: change issue10441.go from "build" to "compile"
We use "build" for tests in the main package with a main function.
We use "compile" for tests that are not in the main package.

Change-Id: I9876b55a9e4672277483fd24e69058d439c66658
Reviewed-on: https://go-review.googlesource.com/c/go/+/334329
Trust: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
2021-08-13 21:43:20 +00:00