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

49281 Commits

Author SHA1 Message Date
Robert Findley
7637345b6e go/internal/typeparams: remove typeparams.{Get,Set} (cleanup)
These helper functions are no longer necessary, now that type parameters
are enabled; we can access type parameters directly.

When considering the existence or non-existence of type parameters, we
can either check whether node.TParams != nil, or whether
node.TParams.NumFields() > 0. The heuristic I'm using for deciding
between these checks is as follows:
 - For data access, just check node.TParams != nil.
 - For producing errors if type parameters exist, check NumFields() > 0.

Change-Id: I6597536898e975564e9e8bf6a3a91bc798e0f110
Reviewed-on: https://go-review.googlesource.com/c/go/+/346549
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
2021-08-31 21:25:03 +00:00
Robert Findley
78d0f8c870 go/types: fix type set printing and add a test
This is a port of CL 344873 to go/types.

Change-Id: Iad41d6de166214178adf2123ac05023895f5208b
Reviewed-on: https://go-review.googlesource.com/c/go/+/346435
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
2021-08-31 21:24:09 +00:00
Robert Findley
ae2b2dc01a go/types: rename IsMethodSet to IsConstraint (cleanup)
This is a port of CL 344872 to go/types.

Change-Id: Id794f1fc3b86779ee32dbe5e656ffc747d44c3e2
Reviewed-on: https://go-review.googlesource.com/c/go/+/346434
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-31 21:23:49 +00:00
Robert Findley
b93581e47d go/types: add error reporting for 1.18 syntax if GoVersion is below 1.18
This is a port of CL 344871 to go/types. Unlike the compiler, go/parser
is already always producing 1.18 syntax, so the effect of this CL is to
add some additional errors when Config.GoVersion is below 1.18.

This is a non-trivial port, both due to different error reporting APIs
and due to interacting with declaration syntax nodes, which differ
between go/ast and cmd/compile/internal/syntax.

Change-Id: I8003a014e6eec5e554c24e9a6cfc0548ec534834
Reviewed-on: https://go-review.googlesource.com/c/go/+/346433
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-31 21:22:54 +00:00
Robert Findley
aed59d172a go/types: allow composite literals of type parameter type
This is a port of CL 342690 to go/types.

Change-Id: I27dcde237e400a84c3394a3579805014777830bc
Reviewed-on: https://go-review.googlesource.com/c/go/+/346432
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-31 20:39:39 +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
Martin Möhrmann
46121306d3 cmd/compile: remove folding of 32 bit pointer offsets on amd64
These rules were likely only used in the removed amd64p32 port.

Passes toolstash -cmp.

Change-Id: Ie626d1021bade7f7571d1bd5271fbe8676bb295e
Reviewed-on: https://go-review.googlesource.com/c/go/+/346509
Trust: Martin Möhrmann <martin@golang.org>
Run-TryBot: Martin Möhrmann <martin@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
2021-08-31 18:41:52 +00:00
Martin Möhrmann
144e0b1f6e cmd/compile: add MOVOstoreconst with offset folding on amd64
Replace MOVOstorezero with new MOVOstoreconst.
MOVOstoreconst has similar address folding rules then
other MOVstoreconst operations but only supports zero
as store value. Currently only MOVO stores with zero
values are generated. Using MOVOstoreconst with
SymValAndOff aux has the advantage that we can just
add one more MOVstoreconst variant to the existing rules.

The main effect of this CL is converting 16 byte zeroing
of a value on the stack from LEAQ+MOVUPS to just MOVUPS
which reduces binary size.

old:
LEAQ 0x20(SP), DX
MOVUPS X15, 0(DX)

new:
MOVUPS X15, 0x20(SP)

file      before    after     Δ       %
addr2line 3661568   3657472   -4096   -0.112%
asm       4566432   4562336   -4096   -0.090%
cgo       4305456   4301360   -4096   -0.095%
compile   22878528  22874512  -4016   -0.018%
cover     4517952   4513856   -4096   -0.091%
link      6287248   6283152   -4096   -0.065%
nm        3640768   3636672   -4096   -0.113%
objdump   4010592   4006496   -4096   -0.102%
pack      2188224   2184128   -4096   -0.187%
pprof     13429504  13421312  -8192   -0.061%
trace     10143968  10135776  -8192   -0.081%
vet       6868864   6864768   -4096   -0.060%

Change-Id: I08f5dd5ab9251448a4572d3ddd1e0c8cd417f5e3
Reviewed-on: https://go-review.googlesource.com/c/go/+/346249
Run-TryBot: Martin Möhrmann <moehrmann@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Trust: Martin Möhrmann <martin@golang.org>
2021-08-31 17:35:15 +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
Robert Griesemer
605d1aaea2 go/types, types2: union terms must be instantiated
Fixes #48083.

Change-Id: I77899d3e6edc806dee770403b3c3c4e2974d0e50
Reviewed-on: https://go-review.googlesource.com/c/go/+/346293
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-08-31 16:20:54 +00:00
Robert Griesemer
ded10d75a9 cmd/compile/internal/types2: remove superfluous ordinaryType calls
The value types in type assertions and type switches cannot be
constraint types (if there are, an error was reported earlier),
so there is no need to check again that they are not constraint
types.

This permits merging the ordinaryType call with varType, which
is the only place where it's needed.

Change-Id: I44a852377b3dddf53692f764e588801fb3d3c0a8
Reviewed-on: https://go-review.googlesource.com/c/go/+/346291
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-08-31 16:14:01 +00:00
Andy Pan
3920d6f208 runtime: eliminate the redundant for loop in runqget()
Change-Id: If9b283bbef3ff12a64d34b07491aee3396852f05
Reviewed-on: https://go-review.googlesource.com/c/go/+/317509
Reviewed-by: Austin Clements <austin@google.com>
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Keith Randall <khr@golang.org>
2021-08-31 13:54:19 +00:00
Matthew Dempsky
f118d145a5 cmd/compile: make unified IR more selective about method wrappers
This CL makes two changes to how unified IR emits method wrappers:

1. It no longer emits wrappers for defined types' underlying
types. Previously, a declaration like `type T struct { U }` would emit
wrappers for both `T` and `struct { U }`. Now they're only emitted for
`T`.

2. It emits method value wrappers only when OMETHVALUE nodes are
actually created, like how -G=0 works. Method values are relatively
rare, aren't needed for runtime type descriptors (unlike method
expression wrappers), and large projects end up spending a non-trivial
amount of time compiling these unneeded wrappers.

Change-Id: I21da97df3132ec12cc67debf62b5b2d282f481cf
Reviewed-on: https://go-review.googlesource.com/c/go/+/346230
Trust: Matthew Dempsky <mdempsky@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>
2021-08-31 08:41:16 +00:00
Tobias Klauser
d384ebde60 net: enable multicast listener tests on solaris/illumos
It seems everything is in place for these tests to pass on solaris and
illumos, so enable them.

Fixes #7399

Change-Id: If6defb651ef9c5059c1aeccbc4fc13a12a86b682
Reviewed-on: https://go-review.googlesource.com/c/go/+/346149
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Trust: Damien Neil <dneil@google.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
2021-08-31 04:26:31 +00:00
Robert Findley
7622e41c84 go/types, types2: add a test for invalid import of "init"
This error reporting code path did not have test coverage, and panics in
1.17 (filed as #48082).

Add a test that would have reproduced the panic, for both go/types and
cmd/compile/internal/types2.

Change-Id: Icd5f54f8407e4ab57d432f44a129ecf6b2755feb
Reviewed-on: https://go-review.googlesource.com/c/go/+/346309
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
2021-08-30 22:09:22 +00:00
Robert Griesemer
3342aa5f51 cmd/compile/internal/types2: more systematic error handling in typeWriter
When using a typeWriter for debugging/error message type strings,
it shouldn't crash in the presence of type-checker internal bugs.
But when a typeHasher is used, we don't want to silently ignore
errors.

Introduce an error method that panics in type hashing mode but
prints an error value otherwise.

Also fixed an incorrect 'if' statement in tParamList.

Change-Id: I26c8b8e0b14396e91ad71bf903e36ce1ca55839e
Reviewed-on: https://go-review.googlesource.com/c/go/+/346009
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-08-30 22:07:53 +00:00
Robert Griesemer
b06cfe9b25 cmd/compile/internal/types2: eliminate typeHashing global variable
Instead, keep track of hashing mode with a typeWriter field.
Introduce a new constructor (newTypeHasher) to set the mode.

Change-Id: Ie69cc0382532c75973794326be15c884b7fdcb76
Reviewed-on: https://go-review.googlesource.com/c/go/+/345929
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-08-30 22:07:49 +00:00
Robert Griesemer
437362ccec cmd/compile/internal/types2: generalize instanceHash to accept any type, rename to typeHash
Rename instanceHashing accordingly.

Eventually, this will make it possible to use typeHash to detect
multiple identical types in type switch cases and other places.

Also fix some bugs: When creating a type hash, the name of function
parameters must be ignored because they don't matter for type
identity. And when printing a type name, don't assume its type
is a *Named type; it could be a *Basic type as well.

Finally, use a correctly qualified type string when reporting
a duplicate type error in a type switch case rather than the
(debugging) type string.

Change-Id: Ida3873f6259b51847843b0e2d7e3aa2fcdc3a0c3
Reviewed-on: https://go-review.googlesource.com/c/go/+/345791
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-08-30 22:07:43 +00:00
Quim Muntal
86fa510d24 go/types, types2: types in method expressions must be instantiated
Use varType instead of instantiatedOperand to check if the type of a method expressions is instantiated.

This removes the last usage of instantiatedOperand, so it can be deleted.

Fixes #48048

Change-Id: I2b219dafe2bba3603100bb8f25b8ff4e8ef53841
Reviewed-on: https://go-review.googlesource.com/c/go/+/345970
Trust: Robert Griesemer <gri@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-08-30 21:51:52 +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
Robert Griesemer
8250141c9a cmd/compile/internal/types2: don't print instance markers for type hashes
Since we know whether we are printing a type string used as
instance hash, don't print instance markers, so that we don't
need to remove them afterwards either.

Change-Id: Ib01627b6da989ef89d51e734810a3377eb466925
Reviewed-on: https://go-review.googlesource.com/c/go/+/345891
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-08-30 20:22:43 +00:00
Robert Griesemer
5f0d821add cmd/compile/internal/types2: use a typeWriter to write types (cleanup)
Rather then passing through a buffer, qualified, and visited
list to each helper function, maintain state in a typeWriter
object and use methods on it. This cleans up this code quite
a bit.

Use a map ("seen") for cycle detection rather than a list.

Move printing of [ and ] for type lists into the typeList
method so that callers don't have to do it themselves.

Change-Id: I1346373e979cb90710fbc073953aa51e2f6581f9
Reviewed-on: https://go-review.googlesource.com/c/go/+/345890
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-08-30 20:22:38 +00:00
Bryan C. Mills
61120c634c cmd/go/internal/modload: use "pruned" instead of "lazy" to describe pruned module graphs
The level of support for pruning — not the lazy/eager loading behavior
— is the more fundamental property, and what matters in terms of what
invariants we need to maintain.

If the main module supports pruned module graphs we load its
dependencies lazily, and if it does not support pruned module graphs
we load its dependencies eagerly. However, in principle we could also
load the module graph lazily even in modules that do not support graph
pruning — we would just be more likely to overlook inconsistent
requirements introduced by hand-edits or bad VCS merges to the go.mod
file.

(After this change, a “lazy” module is just one in which we happen not
to have loaded the module graph, and an “eager” one is one in which we
happen to load the module graph more aggressively.)

Updates #36460
For #47397

Change-Id: I0d2ffd21acc913f72ff56b59a6bdc539ebc3d377
Reviewed-on: https://go-review.googlesource.com/c/go/+/345393
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
2021-08-30 20:08:45 +00:00
Bryan C. Mills
af9009a989 cmd/go/internal/modload: remove go117LazyTODO
Replace the last remaining use with a reference to #48024.

Change-Id: I699711b4e42abe9c6d3512c28d2ee81a84e3263a
Reviewed-on: https://go-review.googlesource.com/c/go/+/345392
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
2021-08-30 20:08:37 +00:00
Bryan C. Mills
9da7ccab58 cmd/go/internal/modload: remove go117EnableLazyLoading
Updates #36460

Change-Id: I19f375f58f118e83a2615a29bbbb3853f059f0bb
Reviewed-on: https://go-review.googlesource.com/c/go/+/345391
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
2021-08-30 20:08:26 +00:00
Jay Conrod
bdc1bef8a0 cmd/go: ensure 'go get -u' can upgrade pruned (1.17+) modules
Fixes #47768

Change-Id: I981a31ba4ff716570ac4c6f35b289fa480faa5bb
Reviewed-on: https://go-review.googlesource.com/c/go/+/343879
Trust: Jay Conrod <jayconrod@google.com>
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2021-08-30 17:58:12 +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
Koichi Shiraishi
7b38dd8e25 runtime: remove unnecesarry newline on freeStackSpans
Change-Id: I16a3241d8818c67922ddbf7830b8c2c5f317e1a7
Reviewed-on: https://go-review.googlesource.com/c/go/+/338209
Reviewed-by: Austin Clements <austin@google.com>
Run-TryBot: Austin Clements <austin@google.com>
Trust: Keith Randall <khr@golang.org>
2021-08-30 16:00:10 +00:00
Matthew Dempsky
56c3856d52 cmd/compile/internal/types: unexport Type.widthCalculated
It's not needed outside of package types anymore.

Change-Id: Idadf915fc254920ca778b5f5f8de8a1300da1953
Reviewed-on: https://go-review.googlesource.com/c/go/+/345794
Trust: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: 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>
2021-08-30 02:40:46 +00:00
Matthew Dempsky
21d0b306af cmd/compile/internal/types: remove unused Tie method
Once upon a time, this was used by package walk to compute the
"conv[TIE]2[TIE]" function names, etc.; but it seems like those
callers have all changed to directly specializing on IsInterface and
IsEmptyInterface instead.

Change-Id: I629cdf076a09e7255ae293b8f879db0cdcf4de5b
Reviewed-on: https://go-review.googlesource.com/c/go/+/345793
Trust: Matthew Dempsky <mdempsky@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>
2021-08-30 02:40:35 +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
Kir Kolyshkin
f4cd001b57 os/user: simplify skipping listGroups test
This is not implemented on AIX and Illumos, and we already have a
mechanism to skip the test case -- let's use it.

Change-Id: Idb1cc2d716cf6d0731e93dfc3aa7853b9edec41f
Reviewed-on: https://go-review.googlesource.com/c/go/+/330752
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-08-28 18:48:37 +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
Cuong Manh Le
5afa555428 cmd/compile: fix wrong check for b.Controls in isBlockMultiValueExit
b.Controls has type [2]*Value, thus len(b.Controls) > 0 is always true.
The right check should be b.Controls[0] != nil, though, this is also
always true, since when we always set control value for BlockRet and
BlockRetJmp when state.exit is called.

Though checkFunc also checks for nil control value of ret/retjmp, but
it happens later after expand_calls pass, so better to be defensive
here, just in case.

Change-Id: Ie4a292a3494dfbf5e6d872cde498703023b84d00
Reviewed-on: https://go-review.googlesource.com/c/go/+/345433
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 16:58:26 +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
Cuong Manh Le
044550ab0e runtime: add test case for checkptr alignment with nested expression
Discover while working on moving checkptr instrumentation from walk to
SSA generation.

Change-Id: I3f4a41fe4ad308b86c7c57d14b6ccc7c613e7f98
Reviewed-on: https://go-review.googlesource.com/c/go/+/345432
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-28 06:22:11 +00:00
Cuong Manh Le
010817714e cmd/compile: ignore SliceExpr.CheckPtrCall for mknode
CL 343972 added SliceExpr.CheckPtrCall field but forgot to add ignore
tag for mknode. This CL adds the missing tag.

Change-Id: Ib39bff3d456063bdc10fc17b4047b8392d373bf1
Reviewed-on: https://go-review.googlesource.com/c/go/+/345431
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-08-28 04:46:13 +00:00
Joe Tsai
f371b30f32 unicode/utf8: add AppendRune
AppendRune appends the UTF-8 encoding of a rune to a []byte.
It is a generally more user friendly than EncodeRune.

    EncodeASCIIRune-4     2.35ns ± 2%
    EncodeJapaneseRune-4  4.60ns ± 2%
    AppendASCIIRune-4     0.30ns ± 3%
    AppendJapaneseRune-4  4.70ns ± 2%

The ASCII case is written to be inlineable.

Fixes #47609

Change-Id: If4f71eedffd2bd4ef0d7f960cb55b41c637eec54
Reviewed-on: https://go-review.googlesource.com/c/go/+/345571
Trust: Joe Tsai <joetsai@digital-static.net>
Reviewed-by: Rob Pike <r@golang.org>
Run-TryBot: Rob Pike <r@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
2021-08-28 01:49:50 +00:00
Matthew Dempsky
ef4cb2f776 cmd/compile/internal/types: change NewNamed to use TypeObject
Semantically, TypeObject is the interface that go/types.TypeName would
implement, so we might as well use that instead of the more generic
Object (analog to go/types.Object) for NewNamed. In practice, this
doesn't really matter though, because we use *ir.Name for almost all
Objects anyway.

Also, remove VarObject: its last use was removed in CL 302071 (March
2021).

Change-Id: I6e987ecd419105e09f74fc8d60cadb61bcbc751f
Reviewed-on: https://go-review.googlesource.com/c/go/+/345810
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
2021-08-28 01:26:53 +00:00
Robert Griesemer
5fb177163b go/types, types2: types in type switch cases must be instantiated
We already have a function that does all the right checks and it's called
varType. The only reason it wasn't used for type switch cases was that we
also have to accept the nil value. That was handled with typeOrNil. But
that function (typeOrNil) was only used for this specific purpose and I long
wished to get rid of it. It turns out that there's only one way to write the
untyped value nil, which is to actually write "nil" (maybe with parentheses).
So looking for that turned out to be simpler than using typeOrNil.

The new code does exactly that, and now we can just use varType and delete
typeOrNil. With this, there is now less code (excluding the test) and the code
is simpler and more correct.

Fixes #48008.

Change-Id: I8f2d80e61ae663c886924909f22bbfa634e7779c
Reviewed-on: https://go-review.googlesource.com/c/go/+/345790
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-08-28 00:51:39 +00:00
Matthew Dempsky
c81fa001a7 cmd/compile/internal/types: simplify and optimize PtrDataSize
The current implementation of PtrDataSize checks HasPointers each
call, which could lead to exponential blow-up in handling (admittedly
contrived) deeply nested structs.

To avoid the duplicate recursion, this CL incorporates the HasPointers
logic directly int PtrDataSize, and then re-defines HasPointers as
simply "PtrDataSize(t) > 0".

This CL also tightens up HasPointers/PtrDataSize to only be valid on
actual Go types. Fortunately, there was only one instance where this
wasn't already the case (escape analysis), and that's easily fixed
with an extra check for untyped types.

Change-Id: I0044bf9b558a88333aee2ccb137afb6cb4fea1db
Reviewed-on: https://go-review.googlesource.com/c/go/+/345809
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-08-28 00:50:13 +00:00
Matthew Dempsky
a9377183d0 cmd/compile/internal/types: unexport New and NewBasic
Now that the universe is fully initialized within package types, we
can stop exporting New and NewBasic, which are only needed for that
purpose. So this CL renames "New" to "newType" and "NewBasic" to
"newBasic".

This CL also moves the initialization of Types[TBLANK] and Types[TNIL]
from typecheck.InitUniverse to types.InitTypes, which I missed in an
earlier CL. And a use of "New(TSTRING)" in test/abiutils_test.go,
which should just be "Types[TSTRING]" anyway.

Change-Id: I1d83f93e27b88be289d4f3f6c16357a20f570460
Reviewed-on: https://go-review.googlesource.com/c/go/+/345487
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-08-27 23:06:52 +00:00
Matthew Dempsky
82efc05403 cmd/compile: use Type.OrigSym getter/setters [generated]
Automated CL to rewrite existing code to use OrigSym getters and
setters. Afterwards, we also unexported OrigSym, and then rename the
getter to OrigSym.

[git-generate]
cd src/cmd/compile/internal

: Workaround rf issue with types2 tests.
rm types2/*_test.go

rf '
ex ./noder ./typecheck {
import "cmd/compile/internal/types"
var s *types.Sym
var t *types.Type

t.OrigSym = s -> t.SetOrigSym(s)
t.OrigSym     -> t.OrigSym_()
}
'

cd types
rf '
mv Type.OrigSym Type.origSym
mv Type.OrigSym_ Type.OrigSym
'

: Revert types2 hack.
cd ../types2
git checkout HEAD^ .

Change-Id: I8eb17098613b1575df56b8189b1615823071d3d1
Reviewed-on: https://go-review.googlesource.com/c/go/+/345485
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Trust: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2021-08-27 21:27:59 +00:00
Matthew Dempsky
68ecdc2c70 cmd/compile/internal/types: add Type.OrigSym getter/setters
Will be used in the next CL, so that Type.OrigSym can be unexported.

Change-Id: I085f2a886abd419343c7ec7e4ae18c19de1fbbd4
Reviewed-on: https://go-review.googlesource.com/c/go/+/345484
Trust: Matthew Dempsky <mdempsky@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>
2021-08-27 20:43:38 +00:00
Matthew Dempsky
72c003ef82 cmd/compile: unexport Type.Width and Type.Align [generated]
[git-generate]
cd src/cmd/compile/internal

: Workaround rf issue with types2 tests.
rm types2/*_test.go

: Rewrite uses. First a type-safe rewrite,
: then a second pass to fix unnecessary conversions.
rf '
ex ./abi ./escape ./gc ./liveness ./noder ./reflectdata ./ssa ./ssagen ./staticinit ./typebits ./typecheck ./walk {
  import "cmd/compile/internal/types"
  var t *types.Type
  t.Width -> t.Size()
  t.Align -> uint8(t.Alignment())
}

ex ./abi ./escape ./gc ./liveness ./noder ./reflectdata ./ssa ./ssagen ./staticinit ./typebits ./typecheck ./walk {
  import "cmd/compile/internal/types"
  var t *types.Type
  int64(uint8(t.Alignment())) -> t.Alignment()
}
'

: Rename fields to lower case.
(
cd types
rf '
mv Type.Width Type.width
mv Type.Align Type.align
'
)

: Revert types2 changes.
git checkout HEAD^ types2

Change-Id: I42091faece104c4ef619d9d4d50514fd48c8f029
Reviewed-on: https://go-review.googlesource.com/c/go/+/345480
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-08-27 20:43:31 +00:00
Michael Matloob
94f2a03951 cmd: update requirement on golang.org/x/mod
Commands run:
  go get golang.org/x/mod@master
  go mod vendor
  go mod tidy

This change pulls in the x/mod on master. Before it was pulled in on
the dev.cmdgo branch of x/mod, but now that the workspace changes have
been pulled into x/mod, we can change the requirement back on to the
main branch.

Change-Id: I296799a87ecc08ba17c0722e955f000426b105ef
Reviewed-on: https://go-review.googlesource.com/c/go/+/345390
Trust: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
2021-08-27 18:01:06 +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