1
0
mirror of https://github.com/golang/go synced 2024-11-12 01:10:21 -07:00
Commit Graph

48512 Commits

Author SHA1 Message Date
Matthew Dempsky
4c072c94dc [dev.typeparams] cmd/compile: refactor import reading
This CL restructures the gcimports importer to mmap the export data
into memory as a string, and then pass that same string to both the
typecheck and types2 importers.

This is primarily motivated by preparation for unified IR; but it
should also improve performance (fewer string copies) and reduces
divergance between the two importers.

Passes toolstash -cmp.

Change-Id: I397f720693e9e6360bfcb5acb12609ab339d251f
Reviewed-on: https://go-review.googlesource.com/c/go/+/325210
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Trust: Matthew Dempsky <mdempsky@google.com>
Trust: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-06-05 23:28:52 +00:00
DQNEO
e1fa26026d spec: improve wording consistency by eliminating "specifier"
The word "specifier" is used once only here and technically not defined.

Change-Id: Ifc9f0582f4eb3c3011ba60d8008234de511d4be6
Reviewed-on: https://go-review.googlesource.com/c/go/+/323730
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Ian Lance Taylor <iant@golang.org>
Trust: Robert Griesemer <gri@golang.org>
2021-06-05 19:52:26 +00:00
DQNEO
f490134126 spec: improve wording by choosing an official term "keyword"
Replace "reserved word" by "keyword" as the latter is the official term.

Change-Id: I9f269759b872026034a9f47e4a761cff2d348ca0
Reviewed-on: https://go-review.googlesource.com/c/go/+/323729
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Ian Lance Taylor <iant@golang.org>
Trust: Robert Griesemer <gri@golang.org>
2021-06-05 19:51:45 +00:00
Sergey Zagursky
e3cb381704 go/internal/gcimporter: don't waste CPU copying bytes in io.ReadAll
`io.ReadAll` dynamically reallocates byte slice because it doesn't know
its size in advance. We don't need to read an entire file into memory
and therefore may use `bufio.Reader` to read its contents.

Fixes #46564

Change-Id: Id504b1512662b6dea4775d523455896fa4162ab3
Reviewed-on: https://go-review.googlesource.com/c/go/+/325429
Reviewed-by: Dominik Honnef <dominik@honnef.co>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Trust: Matthew Dempsky <mdempsky@google.com>
Trust: Dominik Honnef <dominik@honnef.co>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-06-05 09:28:43 +00:00
Ian Lance Taylor
9d669ed47a misc/cgo/errors: use expected column numbers
The test was using the wrong column numbers, and was erroneously
passing because there happened to be line numbers that matched those
column numbers. Change the test harness to require the expected line
number for the ERROR HERE regexp case, so that this doesn't happen again.

Also rename a couple of variables in the test to avoid useless
redeclaration errors.

Fixes #46534

Change-Id: I2fcbf5e379c346de5346035c73d174a3980c0927
Reviewed-on: https://go-review.googlesource.com/c/go/+/324970
Trust: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-06-05 04:40:03 +00:00
Matthew Dempsky
4e001a8d9e [dev.typeparams] runtime/race: make test compatible with types2
types2 correctly distinguishes variable assignment from use even
within function literals. Whatever the outcome of #3059, the test
cases in runtime/race need to be fixed to accomodate that.

Change-Id: Ibe3547f07b681ff41225caabaf050872a48c98d1
Reviewed-on: https://go-review.googlesource.com/c/go/+/325030
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-06-05 02:01:10 +00:00
Robert Griesemer
246a5570be [dev.typeparams] cmd/compile: rename (types2.Inferred.)Targs to TArgs
This is consistent with Named.TArgs.

This is a straight-forward port of https://golang.org/cl/321289
plus the necessary compiler noder changes.

Change-Id: I50791e5abe0d7f294293bed65cebc8dde8bf8c06
Reviewed-on: https://go-review.googlesource.com/c/go/+/325010
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-06-05 01:52:30 +00:00
Robert Griesemer
692399fbaa [dev.typeparams] cmd/compile/internal/syntax: not all index expressions can be instantiated types
An index expression followed by an opening "{" may indicate
a composite literal but only if the index expression can be
a type. Exclude cases where the index expression cannot be
a type (e.g. s[0], a[i+j], etc.).

This leads to a better error message in code that is erroneous.

Fixes #46558.

Change-Id: Ida9291ca30683c211812dfb95abe4969f44c474f
Reviewed-on: https://go-review.googlesource.com/c/go/+/325009
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-06-05 01:52:24 +00:00
Matthew Dempsky
a94e4f5a85 [dev.typeparams] cmd/compile: point StructKeyExpr at the types.Field
When constructing struct literals, importers need a way to specify
precisely which field to initialize without worrying about visibility
or those fields being blank. (A blank field doesn't actually need to
be initialized, but the expression needs to be evaluated still, and
with the right order-of-operations.)

This CL changes StructKeyExpr's Field field to point directly to the
corresponding types.Field, rather than merely holding a copy of its
Sym and Offset. This is akin to past changes to add
SelectorExpr.Selection.

Change-Id: I95b72b1788f73206fcebc22b456cf6b1186db6a7
Reviewed-on: https://go-review.googlesource.com/c/go/+/325031
Trust: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-06-04 21:07:19 +00:00
sryoya
95939e8de7 cmd/compile/internal/abi: fix typo in comment
Change-Id: I196045314b2b0e908d7b31ac0cea5b25404f3ee0
Reviewed-on: https://go-review.googlesource.com/c/go/+/325249
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Trust: Keith Randall <khr@golang.org>
2021-06-04 20:51:27 +00:00
Keith Randall
bad388744b [dev.typeparams] cmd/compile: handle dictionaries for top-level instantiations
There's no outer function in these cases, so we won't be reading
the dictionary as a subdictionary from the outer scope's dictionary.
It will always be a compile-time constant.

Change-Id: I754b126652a6ffb62255734d53fcec29d77cfa9e
Reviewed-on: https://go-review.googlesource.com/c/go/+/324949
Trust: Keith Randall <khr@golang.org>
Trust: Dan Scales <danscales@google.com>
Reviewed-by: Dan Scales <danscales@google.com>
2021-06-04 18:11:39 +00:00
Dan Scales
de61465156 [dev.typeparams] cmd/compile: allow inlining in instantiated functions
Change markType to scan generic types and methods, so that inlineable
functions inside generic functions/methods will be properly marked for
export, which means inlining inside instantiated functions will work
correctly.

Also, fix handling of closures for instantiated functions. Some code
needs to be adjusted, since instantiated functions/methods are compiled
as if in the package of the source generic function/type, rather than in
the local package. When we create the closure struct, we want to make
sure that the .F field has the same package as the other fields for the
closure variables. Also, we need to disable a check in tcCompLit() when
being done for an instantiated function, since fields of the closure
struct will be from the source package, not the local package.

Re-enabled part of the orderedmapsimp test that was disabled because of
these issues.

Change-Id: Ic4dba8917da0a36b17c0bdb69d6d6edfdf14104a
Reviewed-on: https://go-review.googlesource.com/c/go/+/324331
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Dan Scales <danscales@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
2021-06-04 17:48:10 +00:00
Damien Neil
831f9376d8 net/http: fix ResponseWriter.ReadFrom with short reads
CL 249238 changes ResponseWriter.ReadFrom to probe the source with
a single read of sniffLen bytes before writing the response header.
If the source returns less than sniffLen bytes without reaching
EOF, this can cause Content-Type and Content-Length detection to
fail.

Fix ResponseWrite.ReadFrom to copy a full sniffLen bytes from
the source as a probe.

Drop the explicit call to w.WriteHeader; writing the probe will
trigger a WriteHeader call.

Consistently use io.CopyBuffer; ReadFrom has already acquired a
copy buffer, so it may as well use it.

Fixes #44953.

Change-Id: Ic49305fb827a2bd7da4764b68d64b797b5157dc0
Reviewed-on: https://go-review.googlesource.com/c/go/+/301449
Trust: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2021-06-04 17:33:24 +00:00
Jason A. Donenfeld
3a9d906edc os: avoid finalizer race in windows process object
If proc.Release is called concurrently, a handle will be double-freed.

Change-Id: I0c0c32e312e07bc8615e0bf9e9b691214444d8d5
Reviewed-on: https://go-review.googlesource.com/c/go/+/322510
Trust: Jason A. Donenfeld <Jason@zx2c4.com>
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-06-04 17:21:49 +00:00
Jason A. Donenfeld
105c5b50e0 os: terminate windows processes via handle directly
We already have a handle to the process, so use that for termination,
rather than doing a new lookup based on the PID.

Change-Id: I2958c1817f12f3dd783412baacbf629049f6956a
Reviewed-on: https://go-review.googlesource.com/c/go/+/322509
Trust: Jason A. Donenfeld <Jason@zx2c4.com>
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-06-04 17:21:40 +00:00
Cherry Mui
4cf7f5f694 [dev.typeparams] test: test regabidefers in live.go
Previously, live.go is conditioned on not using regabidefers. Now
we have regabidefers enabled by default everywhere, and we may
remove the fallback path in the near future, test that
configuration instead.

Change-Id: Idf910aee323bdd6478bc7a2062b2052d82ce003f
Reviewed-on: https://go-review.googlesource.com/c/go/+/325111
Trust: Cherry Mui <cherryyz@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
2021-06-04 17:00:48 +00:00
Cherry Mui
3298c749ac [dev.typeparams] runtime: undo go'd closure argument workaround
In CL 298669 we added defer/go wrapping, and, as it is not
allowed for closures to escape when compiling runtime, we worked
around it by rewriting go'd closures to argumentless
non-capturing closures, so it is not a real closure and so not
needed to escape.

Previous CL removes the restriction. Now we can undo the
workaround.

Updates #40724.

Change-Id: Ic7bf129da4aee7b7fdb7157414eca943a6a27264
Reviewed-on: https://go-review.googlesource.com/c/go/+/325110
Trust: Cherry Mui <cherryyz@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
2021-06-04 17:00:32 +00:00
Cherry Mui
46beeed0ac [dev.typeparams] cmd/compile: allow go'd closure to escape when compiling runtime
When compiling runtime, we don't allow closures to escape,
because we don't want (implicit) allocations to occur when it is
not okay to allocate (e.g. in the allocator itself). However, for
go statement, it already allocates a new goroutine anyway. It is
okay to allocate the closure. Allow it.

Also include the closure's name when reporting error.

Updates #40724.

Change-Id: Id7574ed17cc27709609a059c4eaa67ba1c4436dc
Reviewed-on: https://go-review.googlesource.com/c/go/+/325109
Trust: Cherry Mui <cherryyz@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
2021-06-04 17:00:19 +00:00
Dan Scales
8e6dfe1b31 [dev.typeparams] cmd/compile: export/import of recursive generic types.
Deal with export/import of recursive generic types. This includes
typeparams which have bounds that reference the typeparam.

There are three main changes:

  - Change export/import of typeparams to have an implicit "declaration"
    (doDecl). We need to do a declaration of typeparams (via the
    typeparam's package and unique name), because it may be referenced
    within its bound during its own definition.

  - We delay most of the processing of the Instantiate call until we
    finish the creation of the top-most type (similar to the way we
    delay CheckSize). This is because we can't do the full instantiation
    properly until the base type is fully defined (with methods). The
    functions delayDoInst() and resumeDoInst() delay and resume the
    processing of the instantiations.

  - To do the full needed type substitutions for type instantiations
    during import, I had to separate out the type subster in stencil.go
    and move it to subr.go in the typecheck package. The subster in
    stencil.go now does node substitution and makes use of the type
    subster to do type substitutions.

Notable other changes:
 - In types/builtins.go, put the newly defined typeparam for a union type
   (related to use of real/imag, etc.) in the current package, rather
   than the builtin package, so exports/imports work properly.

 - In types2, allowed NewTypeParam() to be called with a nil bound, and
   allow setting the bound later. (Needed to import a typeparam whose
   bound refers to the typeparam itself.)

 - During import of typeparams in types2 (importer/import.go), we need
   to keep an index of the typeparams by their package and unique name
   (with id). Use a new map typParamIndex[] for that. Again, this is
   needed to deal with typeparams whose bounds refer to the typeparam
   itself.

 - Added several new tests absdiffimp.go and orderedmapsimp.go. Some of
   the orderemapsimp tests are commented out for now, because there are
   some issues with closures inside instantiations (relating to unexported
   names of closure structs).

 - Renamed some typeparams in test value.go to make them all T (to make
   typeparam uniqueness is working fine).

Change-Id: Ib47ed9471c19ee8e9fbb34e8506907dad3021e5a
Reviewed-on: https://go-review.googlesource.com/c/go/+/323029
Trust: Dan Scales <danscales@google.com>
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-06-04 16:43:27 +00:00
Bryan C. Mills
79cd407f88 syscall: regenerate zsyscall_windows.go
The declaration order in CL 319310 does not match what the generator
produces from scratch. That currently causes
cmd/internal/moddeps.TestAllDependencies to fail, since it is
explicitly checking for that kind of skew.

Updates #45914

Change-Id: If2a9cabc3d54e21deba7cb438fa364df205f38ac
Reviewed-on: https://go-review.googlesource.com/c/go/+/325112
Trust: Bryan C. Mills <bcmills@google.com>
Trust: Jason A. Donenfeld <Jason@zx2c4.com>
Reviewed-by: Jason A. Donenfeld <Jason@zx2c4.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-06-04 15:53:06 +00:00
Aaron Sheah
c6b6211229 doc/go1.17: document testing changes for Go 1.17
For #44513. Fixes #46024

Change-Id: Icf3877d1fcd67448fbc79a0ce3db3f319ad4a0e9
GitHub-Last-Rev: 8c015935c2
GitHub-Pull-Request: golang/go#46324
Reviewed-on: https://go-review.googlesource.com/c/go/+/322109
Reviewed-by: Heschi Kreinick <heschi@google.com>
Trust: Jeremy Faller <jeremy@golang.org>
Trust: Dmitri Shuralyov <dmitshur@golang.org>
2021-06-04 14:31:24 +00:00
Rob Findley
93a886a165 [dev.typeparams] go/types: move struct checking into separate file
This is a port of CL 321589 to go/types. Specifically, the same checker
methods were moved.

Change-Id: If07d96faa77d2f9409d8895f970149c42cbfe440
Reviewed-on: https://go-review.googlesource.com/c/go/+/324753
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-06-04 11:01:22 +00:00
Rob Findley
ffc74ad5d3 [dev.typeparams] go/types: move interface checking into separate file
This is a port of CL 321549 to go/types. Specifically, the same checker
methods were moved.

Change-Id: I491a8c5a985d71ebb23e4b34541a557da0af0cfc
Reviewed-on: https://go-review.googlesource.com/c/go/+/324752
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-06-04 11:01:02 +00:00
Rob Findley
090a17c998 [dev.typeparams] go/types: use correct type parameter list in missingMethod
This is a port of CL 321232 to go/types, adjusted to add a missing
comment and to remove optional support for method type params.

Fixes #46275

Change-Id: I63fcbb669e7607876a888fca89b9064568805448
Reviewed-on: https://go-review.googlesource.com/c/go/+/324751
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-06-04 11:00:45 +00:00
Rob Findley
62c40878e4 [dev.typeparams] go/types: better recv Var for method expressions
This is a port of CL 320489 to go/types, adjusted to be consistent about
named/unnamed parameters. TestEvalPos was failing without this addition.

For #46209

Change-Id: Icdf86e84ebce8ccdb7846a63b5605e360e2b8781
Reviewed-on: https://go-review.googlesource.com/c/go/+/324733
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-06-04 10:59:39 +00:00
Rob Findley
e32fab145b [dev.typeparams] go/types: fix panic with nil package name
This is a straightforward port of CL 320490 to go/types.

Change-Id: I763c806c777f926a563d8f9384764e5b3f7f083c
Reviewed-on: https://go-review.googlesource.com/c/go/+/324732
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-06-04 10:59:23 +00:00
Rob Findley
cd6e9df446 [dev.typeparams] go/types: print "incomplete" for interfaces in debug mode only
This is a straightforward port of CL 320150 to go/types.

Fixes #46167

Change-Id: Id1845046f598ac4fefd68cda6a5a03b7a5fc5a4a
Reviewed-on: https://go-review.googlesource.com/c/go/+/324731
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-06-04 10:59:00 +00:00
Rob Findley
655246f99a [dev.typeparams] go/types: make TestManual work for directories
This is a port of CL 315769 to go/types, adjusted for the additional
testPkg indirection in go/types on top of testFiles, and to remove the
colDelta argument.

Change-Id: Ieb722d77866313a01645aeec49912c16cb475462
Reviewed-on: https://go-review.googlesource.com/c/go/+/324730
Trust: Robert Findley <rfindley@google.com>
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-06-04 10:58:49 +00:00
Rob Findley
d7592ab424 [dev.typeparams] go/types: implement types.Instantiate
This is a straightforward port of CL 314773 to go/types.

Change-Id: If9e2d6d99790d694615389acbe6ccb3c8c0bd1da
Reviewed-on: https://go-review.googlesource.com/c/go/+/324729
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-06-04 10:04:16 +00:00
Rob Findley
410fa4c75b [dev.typeparams] go/types: rename Inferred.Targs to TArgs
This is consistent with Named.TArgs.

Change-Id: Ib25f7ac5b7242e169c8c1701dfa407f763f26125
Reviewed-on: https://go-review.googlesource.com/c/go/+/321289
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-06-04 10:02:50 +00:00
Rob Findley
298149a915 [dev.typeparams] go/types: use Checker-provided type parameter IDs when possible
Incrementing type parameter subscripts for each type checking pass is
distracting for an interactive program where packages are type-checked
on each keystroke.

We should perhaps hide the type parameter ID altogether, but for now at
least add a layer of indirection so that type parameters for a single
type-checked package can be stabilized.

This change should have no effect on non-generic type checking.

For #46003

Change-Id: I60d747e0a2bfb68e7d64e897eac23f609a2a4429
Reviewed-on: https://go-review.googlesource.com/c/go/+/321269
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-06-04 10:02:38 +00:00
Jason A. Donenfeld
0214440075 syscall: do not pass console handles to PROC_THREAD_ATTRIBUTE_HANDLE_LIST on Windows 7
On Windows 7 (and below), console handles are not real kernel handles
but are rather userspace objects, with information passed via special
bits in the handle itself. That means they can't be passed in
PROC_THREAD_ATTRIBUTE_HANDLE_LIST, even though they can be inherited.
So, we filter the list passed to PROC_THREAD_ATTRIBUTE_HANDLE_LIST to
not have any console handles on Windows 7. At the same time, it turns
out that the presence of a NULL handle in the list is enough to render
PROC_THREAD_ATTRIBUTE_HANDLE_LIST completely useless, so filter these
out too. Console handles also can't be duplicated into parent processes,
as inhertance always happens from the present process, so duplicate
always into the present process even when a parent process is specified.

Fixes #45914.

Change-Id: I70b4ff4874dbf0507d9ec9278f63b9b4dd4f1999
Reviewed-on: https://go-review.googlesource.com/c/go/+/319310
Trust: Jason A. Donenfeld <Jason@zx2c4.com>
Trust: Alex Brainman <alex.brainman@gmail.com>
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2021-06-04 09:39:32 +00:00
Matthew Dempsky
2175e2f573 [dev.typeparams] cmd/compile: lazy import resolution for types2
This CL adds three new functions to the types2 API to support lazy
import resolution:

1. A new Scope.InsertLazy method to allow recording that Objects exist
in a particular Scope (in particular, package scopes) without having
to yet fully construct those objects. Instead, types2 will call the
provided `resolve` function if/when the object is actually needed.

2. Similarly, a new NewTypeNameLazy function to create TypeName
objects without yet instantiating their underlying Named
instance.

3. Finally, an InstantiateLazy method, that allows creating type
instances without requiring any of the types to be expanded right
away. Importantly, this requires providing a types2.Checker argument
to handle recursive types correctly.

The APIs as-is are a bit clumsy (esp. NewTypeNameLazy), but seem to
work well for cmd/compile's needs. In particular, they simplify some
of the complexities of handling recursive type definitions within the
importer.

Also, the current prototype is a bit fragile. It uses sync.Once to
manage concurrent lazy resolution, which is frustrating to debug in
the presence of reentrancy issues. It also means the importer needs to
deal with concurrency as well. These aren't issues for types2 though
as cmd/compile only walks the type-checked AST sequentially.

Finally, it looks like some of the details of lazy type names are
similar to the lazy "instance" stuff used for generics, so maybe
there's opportunity for unifying them under a more general (but still
internal) lazy type mechanism.

I had originally intended for this CL to also update the types2
importer, but (1) it doesn't have access to the types2.Checker
instance needed to call InstantiateLazy, and (2) it creates a new
TypeName/TypeParam at each use rather than reusing them, which
evidently works with types2.Instantiate but not
types2.(*Checker).instantiate (i.e., InstantiateLazy). I spent a while
trying to fix these issues, but kept running into more subtle
issues. Instead, I've included my WIP "unified IR" CL as a followup CL
that demonstrates these Lazy methods (see noder/reader2.go).

Updates #46449.

Change-Id: I4d1e8e649f6325a11790d25fd90c39fa07c8d41d
Reviewed-on: https://go-review.googlesource.com/c/go/+/323569
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Trust: Matthew Dempsky <mdempsky@google.com>
Trust: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-06-04 04:28:10 +00:00
Matthew Dempsky
962d5c997a cmd/compile,go/types: restrict use of unsafe.{Add,Slice} to go1.17 or newer
This CL updates cmd/compile (including types2) and go/types to report
errors about using unsafe.Add and unsafe.Slice when language
compatibility is set to Go 1.16 or older.

Fixes #46525.

Change-Id: I1bfe025a672d9f4b929f443064ad1effd38d0363
Reviewed-on: https://go-review.googlesource.com/c/go/+/324369
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>
2021-06-04 01:31:23 +00:00
Matthew Dempsky
b29b123e07 cmd/compile: remove spurious ir.Dump
This ir.Dump call is a debugging artifact introduced in
golang.org/cl/274103, which should never be printed for valid,
non-generic code, but evidently can now sometimes appear due to how
the parser handles invalid syntax.

The parser should probably not recognize "x[2]" as a type expression
in non-generics mode, but also probably we shouldn't try noding after
reporting syntax errors. Either way, this diagnostic has outlived its
usefulness, and noder's days are numbered anyway, so we might as well
just remove it to save end users any confusion.

Updates #46558.

Change-Id: Ib68502ef834d610b883c2f2bb11d9b385bc66e37
Reviewed-on: https://go-review.googlesource.com/c/go/+/324991
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-06-04 01:26:43 +00:00
Cherry Mui
4d2b528795 [dev.typeparams] internal/buildcfg: turn on register ABI by default on ARM64
This CL enables all regabi experiments on ARM64 by default.
regabiwrappers and regabireflect are enabled in the previous CLs.
regabidefer is already enabled everywhere. regabig is no-op on
ARM64 as it already has a G register. regabiargs is enabled in
this CL.

Go1 benchmarks results (GOEXPERIMENT=regabi vs. none, on macOS/ARM64):

name                     old time/op    new time/op     delta
BinaryTree17-8              1.20s ± 1%      1.02s ± 0%  -15.08%  (p=0.000 n=9+9)
Fannkuch11-8                1.55s ± 0%      1.57s ± 0%   +1.53%  (p=0.000 n=9+8)
FmtFprintfEmpty-8          22.5ns ± 3%     14.7ns ± 1%  -34.47%  (p=0.000 n=10+8)
FmtFprintfString-8         38.4ns ± 0%     28.8ns ± 0%  -24.99%  (p=0.000 n=9+9)
FmtFprintfInt-8            38.7ns ± 2%     34.5ns ± 0%  -10.79%  (p=0.000 n=10+7)
FmtFprintfIntInt-8         61.1ns ± 1%     57.9ns ± 0%   -5.23%  (p=0.000 n=10+8)
FmtFprintfPrefixedInt-8    69.9ns ± 0%     64.4ns ± 0%   -7.78%  (p=0.000 n=8+8)
FmtFprintfFloat-8           106ns ± 0%       76ns ± 0%  -28.12%  (p=0.000 n=7+10)
FmtManyArgs-8               273ns ± 0%      236ns ± 1%  -13.57%  (p=0.000 n=9+10)
GobDecode-8                3.09ms ± 1%     2.02ms ± 0%  -34.70%  (p=0.000 n=9+10)
GobEncode-8                2.45ms ± 1%     1.44ms ± 1%  -41.26%  (p=0.000 n=10+10)
Gzip-8                      128ms ± 0%      124ms ± 0%   -2.89%  (p=0.000 n=7+8)
Gunzip-8                   23.6ms ± 1%     19.8ms ± 0%  -16.15%  (p=0.000 n=10+9)
HTTPClientServer-8         27.4µs ± 1%     26.3µs ± 0%   -4.05%  (p=0.000 n=10+10)
JSONEncode-8               4.47ms ± 1%     3.45ms ± 1%  -22.73%  (p=0.000 n=10+9)
JSONDecode-8               21.5ms ± 0%     17.2ms ± 0%  -19.78%  (p=0.000 n=9+9)
Mandelbrot200-8            2.33ms ± 1%     2.33ms ± 1%     ~     (p=0.842 n=9+10)
GoParse-8                  1.62ms ± 1%     1.32ms ± 1%  -18.67%  (p=0.000 n=10+10)
RegexpMatchEasy0_32-8      33.1ns ± 0%     26.3ns ± 0%  -20.50%  (p=0.000 n=8+10)
RegexpMatchEasy0_1K-8       121ns ± 6%      121ns ± 8%     ~     (p=0.926 n=10+10)
RegexpMatchEasy1_32-8      31.4ns ± 0%     24.7ns ± 0%  -21.50%  (p=0.000 n=9+10)
RegexpMatchEasy1_1K-8       177ns ± 0%      140ns ± 0%  -20.70%  (p=0.000 n=10+9)
RegexpMatchMedium_32-8     3.02ns ± 3%     2.12ns ± 0%  -29.73%  (p=0.000 n=10+10)
RegexpMatchMedium_1K-8     19.8µs ± 2%     17.1µs ± 0%  -13.50%  (p=0.000 n=9+9)
RegexpMatchHard_32-8        940ns ± 0%      872ns ± 0%   -7.20%  (p=0.000 n=9+8)
RegexpMatchHard_1K-8       28.5µs ± 1%     26.5µs ± 0%   -7.06%  (p=0.000 n=10+10)
Revcomp-8                   186ms ± 1%      179ms ± 1%   -3.66%  (p=0.000 n=10+10)
Template-8                 30.3ms ± 0%     22.3ms ± 0%  -26.58%  (p=0.000 n=8+9)
TimeParse-8                 133ns ± 0%      117ns ± 0%  -12.40%  (p=0.000 n=10+10)
TimeFormat-8                176ns ± 0%      141ns ± 0%  -19.92%  (p=0.000 n=8+9)
[Geo mean]                 21.4µs          17.8µs       -16.81%

name                     old speed      new speed       delta
GobDecode-8               249MB/s ± 1%    381MB/s ± 0%  +53.13%  (p=0.000 n=9+10)
GobEncode-8               314MB/s ± 1%    534MB/s ± 1%  +70.25%  (p=0.000 n=10+10)
Gzip-8                    152MB/s ± 0%    156MB/s ± 0%   +2.97%  (p=0.000 n=7+8)
Gunzip-8                  822MB/s ± 1%    981MB/s ± 0%  +19.26%  (p=0.000 n=10+9)
JSONEncode-8              434MB/s ± 1%    562MB/s ± 1%  +29.41%  (p=0.000 n=10+9)
JSONDecode-8             90.3MB/s ± 0%  112.5MB/s ± 0%  +24.66%  (p=0.000 n=9+9)
GoParse-8                35.7MB/s ± 1%   43.9MB/s ± 1%  +22.96%  (p=0.000 n=10+10)
RegexpMatchEasy0_32-8     967MB/s ± 0%   1216MB/s ± 0%  +25.78%  (p=0.000 n=8+10)
RegexpMatchEasy0_1K-8    8.46GB/s ± 6%   8.45GB/s ± 7%     ~     (p=0.912 n=10+10)
RegexpMatchEasy1_32-8    1.02GB/s ± 0%   1.30GB/s ± 0%  +27.40%  (p=0.000 n=9+10)
RegexpMatchEasy1_1K-8    5.78GB/s ± 0%   7.29GB/s ± 0%  +26.10%  (p=0.000 n=10+9)
RegexpMatchMedium_32-8    331MB/s ± 2%    471MB/s ± 0%  +42.29%  (p=0.000 n=10+10)
RegexpMatchMedium_1K-8   51.7MB/s ± 2%   59.8MB/s ± 0%  +15.60%  (p=0.000 n=9+9)
RegexpMatchHard_32-8     34.0MB/s ± 0%   36.7MB/s ± 0%   +7.75%  (p=0.000 n=9+8)
RegexpMatchHard_1K-8     35.9MB/s ± 1%   38.6MB/s ± 0%   +7.59%  (p=0.000 n=10+10)
Revcomp-8                1.37GB/s ± 1%   1.42GB/s ± 1%   +3.79%  (p=0.000 n=10+10)
Template-8               64.0MB/s ± 0%   87.1MB/s ± 0%  +36.20%  (p=0.000 n=8+9)
[Geo mean]                299MB/s         368MB/s       +23.16%

Binary sizes:
                old            new
hello           1180994        1162626      -1.6%
cmd/compile     23455858       22833970     -2.7%
cmd/link        6425010        6332978      -1.4%

Text sizes:
                old            new
hello           458752         425984       -7.1%
cmd/compile     10190848       9355264      -8.2%
cmd/link        2621440        2441216      -6.9%

Change-Id: I52c10c11bb8fe5952b7043f9dbf09573ef71d2b0
Reviewed-on: https://go-review.googlesource.com/c/go/+/324890
Trust: Cherry Mui <cherryyz@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Jeremy Faller <jeremy@golang.org>
2021-06-03 21:55:26 +00:00
Cherry Mui
5f034f9b46 [dev.typeparams] internal/buildcfg: turn on regabireflect by default on ARM64
Change-Id: I4a0a093b07a287cc3a3e0ee939e7ee82d8e9b1aa
Reviewed-on: https://go-review.googlesource.com/c/go/+/324889
Trust: Cherry Mui <cherryyz@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-06-03 20:58:43 +00:00
Matthew Dempsky
026480d06b [dev.typeparams] cmd/compile: allow nil Syms in Sym.Less
Allows sorting interfaces that contain embedded anonymous types.

Fixes #46556.

Change-Id: If19afa1d62432323b2e98957087867afbf3f9097
Reviewed-on: https://go-review.googlesource.com/c/go/+/324812
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: Dan Scales <danscales@google.com>
2021-06-03 20:52:22 +00:00
Cherry Mui
a2d6a2caeb [dev.typeparams] internal/buildcfg: turn on regabiwrappers by default on ARM64
Change-Id: I8db0a797a745630ec35af3e56406fcb250ea59fe
Reviewed-on: https://go-review.googlesource.com/c/go/+/324768
Trust: Cherry Mui <cherryyz@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
2021-06-03 20:17:38 +00:00
Cherry Mui
55b4310acd [dev.typeparams] runtime: crash the GC at clobberdead pointer on ARM64
Extend CL 310330 to ARM64, which now has clobberdead mode
implemented in the compiler.

Change-Id: I07f6951d81a0797ef7a74e48b79db5cea2bf876b
Reviewed-on: https://go-review.googlesource.com/c/go/+/324766
Trust: Cherry Mui <cherryyz@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-06-03 20:00:56 +00:00
Cherry Mui
6b1e4430bb [dev.typeparams] cmd/compile: implement clobberdead mode on ARM64
For debugging.

Change-Id: I5875ccd2413b8ffd2ec97a0ace66b5cae7893b24
Reviewed-on: https://go-review.googlesource.com/c/go/+/324765
Trust: Cherry Mui <cherryyz@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-06-03 20:00:30 +00:00
Dan Scales
1c947e4f31 [dev.typeparams] cmd/compile: properly copy tilde value for unions in types2-to-types1 conversion
Change-Id: I2211020141886b348cddf9e33ab31b71c8478987
Reviewed-on: https://go-review.googlesource.com/c/go/+/324811
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-06-03 19:59:18 +00:00
Cherry Mui
e9ba0750b6 [dev.typeparams] reflect: guard abi_test.go with regabiargs build tag
The test in abi_test.go relies on the compiler to generate
register-ABI calls using a magic name. As of CL 300150 the name
loses its magic. Guard it with regabiargs for the use of
register-ABI calls.

Change-Id: Ib8b3c24f71ea5161d607c9becfb3027ceee40ac1
Reviewed-on: https://go-review.googlesource.com/c/go/+/324767
Trust: Cherry Mui <cherryyz@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-06-03 19:48:38 +00:00
Than McIntosh
6d98301114 cmd/link: use correct alignment in PE DWARF sections
Set the correct section flags to insure that .debug_* sections are
using 1-byte alignment instead of the default. This seems to be
important for later versions of LLVM-mingw on windows (shows up on the
windows/arm64 builder).

Updates #46406.

Change-Id: I023d5208374f867552ba68b45011f7990159868f
Reviewed-on: https://go-review.googlesource.com/c/go/+/324763
Trust: Than McIntosh <thanm@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-06-03 19:38:56 +00:00
Michael Pratt
e0d029f758 runtime: avoid gp.lockedm race in exitsyscall0
Following https://golang.org/cl/291329, exitsyscall0 accesses gp.lockedm
after releasing gp to the global runq. This creates a race window where
another M may schedule the (unlocked) G, which subsequently calls
LockOSThread, setting gp.lockedm and thus causing exitsyscall0 to think
it should call stoplockedm.

Avoid this race by checking if gp is locked before releasing it to the
global runq.

Fixes #46524

Change-Id: I3acdaf09e7a2178725adbe61e985130e9ebd0680
Reviewed-on: https://go-review.googlesource.com/c/go/+/324350
Trust: Michael Pratt <mpratt@google.com>
Run-TryBot: Michael Pratt <mpratt@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
2021-06-03 16:34:34 +00:00
Cherry Mui
28bd325e41 [dev.typeparams] runtime: use ABIInternal callbackWrap in callbackasm1 on ARM64
On Windows/ARM64, callbackasm1 calls callbackWrap via cgocallback.
cgocallback uses ABIInternal calling convention to call the
function. Pass the ABIInternal entry point to cgocallback.

Change-Id: I79d21b77525f6ac8dd50d34f4f304749419b2ad4
Reviewed-on: https://go-review.googlesource.com/c/go/+/324735
Trust: Cherry Mui <cherryyz@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
2021-06-03 16:28:44 +00:00
Cherry Mui
3de4986852 [dev.typeparams] runtime: call cgocallbackg indirectly on ARM64
This is CL 312669, for ARM64.

cgocallback calls cgocallbackg after switching the stack. Call it
indirectly to bypass the linker's nosplit check. In particular,
this avoids a nosplit stack overflow on Windows when register ABI
is enabled.

Change-Id: I7054a750fb0ec2579d46004f94b46b6f7b9e3a21
Reviewed-on: https://go-review.googlesource.com/c/go/+/324734
Trust: Cherry Mui <cherryyz@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
2021-06-03 16:28:28 +00:00
Cherry Mui
5a40fab19f [dev.typeparams] runtime, internal/bytealg: port performance-critical functions to register ABI on ARM64
This CL ports a few performance-critical assembly functions to use
register arguments directly. This is similar to CL 308931 and
CL 310184.

Change-Id: I6e30dfff17f76b8578ce8cfd51de21b66610fdb0
Reviewed-on: https://go-review.googlesource.com/c/go/+/324400
Trust: Cherry Mui <cherryyz@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-06-03 16:28:19 +00:00
Dan Scales
370ff5ff96 [dev.typeparams] test: update all the typeparam tests to use the new union/tilde syntax
Did a mix of tilde and non-tilde usage. Tilde notation is not quite
fully functional, so no tests are currently trying to distinguish
(fail/not fail) based on tilde usage.

Change-Id: Ib50cec2fc0684f9d9f3561c889fd44c7a7af458c
Reviewed-on: https://go-review.googlesource.com/c/go/+/324572
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-06-03 16:05:22 +00:00
Cherry Mui
5a008a92e8 [dev.typeparams] internal/bytealg: call memeqbody directly in memequal_varlen on ARM64
Currently, memequal_varlen opens up a frame and call memequal,
which then tail-calls memeqbody. This CL changes memequal_varlen
tail-calls memeqbody directly.

This makes it simpler to switch to the register ABI in the next
CL.

Change-Id: Ia1367c0abb7f4755fe736c404411793fb9e5c04f
Reviewed-on: https://go-review.googlesource.com/c/go/+/324399
Trust: Cherry Mui <cherryyz@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
2021-06-03 14:29:14 +00:00