Commit graph

48948 commits

Author SHA1 Message Date
Dan Scales 8ab59d812a [dev.typeparams] cmd/compile: change export version to 1.17 for testing
This is a temporary change. We will revert this back before the 1.18
release. We make this change now to simplify testing, since a lot of
tools will break on the new export version.

Updates #47654.

Change-Id: I0650fa753bb11229c71254d779dd61b5c1af9cdf
Reviewed-on: https://go-review.googlesource.com/c/go/+/341211
Trust: Dan Scales <danscales@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-08-11 19:48:50 +00:00
Cherry Mui d7d4f28a06 [dev.typeparams] runtime, internal/bytealg: remove regabi fallback code on AMD64
As we commit to always enabling register ABI on AMD64, remove the
fallback code.

Change-Id: I30556858ba4bac367495fa94f6a8682ecd771196
Reviewed-on: https://go-review.googlesource.com/c/go/+/341152
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: Austin Clements <austin@google.com>
2021-08-11 17:08:54 +00:00
Cherry Mui eeb7899137 [dev.typeparams] internal/buildcfg: always enable regabi on AMD64
In Go 1.17 we added register ABI on AMD64 on Linux/macOS/Windows
as a GOEXPERIMENT, on by default. In Go 1.18, we commit to always
enabling register ABI on AMD64.

Now "go build" for AMD64 always have goexperiment.regabi* tags
set. However, at bootstrapping cmd/dist does not set the tags
when building go_bootstrap. For this to work, unfortunately, we
need to hard-code AMD64 to use register ABI in runtime code.

Change-Id: I0b31e678e186b9cdeeb8502cd9e38ed0d7e72d4f
Reviewed-on: https://go-review.googlesource.com/c/go/+/341151
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: Austin Clements <austin@google.com>
2021-08-11 16:59:43 +00:00
Robert Griesemer 0888a8cd2d [dev.typeparams] cmd/compile/internal/types2: remove unused TypeParam.Bound method
Use TypeParam.Constraint instead.

Change-Id: Iebd77d304f2b7238baa231fb9869c964f66ea355
Reviewed-on: https://go-review.googlesource.com/c/go/+/340990
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-08-11 06:15:15 +00:00
Rob Findley 7308d747e7 [dev.typeparams] cmd/compile/internal/types2: remove Named.SetTArgs
Calling SetTArgs without substituting can leave the type in incoherent
state, so we should avoid exposing this API unless necessary. Since it
is currently not used by the importer(s), it is probably not necessary
to expose for 1.18, so remove it.

Change-Id: I06bd7b5bbfacd3c65e2e66a9d5980f20cd1c10c1
Reviewed-on: https://go-review.googlesource.com/c/go/+/341290
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-10 21:52:02 +00:00
Rob Findley 0f34a92df7 [dev.typeparams] go/types: don't expose the TypeSet API for 1.18
The TypeSet API is very new and probably not necessary to expose outside
of go/types, at least for 1.18. Users can check whether a type is
contained within a type set via Implements, and can access the
representation of the type set via the embedded Unions.

Change-Id: Icc7355285785bee5aa7a8fe74052bcb0fedcd0a1
Reviewed-on: https://go-review.googlesource.com/c/go/+/341289
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-10 21:49:07 +00:00
Dan Scales 40ba119e3f [dev.typeparams] cmd/compile: keep export format unchanged if no type params are exported
Added new export tags 'G' and 'U' to export parameterized
functions/methods and parameterized types respectively. This has the
advantage that the Go 1.18 format remains backward-compatible with the
Go 1.17 format if no type parameters are exported.

Change-Id: I9dba8faaa65609eb3f9c693bd0c79daee98bd865
Reviewed-on: https://go-review.googlesource.com/c/go/+/340989
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Dan Scales <danscales@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-08-10 19:48:58 +00:00
Cherry Mui fb8579746c [dev.typeparams] internal/goexperiment: update comment for RegabiArgs requirements
RegabiG and regabiDefer have been always enabled and removed from
experiments. Update the comment.

Change-Id: Ieaf4b4f0a7e0e9d6733a18932ca457be4f150d08
Reviewed-on: https://go-review.googlesource.com/c/go/+/341150
Trust: Cherry Mui <cherryyz@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
2021-08-10 16:07:59 +00:00
Cherry Mui 2e250cc957 [dev.typeparams] cmd: update vendored golang.org/x/tools to 337cebd2c1
Update vendored golang.org/x/tools repo to pick up CL 339250 for
assembly function check for register ABI.

This is done with

	cd GOROOT/cmd
	go get golang.org/x/tools@master
	go mod tidy
	go mod vendor

Update cmd/vet tests as the error ouput changes in CL 301949.
The error message now includes full package-qualified name.

Change-Id: I52dc7223aee9e011214254488bacf02dc5b4c2ef
Reviewed-on: https://go-review.googlesource.com/c/go/+/341149
Trust: Cherry Mui <cherryyz@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
2021-08-10 16:07:37 +00:00
Keith Randall 2fbf6aafe7 [dev.typeparams] cmd/compile: handle interface type parameters in type switches
Change-Id: I9bba21a64d7e9f42395b6fcdf8aa3ca01cf131dc
Reviewed-on: https://go-review.googlesource.com/c/go/+/340912
Trust: Keith Randall <khr@golang.org>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
2021-08-10 01:56:50 +00:00
Robert Griesemer e4cfa2f6da [dev.typeparams] cmd/compile/internal/types2: parameterized functions must have a body
Add the respective check and add missing bodies to tests.
Use {} as body for functions that don't return a result.
Use { panic(0) } as body for functions that return a result.

For #47069.

Change-Id: Ia5d7525c9c036baf8a955d13bff448401e08235e
Reviewed-on: https://go-review.googlesource.com/c/go/+/340911
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-08-10 01:20:34 +00:00
Robert Griesemer 508624f359 [dev.typeparams] cmd/compile/internal/types2: expand is only required for *Named types
Now that the pointer identity for a *Named type doesn't change
anymore when going from lazy instantiated to actually instantiated
(= expanded) state, expand() only needs to be called when we deal
with *Named types and only if we care about a *Named type's internals.

Remove the expand function and respective calls for all types and
replace with specific t.expand() method calls where t is a *Named.

Change-Id: If82299360d60108b00adc4013b29399aec90b940
Reviewed-on: https://go-review.googlesource.com/c/go/+/340749
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-08-10 01:20:32 +00:00
Dan Scales f5f79c47f9 [dev.typeparams] cmd/compile: use types2.Constraint() rather than types2.Bound()
types2.Constraint() returns the top-level constraint type, including any
unions or other interface elements. Because of that, we needed to
add/fix some code in the type substituter and generic type instantiater
in the importer to deal with unions and non-method members of an
interface. Also, NewUnion was not correctly setting the HasTParam flag.

I also added a better error message when a symbol is not found in
(*deadcodePass).decodeIfaceMethod().

Change-Id: Id3668dc596dce63690fa05a9e5e42295b5e2bbb5
Reviewed-on: https://go-review.googlesource.com/c/go/+/340670
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Dan Scales <danscales@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
2021-08-09 20:08:06 +00:00
Dan Scales 9f4d6a8359 [dev.typeparams] cmd/compile: call transformArgs before early typecheckaste in noder
In the cases where we do an early call to typecheckaste() in noder to
expose CONVIFACE nodes, we need a preceding call to transformArgs().
This is needed to allow typecheckaste() to run correctly, in the case of
f(g()), where g has multiple return values.

I also cleaned up the code a bit and commented the code in Call(), and
we do the call to typecheckaste() in several more cases.

In stencil.go:stencil(), I moved the transformCall earlier for the
OCALLMETH/ODOTMETH case, just as I did in my previous CL for
OCALL/OFUNCINST. By doing this, transformArgs no longer needs to deal
with the extra dictionary args. Therefore, I was able to simply
transformArgs() to look like typecheckargs() again, and make use of
RewriteMultiValue directly.

Updates #47514

Change-Id: I49eb82ac05707e50c2e2fb03e39458a70491d406
Reviewed-on: https://go-review.googlesource.com/c/go/+/340531
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-09 19:43:09 +00:00
Keith Randall ca3c6985cd [dev.typeparams] cmd/compile: implement generic type switches
Add a new dynamicType node, which is used as a case entry when
the type being switched to is generic.

Change-Id: Ice77c6f224b8fdd3ff574fdf4a8ea5f6c7ddbe75
Reviewed-on: https://go-review.googlesource.com/c/go/+/339429
Trust: Keith Randall <khr@golang.org>
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Keith Randall <khr@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
2021-08-09 18:41:45 +00:00
Keith Randall 57668b84ff [dev.typeparams] cmd/compile: simplify interface conversions
Simplify the implementation of interface conversions in the compiler.
Don't pass fields that aren't needed (the data word, usually) to the runtime.

For generics, we need to put a dynamic type in an interface. The new
dataWord function is exactly what we need (the type word will come
from a dictionary).

Change-Id: Iade5de5c174854b65ad248f35c7893c603f7be3d
Reviewed-on: https://go-review.googlesource.com/c/go/+/340029
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-09 16:10:20 +00:00
Dan Scales d10a904712 [dev.typeparams] cmd/compile: don't export/import type parameter indices anymore
types2 now determines type parameter indices lazily, so we don't need
them just as we are importing. We set them in types1 as we are importing
the type param list itself.

type param indices are not strongly needed in types1 - we only use them
in one place which could be rewritten. But I kept them in analogy to
types2 (TypeParam.Index).

Fixes #47451

Change-Id: I30631f95c45a259354eaf7ec5194f71e799eb358
Reviewed-on: https://go-review.googlesource.com/c/go/+/340532
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-07 06:00:09 +00:00
Robert Griesemer 9e0ac72d68 [dev.typeparams] cmd/compile/internal/types2: remove Interface.Complete (cleanup)
Interface.Complete is not needed anymore. We can remove it in
types2 (and eventually make it an empty function in go/types,
where we must maintain the existing API).

Change-Id: I689f0d6f3a83997d8ca5bae773b9af0083d0bf4f
Reviewed-on: https://go-review.googlesource.com/c/go/+/340255
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-08-06 20:34:54 +00:00
Robert Griesemer 9bd1817e41 [dev.typeparams] cmd/compile/internal/types2: limit termlist lengths
At the moment, operations on termlists are O(n^2).
This is fine for normal-sized unions, but overlong
termlist lenghts will lead to excessive type checking
times.

Limit the length of termlists to avoid "compilations
that don't finish".

Change-Id: I39a7fc61b01c9db06faeb49a0e014b1ede532710
Reviewed-on: https://go-review.googlesource.com/c/go/+/340254
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-08-06 20:34:53 +00:00
Robert Griesemer 313924f272 [dev.typeparams] cmd/compile: swap export order of union term components (cleanup)
Export a term as a pair (tilde, type) rather than (type, tilde)
to match the new Union/Term API.

Change-Id: I221c09c2c746ae19fbae0c970ffb26fa7a8ac736
Reviewed-on: https://go-review.googlesource.com/c/go/+/340251
Trust: Robert Griesemer <gri@golang.org>
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-08-06 20:34:52 +00:00
Robert Griesemer 0d7dc417ea [dev.typeparams] cmd/compile: change types2.Union API to accept a list of Terms
Instead of providing a list of tildes and types, use a list of
Terms to create a Union, with suitable accessors.

Define the (exported) notion of a Term representing a union term.

This simplified various uses and also will be easier to extend
should we want to add more information to a Term in the future.

Change-Id: I52fd73938bfa11bac60adbf10580b6d0680df4f1
Reviewed-on: https://go-review.googlesource.com/c/go/+/340250
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-08-06 20:34:51 +00:00
Robert Griesemer 09d82689ed [dev.typeparams] cmd/compile/internal/types2: add defined type to term/termlist tests
Follow-up on https://golang.org/cl/339596 .

Change-Id: Ifa249379df083f80176b9f99900be0bf12483f41
Reviewed-on: https://go-review.googlesource.com/c/go/+/339905
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-08-06 20:34:50 +00:00
Robert Griesemer 3a9fd99849 [dev.typeparams] cmd/compile/internal/syntax: cleanup panic calls
End-users are not expected to deal with the details of panics,
so providing extra information such as an "internal error" prefix
is not helpful.

Matches the types2 changes made in https://golang.org/cl/339969 .

Change-Id: Icb34a9daab981a84f41f8ae7ae5dc1b85b2d2c81
Reviewed-on: https://go-review.googlesource.com/c/go/+/339904
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-08-06 20:34:48 +00:00
Robert Griesemer c3b57af8bc [dev.typeparams] cmd/compile/internal/types2: minor cleanup of writeTParamList
Change-Id: Iaa58b17ad65e93548bb3da8231e0cb6da0c48105
Reviewed-on: https://go-review.googlesource.com/c/go/+/339903
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-08-06 20:34:47 +00:00
Robert Griesemer 0811108670 [dev.typeparams] cmd/compile/internal/types2: fix make with type parameter argument
For make with a type parameter argument, the structural type of
the type parameter's constraint determines what make is making.

Change-Id: I3b48f8ce3236b7624e0638b5f5be208c5915c987
Reviewed-on: https://go-review.googlesource.com/c/go/+/339899
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-08-06 20:34:46 +00:00
Robert Griesemer 93285c89d1 [dev.typeparams] cmd/compile/internal/types2: fix range over exprs of type parameter type
For range expressions of type parameter type, the structural type
of the type parameter's constraint determines the range operation.

While at it, rename implicitArrayDeref to arrayPtrDeref.

Change-Id: Ib631a8a14e717498e5264944f659309df1f68cc2
Reviewed-on: https://go-review.googlesource.com/c/go/+/339897
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-08-06 20:34:45 +00:00
Robert Griesemer 5aac85ad5e [dev.typeparams] cmd/compile/internal/types2: better names for things (cleanup)
- use the symbol 𝓤 (as in 𝓤niverse) instead of ⊤ to denote the set
  of all types (for better readabilty, ⊤ is hard to distinguish from
  T in some fonts)

- use isAll instead of isTop to test for the set of all types

- use allTermlist instead of topTermlist to denote the termlist
  representing all types

Change-Id: Idcb0b3398782b38653338e65173c0dbb935e430a
Reviewed-on: https://go-review.googlesource.com/c/go/+/339891
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-08-06 20:34:43 +00:00
Dan Scales 110343e4a2 [dev.typeparams] cmd/compile: cleanup wrapper code for generics
Simple change - added some comments, but also removed some TODO comments
which are now done or no longer a question. Cleaned up the initial check
for generic methods.

The one remaining TODO that really needs to be done is generating
dictionary wrappers for any methods involving embedded fields. Given we
are not doing this, I think this would only affect if a struct with an
embedded field with methods was converted to an interface containing the
embedded method, and then the method was called via that interface.

Change-Id: I6a8a2885de33ad60b313c1899b659daef7550dfb
Reviewed-on: https://go-review.googlesource.com/c/go/+/340260
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Dan Scales <danscales@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
2021-08-06 19:33:52 +00:00
Dan Scales 5e33d11e10 [dev.typeparams] cmd/compile: do transformCall with non-shape type of call
Do the transformCall using the original types2-derived type of the call
(in particular, the types of the params as non-shapes). Currently, since
we were using the param types of the instantiation, we might add in
interface conversions to an interface with shapes in the one case of a
full-instantiated generic call. So, we do the transformCall() before
installing the shaped-based instantiation. transformCall() works
correctly even in the case of OCALL/FUNCINST.

Fixed two related bugs:
  - Fixed case where we still were not correctly substituting the types
    for a function instantiation.
  - The type substituter needs to copy field flags while substituting in
    tstruct.

Change-Id: I14e960737d6840a75846ede480e6650534ba3af3
Reviewed-on: https://go-review.googlesource.com/c/go/+/340259
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Dan Scales <danscales@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
2021-08-06 19:13:56 +00:00
Dan Scales ac78501b9c [dev.typeparams] cmd/compile: make sure closures inside generic funcs are not compiled
Closures inside generic functions were being added to the g.target.Decls
list during noding, just like other closures. We remove generic
functions/methods from g.target.Decls, so they don't get compiled
(they're only available for export and stenciling). Most closures inside
generic functions/methods were similarly being removed from
g.target.Decls, because they have a generic parameter. But we need to
ensure no closures in generic function/methods are left remaining in
g.target.Decls, since we don't want them transformed and compiled.

So, we set a flag in (*irgen) that records when we are noding a
top-level generic function/method, and don't add any closures to
g.target.Decls when the flag is true.

Updates #47514

Change-Id: Id66b4c41d307ffa8f54cab6ce3646ade81606862
Reviewed-on: https://go-review.googlesource.com/c/go/+/340258
Trust: Dan Scales <danscales@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
2021-08-06 18:50:46 +00:00
Robert Griesemer f78d538858 [dev.typeparams] cmd/compile/internal/types2: cleanup panic calls
End-users are not expected to deal with the details of panics,
so providing extra information such as an "internal error" prefix
or the name of the function invoking the panic are not helpful.

Remove unnecessary panic verbiage if it is readily available from
a stack trace (such as the function where it happens, and the fact
that is is an "internal error").

Change-Id: I5f86bae6d2cca7c04ce692d17257da7ddee206d7
Reviewed-on: https://go-review.googlesource.com/c/go/+/339969
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-08-05 19:37:01 +00:00
Robert Griesemer c5b6c36ddd [dev.typeparams] cmd/compile/internal/types2: remove TestIncompleteInterfaces (cleanup)
TestIncompleteInterfaces is not useful anymore because interface
printing always shows the syntactic type structure of an interface.

Also remove the respective support code in interface printing and
simplify that code.

Move the newDefined and nopos support declarations unchanged into
api_test.go where they are used.

Updates #46167.

Change-Id: I23e303bc4ae4271912ba75f201bd2b7cd4a17b3e
Reviewed-on: https://go-review.googlesource.com/c/go/+/339832
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-08-05 19:36:56 +00:00
Robert Griesemer f14908d01b [dev.typeparams] cmd/compile/internal/types2: remove unused gcCompatibilityMode flag (cleanup)
This flag is not needed by types2 (and possibly can also be removed
from go/types). Removed some unnecessary comments along the way.

Updates #46174.

Change-Id: I1a7a99f724205a084d1c9850bce6f6f5d33f83ca
Reviewed-on: https://go-review.googlesource.com/c/go/+/339831
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-08-05 19:36:52 +00:00
Robert Griesemer bb5608dd5d [dev.typeparams] cmd/compile/internal/types2: implement type sets with term lists
This CL resolves several known issues and TODOs.

- Represent type sets with term lists and using term list abstractions.

- Represent Unions internally as a list of (syntactical) terms.
  Use term operations to print terms and detect overlapping union
  entries.

- Compute type sets corresponding to unions lazily, on demand.

- Adjust code throughout.

- Adjusted error check in test/typeparam/mincheck.dir/main.go
  to make test pass.

Change-Id: Ib36fb7e1d343c2b6aec51d304f0f7d1ad415f999
Reviewed-on: https://go-review.googlesource.com/c/go/+/338310
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-08-05 19:36:47 +00:00
Leonard Wang 6dadee759c [dev.typeparams] cmd/compile: unified importReader receiver name to r
Change-Id: Iaf8ec7665282f4f8c0cb09a652e78aa97959274b
Reviewed-on: https://go-review.googlesource.com/c/go/+/340150
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Robert Griesemer <gri@golang.org>
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
2021-08-05 18:01:57 +00:00
Dan Scales 5dcb5e2cea [dev.typeparams] cmd/compile: dictionary/shape cleanup
- Removed gcshapeType - we're going with more granular shapes for now, and gradually
   coarsening later if needed.

 - Put in early return in getDictionarySym(), so the entire rest of the
   function can be un-indented by one level.

 - Removed some duplicated infoprint calls, and fixed one infoprint
   message in getGfInfo.

Change-Id: I13acce8fdabdb21e903275b53ff78a1e6a378de2
Reviewed-on: https://go-review.googlesource.com/c/go/+/339901
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-05 17:53:59 +00:00
Dan Scales 3cdf8b429e [dev.typeparams] cmd/compile: fixing case where type arg is an interface
In this case, we can't use an itab for doing a bound call, since we're
converting from an interface to an interface. We do a static or dynamic
type assert in new function assertToBound().

The dynamic type assert in assertToBound() is only needed if a bound is
parameterized. In that case, we must do a dynamic type assert, and
therefore need a dictionary entry for the type bound (see change in
getGfInfo). I'm not sure if we can somehow limit this case, since using
an interface as a type arg AND having the type bound of the type
arg be parameterized is a very unlikely case.

Had to add the TUNION case to parameterizedBy1() (which is only used for
extra checking).

Added a bunch of these test cases to 13.go, which now passes.

Change-Id: Ic22eed637fa879b5bbb46d36b40aaad6f90b9d01
Reviewed-on: https://go-review.googlesource.com/c/go/+/339898
Trust: Dan Scales <danscales@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
2021-08-05 17:33:41 +00:00
Rob Findley 1b708c0260 [dev.typeparams] go/types: remove a stale comment (cleanup)
Remove a stale comment from when the new types.Info API was guarded
behind the typeparams build constraint.

Change-Id: I319ad0a9e4e4958efdb96c967bf13a0119b5647b
Reviewed-on: https://go-review.googlesource.com/c/go/+/340010
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-04 23:24:01 +00:00
Rob Findley 0ec2a8b42d [dev.typeparams] go/types: switch the TArgs API to NumTArgs/TArg
As with other go/types APIs, we should not expose the underlying
Named.targs slice.

Change-Id: Iba869298fbd3856022ffe8ec2c3273341598c324
Reviewed-on: https://go-review.googlesource.com/c/go/+/340009
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-04 23:23:45 +00:00
Robert Griesemer e5fe769be1 [dev.typeparams] cmd/compile/internal/types2: implement term lists
Prerequisite for clean implementation of type sets
on top of term lists.

Change-Id: Ice87f2f47327aa6b1f3eaad7f9af20ad7c548155
Reviewed-on: https://go-review.googlesource.com/c/go/+/339596
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-08-04 21:01:48 +00:00
Keith Randall b730a26729 [dev.typeparams] cmd/compile: put shape types in their own package
Put shape types in the top level package called ".shape".
Name them using the serialization of the shape name, instead of
the .shapeN names.

This allows the linker to deduplicate instantiations across packages.

Not sure that this is entirely correct, as shapes in this package
may reference other packages (e.g. a field of a struct). But it seems
to work for now.

For the added test, when you look at the resulting binary (use the -k
option with run.go) it has only one instantiation of F, and 4 call sites:

$ objdump -d a.exe | grep _a\.F
 1053cb0:	e8 8b 00 00 00 	callq	139 <_a.F[.shape.*uint8]>
 1053ce9:	e8 52 00 00 00 	callq	82 <_a.F[.shape.*uint8]>
_a.F[.shape.*uint8]:
 1053d90:	e8 ab ff ff ff 	callq	-85 <_a.F[.shape.*uint8]>
 1053dc9:	e8 72 ff ff ff 	callq	-142 <_a.F[.shape.*uint8]>

Change-Id: I627f7e50210aabe4a10d0e2717d87b75ac82e99b
Reviewed-on: https://go-review.googlesource.com/c/go/+/339595
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-04 17:56:00 +00:00
Austin Clements e590cb64f9 [dev.typeparams] runtime: handle d.link carefully when freeing a defer
CL 339396 allowed stack copying on entry to and during freedefer, but
this introduced a subtle bug: if d is heap-allocated, and d.link
points to a stack-allocated defer, stack copying during freedefer can
briefly introduce a stale pointer, which the garbage collector can
discover and panic about. This happens because d has already been
unlinked from the defer chain when freedefer is called, so stack
copying won't update stack pointers in it.

Fix this by making freedefer nosplit again and immediately clearing
d.link.

This should fix the longtest builders, which currently fail on
GOMAXPROCS=2 runtime -cpu=1,2,4 -quick in the TestDeferHeapAndStack
test.

This seems like the simplest fix, but it just deals with the subtlety
rather than eliminating it. Really, every call site of freedefer (of
which there are surprisingly many) has hidden subtlety between
unlinking the defer and calling freedefer. We could consolidate the
subtlety into each call site by requiring that they unlink the defer
and set d.link to nil before calling freedefer. freedefer could check
this condition like it checks that various other fields have already
been zeroed. A more radical option is to replace freedefer with
"popDefer", which would both pop the defer off the link and take care
of freeing it. There would still be a brief moment of subtlety, but it
would be in one place, in popDefer. Annoyingly, *almost* every call to
freedefer just pops the defer from the head of the G's list, but
there's one place when handling open-coded defers where we have to
remove a defer from the middle of the list. I'm inclined to first fix
that subtlety by only expanding open-coded defer records when they're
at the head of the defer list, and then revisit the popDefer idea.

Change-Id: I3130d2542c01a421a5d60e8c31f5379263219627
Reviewed-on: https://go-review.googlesource.com/c/go/+/339730
Trust: Austin Clements <austin@google.com>
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2021-08-04 15:51:58 +00:00
Rob Findley d27a889119 [dev.typeparams] go/types: move instance.go contents into named.go (cleanup)
This is a port of CL 338469 to go/types.

Change-Id: I3ee655fa2dc7e789f210c8dec171b3358c4ff132
Reviewed-on: https://go-review.googlesource.com/c/go/+/339677
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-04 11:07:34 +00:00
Rob Findley b01e775e9c [dev.typeparams] go/types: print constraint info for type param operands
This is a clean port of CL 338309 to go/types.

Change-Id: Ie2c9e2ea51d6321af8bf149e43cd71b7ac282d13
Reviewed-on: https://go-review.googlesource.com/c/go/+/339676
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-04 11:07:26 +00:00
Rob Findley 3efc8f9a8d [dev.typeparams] go/types: (TypeParam) SetBound -> SetConstraint
This is a straightforward port of CL 338196 to go/types, minus the
deprecated TypeParam.Bound() method (since it is not needed), plus an
adjustment for methodset.go.

Change-Id: Ie372bfeec245094102a2c3257a43499d75981447
Reviewed-on: https://go-review.googlesource.com/c/go/+/339675
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-04 11:07:19 +00:00
Rob Findley ed3667d079 [dev.typeparams] go/types: use type terms to represent unions
This is a straightforward port of CL 338092 to go/types.

Change-Id: I414ec0ad95648c201e85fd2b4f494b1206c658e7
Reviewed-on: https://go-review.googlesource.com/c/go/+/339674
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-04 11:07:13 +00:00
Rob Findley 880ab6209e [dev.typeparams] cmd/compile/internal/types2: fix a panic in missingMethod
When static == false, missingMethod incorrectly continues with a nil
Func.

Also remove some unnecessary type names from typeterm_test.go, which was
done in the go/types port.

Change-Id: I21fa637ac82b115563d3601314a470a5a43f9ae0
Reviewed-on: https://go-review.googlesource.com/c/go/+/339672
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-08-04 11:07:03 +00:00
Rob Findley 5b51cf47dc [dev.typeparams] go/types: implement type terms
This is a port of CL 338049 to go/types. It identical to that CL, except
for eliding unnecessary typenames from the testTerms declaration.

Change-Id: Ieb04d7bbc20063044eb63ea985f75d529f030cd7
Reviewed-on: https://go-review.googlesource.com/c/go/+/339653
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-04 11:06:37 +00:00
Rob Findley e0d0907212 [dev.typeparams] go/types: use comparable bit rather than ==() method
This is a port of CL 337354 to go/types, adjusted for the error
reporting API and to reposition a couple error messages in
issue47411.go2 (the go/types position is probably better).

A panic is also fixed in lookup.go when method lookup fails and static
== false. I'll send a fix for types2 in a separate CL.

For #47411

Change-Id: Icc48f03c3958695f581f10e8675c1f32434c424b
Reviewed-on: https://go-review.googlesource.com/c/go/+/339652
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-04 11:06:24 +00:00
Rob Findley 18e0503724 [dev.typeparams] go/types: embedded type cannot be a (pointer to) a type parameter
This is a port of CL 337353 to go/types, adjusted for the error API and
to comment out a test for MethodSet.

Some nearby error messages that were using errorf rather than error were
also adjusted.

Fixes #43621

Change-Id: I28c9747e044ec7a2863f6890db69475fb8c29231
Reviewed-on: https://go-review.googlesource.com/c/go/+/339651
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-04 11:06:10 +00:00