Commit graph

49005 commits

Author SHA1 Message Date
180909 9c81fd53b3 cmd/vet: add missing copyright header
Change-Id: I78942dde77547f91daebe763328f52b4c476ddaf
GitHub-Last-Rev: 423f1683fc
GitHub-Pull-Request: golang/go#47334
Reviewed-on: https://go-review.googlesource.com/c/go/+/336434
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Than McIntosh <thanm@google.com>
2021-07-26 21:34:18 +00:00
Robert Griesemer 37d2219960 [dev.typeparams] cmd/compile/internal/types2: embedded type cannot be a (pointer to) a type parameter
Change-Id: I5eb03ae349925f0799dd866e207221429bc9fb3c
Reviewed-on: https://go-review.googlesource.com/c/go/+/337353
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-07-26 20:53:17 +00:00
Robert Griesemer d6753fd491 [dev.typeparams] cmd/compile/internal/types2: implement TypeParam.Constraint
Change-Id: I95a96f9dbd199cee3a4be8f42cd64e7f44ba5e5b
Reviewed-on: https://go-review.googlesource.com/c/go/+/336989
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-07-26 20:53:16 +00:00
Robert Griesemer 9e3274bb3d [dev.typeparams] cmd/compile/internal/types2: import regexp/syntax instead of cmd/compile/internal/syntax
This is a straight port of https://golang.org/cl/330431.

For #43232

Change-Id: I5954bdff22a524eaa08754947da9b428b27f7d95
Reviewed-on: https://go-review.googlesource.com/c/go/+/336351
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-07-26 20:53:15 +00:00
Robert Griesemer b93f646125 [dev.typeparams] cmd/compile/internal/types2: fix a bug in package qualification logic
This is a partial port of https://golang.org/cl/330629, containing
only the actual bug fix and adjustements to another test file.

The respective test case has not been ported yet as it requires
some bigger adjustments.

For #46905

Change-Id: Ibd20658b8a31855da20cf56e24bcce9560656ca0
Reviewed-on: https://go-review.googlesource.com/c/go/+/336350
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-07-26 20:53:13 +00:00
Matthew Dempsky 996b0dbc65 [dev.typeparams] all: merge master (ecaa681) into dev.typeparams
Conflicts:

- src/cmd/compile/internal/ssagen/ssa.go

  CL 336629 touched code that had already been removed on dev.typeparams.

Merge List:

+ 2021-07-26 ecaa6816bf doc: clarify non-nil zero length slice to array pointer conversion
+ 2021-07-26 1868f8296e crypto/x509: update iOS bundled roots to version 55188.120.1.0.1
+ 2021-07-25 849b791129 spec: use consistent capitalization for rune literal hex constants
+ 2021-07-23 0914646ab9 doc/1.17: fix two dead rfc links
+ 2021-07-22 052da5717e cmd/compile: do not change field offset in ABI analysis

Change-Id: Ie570ec3f6a3241e0495e39e8a73b3a09a9368605
2021-07-26 12:19:12 -07:00
Matthew Dempsky bfcb7c4c8a [dev.typeparams] cmd/compile: fix unified IR support for //go:nointerface
This CL changes fixedbugs/issue30862.go into a "runindir" test so that
it can use '-goexperiment fieldtrack' and test that //go:nointerface
works with cmd/compile. In particular, this revealed that -G=3 and
unified IR did not handle it correctly.

This CL also fixes unified IR's support for //go:nointerface and adds
a test that checks that //go:nointerface, promoted methods, and
generics all interact as expected.

Updates #47045.

Change-Id: Ib8acff8ae18bf124520d00c98e8915699cba2abd
Reviewed-on: https://go-review.googlesource.com/c/go/+/332611
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-07-26 18:43:12 +00:00
Cuong Manh Le ecaa6816bf doc: clarify non-nil zero length slice to array pointer conversion
There is an example for nil slice already, so adding example for non-nil
zero length slice, too, clarifying to the reader that the result is also
non-nil and different from nil slice case.

Updates #395

Change-Id: I019db1b1a1c0c621161ecaaacab5a4d888764b1a
Reviewed-on: https://go-review.googlesource.com/c/go/+/336890
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-07-26 17:47:47 +00:00
Dmitri Shuralyov 1868f8296e crypto/x509: update iOS bundled roots to version 55188.120.1.0.1
Updates #38843.

Change-Id: I6e003ed03cd13d8ecf86ce05ab0e11c47e271c0b
Reviewed-on: https://go-review.googlesource.com/c/go/+/337329
Trust: Dmitri Shuralyov <dmitshur@golang.org>
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
2021-07-26 14:24:27 +00:00
Ian Lance Taylor 849b791129 spec: use consistent capitalization for rune literal hex constants
Fixes #47368

Change-Id: I2f65c0008658532123f04d08e99e5d083f33461a
Reviewed-on: https://go-review.googlesource.com/c/go/+/337234
Trust: Ian Lance Taylor <iant@golang.org>
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-07-25 17:16:20 +00:00
Keith Randall b27c7e30dc [dev.typeparams] cmd/compile: fix HasShape, add dottype test
HasShape needs a TINTER case.

Add a test for x.(T) in various situations. Needs the fix above.

Also remove ONEW unshapify case. It is ok for ONEW to have a shape
type, as it will just be passed to mallocgc, or possibly used as a
stack object type, both of which are ok.

Change-Id: Ibddf8f5c8c254d32cb5ebcaca7dc94b4c00ab893
Reviewed-on: https://go-review.googlesource.com/c/go/+/337231
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-07-24 22:49:24 +00:00
Dan Scales a2e2b0362b [dev.typeparams] transformDot() should set Selection and tc flag for added ODOTs
Fixes -G=3 issue with issue44688.go.

Change-Id: Ie98c0cbd48683dedd115332043f14c8f3160f46c
Reviewed-on: https://go-review.googlesource.com/c/go/+/337029
Run-TryBot: Dan Scales <danscales@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Trust: Dan Scales <danscales@google.com>
2021-07-24 17:58:49 +00:00
Dan Scales 3dc0a0a2c5 [dev.typeparams] cmd/compile: get rid of concretify use for bounds.
We just need to substitute from the typeparams to the shapes for the dst
type of the bound.

Removed concretify substituter, not used anymore. Also removed
shape2params, not needed anymore.

However, since the dst type is now not concrete, this gives more cases
where the linker can't find a method.

I realized that we need to call MarkUsedIfaceMethod to mark a method as
used on a particular interface, else a type's method can be still
deadcoded even though MarkTypeUsedInInterface has been called on the
concrete type. I added a new version MarkUsedIfaceMethodIndex to fit my
use case.

Change-Id: Id67b72b350889dd3688b42739c337d5d79a0d1a2
Reviewed-on: https://go-review.googlesource.com/c/go/+/337230
Trust: Dan Scales <danscales@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
2021-07-24 17:47:08 +00:00
Keith Randall 77e0bf294c [dev.typeparams] cmd/compile: introduce OCONVIDATA op
This operation computes just the data field needed to put its argument
into an interface. Used by generics because we produce the type field
of an interface using dictionaries (instead of statically).

With this operation defined, we can now assert that shape types
are never marked as used in interfaces (the only previous use
was IDATA(CONVIFACE(t))).

Change-Id: Idb1eb5f3b238285cb99413d382599c0621b7681a
Reviewed-on: https://go-review.googlesource.com/c/go/+/337109
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-07-24 15:57:01 +00:00
Rob Findley 9f928f9318 [dev.typeparams] go/types, types2: set tset when constructing interfaces in the universe
As of CL 334894, type sets are lazily evaluated on interfaces. For the
universe interfaces error and comparable, this can lead to data races
when type checking concurrently. Fix this by computing their type set
when they are defined.

Tested using the repro from #47345. I considered checking this in as a
test, but it probably wouldn't add much value going forward.

Fixes #47345

Change-Id: I014a511b8e3c092c86201a8bfc7f5f494f8f20e8
Reviewed-on: https://go-review.googlesource.com/c/go/+/336910
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-07-24 01:54:15 +00:00
Keith Randall 6992dcdad9 [dev.typeparams] cmd/compile: fix some issues with cons.go
Add a test to make sure there's no invalid OCONVIFACEs when stenciling is done.

Use concrete types for the type of DOTTYPE and DOTTYPE2.

MarkTypeUsedInInterface - should we allow types with shape types
underneath? I think the itab CL will help with this (at least, for
a remaining cons.go issue).

Change-Id: I2c96d74e8daaca26cadc84ea94abb9a27c0bb240
Reviewed-on: https://go-review.googlesource.com/c/go/+/337069
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-07-23 23:44:49 +00:00
Dan Scales e6d956e1c5 [dev.typeparams] cmd/compile: add CONVIFACE nodes for return values during noder2
Even if we can otherwise transform a return statement because of type
params, add CONVIFACE nodes where appropriate.

Change-Id: Ia2216d5f6805926075ba6802a4385eee1d63e37e
Reviewed-on: https://go-review.googlesource.com/c/go/+/337049
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-07-23 23:07:50 +00:00
Dan Scales 02c0172500 [dev.typeparams] cmd/compile: add dictionary entries for itab conversion
This fix the case where a type param or derived type is converted to a
non-empty interface. Previously, we were converting to an empty
interface and then using DOTTYPE to convert to the correct non-empty
interface. In that case, we can get the needed itab directly from the
dictionary. This is needed for correctness from shapes, if the
destination interface is parameterized, else we will incorrectly convert
to the shape version of the interface.

Creating/writing an itab can involve generating wrappers for a bunch of
methods, which may use dictionaries. So, all the
dictionaries/instantiations are being generated on the fly and have
recursive relationships, it is simplest to finish creating/writing the
itabs at the end of the stenciling phase. So, we create a list of the
dictionaries which need to be completed by writing out their itab
entries.

The existing tests ordered.go, ifaceconv.go, and issue44688.go make use
of this optimization.

Got itab conversions for bound calls working, except for 13.go.
Also, want to get rid of the concretify, but I think we need more info
on the Bound from types2.

Change-Id: If552958a7b8a435500d6cc42c401572c367b30d1
Reviewed-on: https://go-review.googlesource.com/c/go/+/336993
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-07-23 21:16:54 +00:00
Dan Scales 12866bd8ea [dev.typeparams] Add CONVIFACE nodes in noder2, where possible
Changes to add CONVIFACE nodes where possible in noder2, even when the
args are typeparams. The transformation to insert a CONVIFACE node can
usually happen when there an obvious assignment/conversion to an
interface type from a non-interface type. So, we now do this
tranformation for:

 - direct conversions to an interface type

 - function arguments that are implicitly converted to an interface
   based on the parameter types.

 - EQ/NE comparison of an interface and a non-interface

With this change, we can remove some special case checks for CONVIFACE
nodes after transformation in node(), and instead just have the one
check in the CONVIFACE check.

Change-Id: I7cf2ef920aebf9e5553210aeaf19f344e128ca62
Reviewed-on: https://go-review.googlesource.com/c/go/+/336992
Trust: Dan Scales <danscales@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
2021-07-23 20:57:41 +00:00
Alberto Donizetti 0914646ab9 doc/1.17: fix two dead rfc links
Updates #44513

Change-Id: Ia0c6b48bde2719f3a99cb216b6166d82159198d1
Reviewed-on: https://go-review.googlesource.com/c/go/+/336930
Trust: Alberto Donizetti <alb.donizetti@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-07-23 18:10:55 +00:00
Keith Randall 4cdc65d32a [dev.typeparams] cmd/compile/internal/types: format union types
Previously it was just printing <S>. Now it prints things like int32|~int64.

Change-Id: I960b011ce8ed360020a49ae7809d85d1d1fdbfb2
Reviewed-on: https://go-review.googlesource.com/c/go/+/336692
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-07-23 03:55:44 +00:00
Gerrit Code Review 244267e8c4 Merge "[dev.typeparams] all: merge master (798ec73) into dev.typeparams" into dev.typeparams 2021-07-22 20:59:40 +00:00
Cherry Mui 052da5717e cmd/compile: do not change field offset in ABI analysis
Currently, the ABI analysis assigns parameter/result offsets
to the fields of function *Type. In some cases, we may have
an ABI0 function reference and an ABIInternal reference share
the same function *Type. For example, for an ABI0 function F,
"f := F" will make f and (ABI0) F having the same *Type. But f,
as a func value, should use ABIInternal. Analyses on F and f will
collide and cause ICE.

Also, changing field offsets in ABI analysis has to be done very
carefully to avoid data races. It has been causing
trickiness/difficulty.

This CL removes the change of field offsets in ABI analysis
altogether. The analysis result is stored in ABIParamAssignment,
which is the only way to access parameter/result stack offset now.

Fixes #47317.
Fixes #47227.

Change-Id: I23a3e081a6cf327ac66855da222daaa636ed1ead
Reviewed-on: https://go-review.googlesource.com/c/go/+/336629
Trust: Cherry Mui <cherryyz@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Than McIntosh <thanm@google.com>
2021-07-22 20:47:59 +00:00
Matthew Dempsky d8ceb133ca [dev.typeparams] runtime: mark TestGcSys as flaky
I don't know what this test is doing, but it very frequently flakes
for me while testing mundane compiler CLs. According to the issue log,
it's been flaky for ~3 years.

Updates #37331.

Change-Id: I81c43ad646ee12d4c6561290a54e4bf637695bc6
Reviewed-on: https://go-review.googlesource.com/c/go/+/336349
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
2021-07-22 19:51:36 +00:00
Matthew Dempsky a27e325c59 [dev.typeparams] all: merge master (798ec73) into dev.typeparams
Merge List:

+ 2021-07-22 798ec73519 runtime: don't clear timerModifiedEarliest if adjustTimers is 0
+ 2021-07-22 fdb45acd1f runtime: move mem profile sampling into m-acquired section
+ 2021-07-21 3e48c0381f reflect: add missing copyright header
+ 2021-07-21 48c88f1b1b reflect: add Value.CanConvert
+ 2021-07-20 9e26569293 cmd/go: don't add C compiler ID to hash for standard library
+ 2021-07-20 d568e6e075 runtime/debug: skip TestPanicOnFault on netbsd/arm

Change-Id: I87e1cd4614bb3b00807f18dfdd02664dcaecaebd
2021-07-22 12:50:31 -07:00
Ian Lance Taylor 798ec73519 runtime: don't clear timerModifiedEarliest if adjustTimers is 0
This avoids a race when a new timerModifiedEarlier timer is created by
a different goroutine.

Fixes #47329

Change-Id: I6f6c87b4a9b5491b201c725c10bc98e23e0ed9d1
Reviewed-on: https://go-review.googlesource.com/c/go/+/336432
Trust: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
2021-07-22 19:26:40 +00:00
Keith Randall 5cb84f0604 [dev.typeparams] cmd/compile: make sure types added to the dictionary are instantiated correctly
Make sure the instantiating types are the type parameters of the containing
function (or types derived from those).

The one exception is the argument of a OFUNCINST, whose type
parameters are those of the declaration site of the function or method
being instantiated. We skip those types.

Change-Id: I4b3ff22eb8a81a76476930cf8ed2a7dd6489d8b8
Reviewed-on: https://go-review.googlesource.com/c/go/+/336352
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-07-22 18:09:49 +00:00
Cuong Manh Le 73162a54c2 [dev.typeparams] cmd/compile: remove outdate TODO in escape analysis
We now understand the root cause of #47227, it will be fixed in #47317.

Change-Id: Ifcd44f887a0bd3195818df33e409bd3e818e0b27
Reviewed-on: https://go-review.googlesource.com/c/go/+/336610
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-07-22 17:54:48 +00:00
Robert Griesemer 80127a7dfe [dev.typeparams] cmd/compile/internal/types2: adjust unsafe.Alignof/Offsetof/Sizeof
Changed the implementation such that the result is a variable rather than
a constant if the argument type (or the struct in case of unsafe.Offsetof)
has a size that depends on type parameters.

Minor unrelated adjustments.

For #40301.

Change-Id: I1e988f1479b95648ad95a455c764ead829d75749
Reviewed-on: https://go-review.googlesource.com/c/go/+/335413
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-07-22 17:53:51 +00:00
Cuong Manh Le fca3e5c445 [dev.typeparams] cmd/compile: fix missing condition in usemethod
CL 330670 simplified usemethod, but dropped the previous condition to
ensure the function have 1 or 2 result. This CL restore that condition,
and also add a test for it.

Change-Id: I434e3736785b43ceea0b386d8d9d01ad78a4ccd2
Reviewed-on: https://go-review.googlesource.com/c/go/+/336609
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-07-22 17:48:41 +00:00
Rob Findley 5ba06495c1 [dev.typeparams] go/types: use the TParams API consistently
Even internally to the type checker, we should use the TParams and
RParams methods instead of accessing fields directly, as TParams may be
lazily expanded, and in the future we may want to pack receiver and
function type parameters into a single field on Signature.

We should also not differentiate a nil *TParamList from an empty
*TParamList.

Change-Id: I85c616e6c708a89b6a5eb1e69fe0b014276eda90
Reviewed-on: https://go-review.googlesource.com/c/go/+/336251
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-07-22 17:24:27 +00:00
Rob Findley 6f57139c7a [dev.typeparams] go/types: set type parameter indices when they are bound
It is invalid to use a type parameter for more than one type, so we can
avoid passing the type parameter index to NewTypeParam and just set it
when type parameters are bound to a type via SetTParams or during type
checking.

In order to enforce the correctness of this change, introduce a
TypeParams type to represent a list of type parameters that have been
associated with a type. For now, expose this new type as the API for
type parameters, but this is of course not necessarily a final API.

Allowing *TypeParams to be nil also decreases the size of Named and
Signature, which is good as most instances of these types will not be
parameterized.

Change-Id: Ia1e39ba51edb05bb535eb5f41c34e9dd02d39c38
Reviewed-on: https://go-review.googlesource.com/c/go/+/336249
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-07-22 17:05:56 +00:00
Matthew Dempsky 311baf65f4 [dev.typeparams] test: cleanup 'go env' and -goexperiment
This CL makes two related changes:

1. It uses 'go env -json' to query the environment configuration,
rather than attempting to manually reconstruct the values that cmd/go
is going to use.

2. It changes the -goexperiment flag to *extend* any ambient
GOEXPERIMENT configuration. Notably, this means that '-goexperiment
fieldtrack' now tests fieldtracking in conjunction with any other
experiments (e.g., unified IR). Tests that want to test an exact
GOEXPERIMENT config should use '-goexperiment none,foo' instead.

Change-Id: I96a97198209e540e934fe7035110c3ae3a8f0e6a
Reviewed-on: https://go-review.googlesource.com/c/go/+/332610
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-07-22 17:01:49 +00:00
David Chase fdb45acd1f runtime: move mem profile sampling into m-acquired section
It was not safe to do mcache profiling updates outside the critical
section, but we got lucky because the runtime was not preemptible.
Adding chunked memory clearing (CL 270943) created preemption
opportunities, which led to corruption of runtime data structures.

Fixes #47304.
Fixes #47302.

Change-Id: I461615470d62328a83ccbac537fbdc6dcde81c85
Reviewed-on: https://go-review.googlesource.com/c/go/+/336449
Trust: David Chase <drchase@google.com>
Run-TryBot: David Chase <drchase@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
2021-07-22 17:01:15 +00:00
Rob Findley b7149b781f [dev.typeparams] go/types: trigger verification while resolving instance
The refactoring of CL 335929 to merge the instance and Named types
resulted in type instances only being evaluated once. As a side effect,
we only verified constraints once per unique instantiation expression.

This can be confusing if type instantations are occurring far apart in
the code. Resolve this by lifting up the verification logic into
Instantiate and InstantiateLazy.

Change-Id: Icd5a482d097d983073955c62931441edfd92f5c2
Reviewed-on: https://go-review.googlesource.com/c/go/+/335978
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-07-22 14:01:09 +00:00
Rob Findley 61f69d2559 [dev.typeparams] go/types: merge instance and Named to eliminate sanitization
Storing temporary syntactic information using an *instance type forces
us to be careful not to leak references to *instance in the checker
output. This is complex and error prone, as types are written in many
places during type checking.

Instead, temporarily pin the necessary syntactic information directly to
the Named type during the type checking pass. This allows us to avoid
having to sanitize references.

This includes a couple of small, unrelated changes that were made in the
process of debugging:
 - eliminate the expandf indirection: it is no longer necessary
 - include type parameters when printing objects

For #46151

Change-Id: I767e35b289f2fea512a168997af0f861cd242175
Reviewed-on: https://go-review.googlesource.com/c/go/+/335929
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-07-22 14:00:49 +00:00
Dan Scales 8e9109e95a [dev.typeparams] Fix problem with 14.go
Removed a case in transformCall() where we were setting a type on n,
which isn't needed, since noder2 already set the type of n. More
importantly, we are losing information, since the type of the results
may be a shape type, but the actual type of call is the known type
from types2, which may be a concrete type (in this case Zero[MyInt]).
That concrete type will then be used correctly if the concrete result is
converted to an interface.

If we are inlining the call to Zero[MyInt], we need to add an implicit
CONVNOP operation, since we are going to use the result variable
directly, which has a shape type. So, add an implicit CONVNOP to
remember that the known type is the concrete type.

Also cleaned up 14.go a bit, so it is more understandable. Renamed type
T to AnyInt, since T is used elsewhere as a type parameter. Reformatted
Zero function and added a comment.

Change-Id: Id917a2e054e0bbae9bd302232853fa8741d49b64
Reviewed-on: https://go-review.googlesource.com/c/go/+/336430
Trust: Dan Scales <danscales@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
2021-07-22 04:45:49 +00:00
Dan Scales ee20dff27d [dev.typeparams] Get dictionaryCapture.go working.
METHVALUE in a generic function (that is not called) was not causing
buildClosure() to be called and therefore not using dictionaries. Also,
had to add an extra check to make sure that if we have a FUNCINST
node above a METHVALUE, we only call buildClosure once.

Change-Id: I49756152fc343e5ac1c449e697960fc2a0f482ae
Reviewed-on: https://go-review.googlesource.com/c/go/+/336429
Reviewed-by: Keith Randall <khr@golang.org>
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Dan Scales <danscales@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-07-22 04:44:48 +00:00
Dan Scales 4e6836e82c [dev.typeparams] Fix the types of the OFUNCINST nodes in noder2
types2 doesn't actually give us the type of an instantiated
function/method after the type args have been applied. So, do a
substitution at the point that we create the OFUNCINST nodes.

We also needed to add in translation of the typeparams of a function
signature in the type substituter. If the type params of the function
become all concrete after the substitution, then we just drop them,
since the whole signature must now be concrete.

Change-Id: I6116d2aa248be6924ec9e6d8516678db45aa65c4
Reviewed-on: https://go-review.googlesource.com/c/go/+/336370
Run-TryBot: Dan Scales <danscales@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Dan Scales <danscales@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
2021-07-21 21:52:05 +00:00
Dan Scales dcc8350ad3 [dev.typeparams] cmd/compile: handle ++/-- in noder2 for operands with generic type
types2 will have already proved the expression's type is compatible, so
just assign the one const to have the same type as the operand.

Fixes #47258.

Change-Id: If0844e6bf6d0a5e6b11453b87df71353863ccc5d
Reviewed-on: https://go-review.googlesource.com/c/go/+/336009
Run-TryBot: Dan Scales <danscales@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Trust: Dan Scales <danscales@google.com>
2021-07-21 21:30:48 +00:00
Dan Scales f19e49e7b1 [dev.typeparams] cmd/compile: added a builtins.go test, fixed one bug
The builtins.go test is derived from
cmd/compile/internal/types2/testdata/check/builtins.go2, after removing
the error cases.  Added a few extra tests for len/cap/append.

Fixed one bug, which is that DELETE operations can't be transformed if
their argument is a typeparam. Also, the tranform of LEN/CAP calls does
not need to be delayed. Removed out-date references to the old
typechecker in the comments.

Change-Id: If7a21506a7ff63ff7c8e87ccd614ef4ff3a0d3c8
Reviewed-on: https://go-review.googlesource.com/c/go/+/336010
Run-TryBot: Dan Scales <danscales@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Trust: Dan Scales <danscales@google.com>
2021-07-21 21:25:20 +00:00
Keith Randall e6a2cf233f [dev.typeparams] cmd/compile: get runtime stuff working
Remaining stuff from Dan's CL 335412 to get tests passing.

 - Removed PTRLIT case in node() that was added with the gcshape change.
   I don't think it is needed anymore.

 - Modified (*itab).init() to add an irrelevant pointer (the itab
   itself) for the '==' entry of interfaces with 'comparable'. That
   entry is not used, so we just want to avoid the error that the given
   type doesn't actually have an '==' method.

Change-Id: I9b2d4c8342c0b2048d76e003d95023f4ccd559f5
Reviewed-on: https://go-review.googlesource.com/c/go/+/336149
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
Trust: Dan Scales <danscales@google.com>
Trust: Keith Randall <khr@golang.org>
2021-07-21 21:06:02 +00:00
Keith Randall 4a97fe8c22 [dev.typeparams] cmd/compile: avoid adding incorrectly instantiated types to the dictionary
FUNCINST nodes aren't instantiated correctly. Skip those types when
adding to the set of types considered for the dictionary.  Those types
include those which are uninstantiated(have tparams), and those with
type parameters that aren't a parameter of the containing function
(they are the type parameter of the function being called).

Allow func types to be put in the dictionary.

Change-Id: I26bab85d3eebc2f54d02b4bba5e31407faf7c5b2
Reviewed-on: https://go-review.googlesource.com/c/go/+/336129
Reviewed-by: Dan Scales <danscales@google.com>
Trust: Dan Scales <danscales@google.com>
Trust: Keith Randall <khr@golang.org>
2021-07-21 21:05:50 +00:00
Keith Randall 2fe4b14795 [dev.typeparams] cmd/compile: ensure methods of generic types survive linker pruning
Calling MarkTypeUsedInInterface before inlining is problematic (when
using the containing function as the reference source), because we end
up attaching a relocation to the original function, which is then
deadcode removed because all instances of it were inlined. (All other
current uses of MarkTypeUsedInInterface happen after inlining, so they
don't have this problem.)

Instead, attach the relocation to the dictionary in which the type
appears.  This should always work, because if the dictionary is ever
deadcode eliminated, then the type can never be put in an interface,
which means we indeed don't need its methods.

This CL is a bit overkill, as not *all* types in the dictionary need
this mark, but it is sufficient for now.

Change-Id: I2d39456691f1c3df8efe3bddc3b9017e0ef37a7f
Reviewed-on: https://go-review.googlesource.com/c/go/+/336012
Trust: Keith Randall <khr@golang.org>
Trust: Dan Scales <danscales@google.com>
Reviewed-by: Dan Scales <danscales@google.com>
2021-07-21 21:05:28 +00:00
Keith Randall 73af5f718f [dev.typeparams] cmd/compile: disable failing generic tests
We'll have to revisit eventually, but disabling for now.

Change-Id: Ic34cfe451939d61884079bb125b9290db1e05e47
Reviewed-on: https://go-review.googlesource.com/c/go/+/335829
Run-TryBot: Keith Randall <khr@golang.org>
Trust: Keith Randall <khr@golang.org>
Trust: Dan Scales <danscales@google.com>
Reviewed-by: Dan Scales <danscales@google.com>
2021-07-21 21:04:29 +00:00
Keith Randall a7a17f0ca8 [dev.typeparams] cmd/compile: introduce named gcshape types
Still 1-1 with real types, but now with their own names!

Shape types are implicitly convertible to (and convertible from)
the types they represent.

Change-Id: I0133a8d8fbeb369380574b075a32b3c987e314d5
Reviewed-on: https://go-review.googlesource.com/c/go/+/335170
Run-TryBot: Keith Randall <khr@golang.org>
Trust: Keith Randall <khr@golang.org>
Trust: Dan Scales <danscales@google.com>
Reviewed-by: Dan Scales <danscales@google.com>
2021-07-21 21:04:15 +00:00
wdvxdr 3e48c0381f reflect: add missing copyright header
Change-Id: I5a2f7203f83be02b03aa7be5fe386e485bf68ca3
Reviewed-on: https://go-review.googlesource.com/c/go/+/336189
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Robert Findley <rfindley@google.com>
2021-07-21 20:29:18 +00:00
Ian Lance Taylor 48c88f1b1b reflect: add Value.CanConvert
For #395
For #46746

Change-Id: I4bfc094cf1cecd27ce48e31f92384cf470f371a6
Reviewed-on: https://go-review.googlesource.com/c/go/+/334669
Trust: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
2021-07-21 19:25:48 +00:00
Matthew Dempsky 897970688b [dev.typeparams] cmd/compile: cleanup unified IR file format a little
This CL makes two changes:

1. It moves object symbols and code tags into a new "relocName"
relocation, which should eventually allow getting rid of objStub.

2. It moves the type parameter data into the relocObjDict relocation,
so everything related to writing out dictionaries is contained there.

Change-Id: If0f7ff7d9384e8664957c3180bf6f20e97bcff6e
Reviewed-on: https://go-review.googlesource.com/c/go/+/336051
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-07-21 01:29:21 +00:00
Cuong Manh Le d5f6ba943c [dev.typeparams] test: add regression test for go/defer wrapper
CL 330330 moved logic for wrapping go/defer from order to esacpe
analysis. It introduced a bug involves go/defer statement with ABI0
functions.

Consider this following code:

	package p

	//go:cgo_unsafe_args
	func g(*int) (r1 struct{}) {
		return
	}

	func f() {
		defer g(new(int))
	}

g is a cgo-like generated function with ABI0. While compiling g, we set
the offset per ABI0.

The function f is rewritten into:

	func f() {
		_0, _1 := g, new(int)
		defer func() { _0(_1) }()
	}

The temporary _0 hold function value with the same type as g, but with
class PAUTO. Thus ssagen/ssa.go:state.call cannot handle it and use
ABIDefault to set the offset, causes the offset of r1 changed

CL 330332 intended to optimize code generated for wrapping function, by
rewriting the wrapper function into:

	func f() {
		_0 := new(int)
		defer func() { g(_0) }()
	}

So it fixed the bug unintentionally.

This CL add regression test for this bug, and also add a comment to
explain while not wrapping declared function is important.

Updates #47227

Change-Id: I75c83d1d9cc7fd4699e6b218a295d0c0a10ef471
Reviewed-on: https://go-review.googlesource.com/c/go/+/334882
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-07-21 00:01:12 +00:00