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

51383 Commits

Author SHA1 Message Date
Michael Matloob
ecf3b39c2a cmd/go: have go work init use the -workfile flag
Change-Id: Idb4795bde699c919222953ec33fa1083798b2000
Reviewed-on: https://go-review.googlesource.com/c/go/+/385654
Trust: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2022-02-14 19:02:39 +00:00
Damien Neil
3d7f836123 net/http: deflake request-not-written path
When we receive an error writing the first byte of a request to a
reused connection, we retry the request on a new connection. Remove
a flaky path which could cause the request to not be retried if
persistConn.roundTrip reads the error caused by closing the connection
before it reads the write error that caused the connection to be
closed.

Fixes #30938.

Change-Id: Iafd99e3239cd9dba4a4c9ddd950a877ca9815e59
Reviewed-on: https://go-review.googlesource.com/c/go/+/379554
Trust: Bryan Mills <bcmills@google.com>
Trust: Damien Neil <dneil@google.com>
Reviewed-by: Russ Cox <rsc@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-02-14 17:30:31 +00:00
Robert Findley
875a6d4010 go/types, types2: no need to revert tparam renaming in inference results
This is a follow up to CL 385494. In early patch sets of that CL,
renamed type parameters were substituted in arguments, which meant that
they could leak into the inference results. However, we subsequently
realized that we could instead substitute in the signature parameters.
In this case it is not possible for the substituted type parameters to
appear in the resulting type arguments, so there is no need to
un-substitute.

Change-Id: I4da45b0b8d7ad809d0ddfa7061ae5f6f07895540
Reviewed-on: https://go-review.googlesource.com/c/go/+/385574
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2022-02-14 12:26:56 +00:00
Robert Griesemer
badbc52d82 spec: highlight missing prose for easier review, fixed a few sections
The (temporary) highlights will make it easier to review the spec
in formatted form as opposed to html text.

Added a missing rule about the use of adjusted core types for
constraint type inference.

Adjusted rule for invalid embedding of interface types.

Change-Id: Ie573068d2307b66c937e803c486724175415b9c6
Reviewed-on: https://go-review.googlesource.com/c/go/+/385535
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2022-02-14 05:18:03 +00:00
Robert Findley
93b5309f0a go/types, types2: avoid infinitely recursive instantiation
Type inference uses type parameter pointer identity to keep track of the
correspondence between type parameters and type arguments. However, this
technique can misidentify type parameters that are used in explicit type
arguments or function arguments, as in the recursive instantiation
below:

  func f[P *Q, Q any](p P, q Q) {
  	f[P]
  }

In this example, the fact that the P used in the instantation f[P] has
the same pointer identity as the P we are trying to solve for via
unification is coincidental: there is nothing special about recursive
calls that should cause them to conflate the identity of type arguments
with type parameters. To put it another way: any such self-recursive
call is equivalent to a mutually recursive call, which does not run into
any problems of type parameter identity. For example, the following code
is equivalent to the code above.

  func f[P interface{*Q}, Q any](p P, q Q) {
  	f2[P]
  }

  func f2[P interface{*Q}, Q any](p P, q Q) {
  	f[P]
  }

We can turn the first example into the second example by renaming type
parameters in the original signature to give them a new identity. This
CL does this for self-recursive instantiations.

Fixes #51158
Fixes #48656
Updates #48619

Change-Id: I54fe37f2a79c9d98950cf6a3602335db2896dc24
Reviewed-on: https://go-review.googlesource.com/c/go/+/385494
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-02-14 02:34:05 +00:00
Ian Lance Taylor
16b1893600 test: add notinheap test that caused a gofrontend crash
Change-Id: Ie949f2131845f9f9292caff798f6933648779122
Reviewed-on: https://go-review.googlesource.com/c/go/+/385434
Trust: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
2022-02-13 18:51:07 +00:00
Robert Griesemer
5bd734839d go/types, types2: add additional tests using core types during unification
This change adds tests that use a type parameter's core type during
function argument type inference, not just during constraint type
inference.

Also, fix a typo in a comment.

For #50755.

Change-Id: I0c3196bdce5338341e0b6dfd7c63efb2e43ace25
Reviewed-on: https://go-review.googlesource.com/c/go/+/385376
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-02-13 02:11:11 +00:00
Robert Griesemer
f03ab0e014 go/types, types2: unify core types for unbound type parameters
NOTE: Should this change cause problems, the new functionality
can be disabled by setting the flag enableCoreTypeUnification
in unify.go to false.

In the code

func f1[M1 map[K1]int, K1 comparable](m1 M1) {}

func f2[M2 map[K2]int, K2 comparable](m2 M2) {
	f1(m2)
}

type inference attempts to unify the types of m1 and m2. This leads
to the unification attempt of M1 and M2. The result is that the type
argument for M1 is inferred to be M2. Since there is no furter function
argument to use, constraint type inference attempts to infer the type
for K1 which is still missing. Constraint type inference (inferB in
the trace below) compares the inferred type for M1 (i.e., M2) against
map[K1]int. M2 is bound to f2, not f1; with the existing algorithm
that means M2 is simply a named type without further information.
Unification fails and with that type inference, and the type checker
reports an error.

-- inferA [M1₁, K1₂] ➞ []
M1₁ ≡ M2₃
.  M1₁ ➞ M2₃
-- inferB [M1₁, K1₂] ➞ [M2₃, <nil>]
M1₁ ➞ M2₃
M1₁ ≡ map[K1₂]int
.  M2₃ ≡ map[K1₂]int
.  M2₃ ≢ map[K1₂]int
M1₁ ≢ map[K1₂]int
=> inferB [M1₁, K1₂] ➞ []
=> inferA [M1₁, K1₂] ➞ []

With this change, when attempting to unify M2 with map[K1]int,
rather than failing, the unifier now considers the core type of
M2 which is map[K2]int. This leads to the unification of K1 and
K2; so type inference successfully infers M2 for M1 and K2 for K1.

-- inferA [M1₁, K1₂] ➞ []
M1₁ ≡ M2₃
.  M1₁ ➞ M2₃
-- inferB [M1₁, K1₂] ➞ [M2₃, <nil>]
M1₁ ➞ M2₃
M1₁ ≡ map[K1₂]int
.  M2₃ ≡ map[K1₂]int
.  .  core M2₃ ≡ map[K1₂]int
.  .  map[K2₄]int ≡ map[K1₂]int
.  .  .  K2₄ ≡ K1₂
.  .  .  .  K1₂ ➞ K2₄
.  .  .  int ≡ int
=> inferB [M1₁, K1₂] ➞ [M2₃, K2₄]
=> inferA [M1₁, K1₂] ➞ [M2₃, K2₄]

The fix for this issue was provided by Rob Findley in CL 380375;
this change is a copy of that fix with some additional changes:

- Constraint type inference doesn't simply use a type parameter's
  core type. Instead, if the type parameter type set consists of
  a single, possibly named type, it uses that type. Factor out the
  existing code into a new function adjCoreType. This change is not
  strictly needed but makes it easier to think about the code.

- Tracing code is added for debugging type inference. All tracing
  code is guarded with the flag traceEnabled which is set to false
  by default.

- The change to the unification algorithm is guarded with the flag
  enableCoreTypeUnification.

- The sprintf function has a new type switch case for lists of
  type parameters. This is used for tracing output (and was also
  missing for a panic that was printing type parameter lists).

Fixes #50755.

Change-Id: Ie50c8f4540fcd446a71b07e2b451a95339b530ce
Reviewed-on: https://go-review.googlesource.com/c/go/+/385354
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-02-12 18:53:12 +00:00
Ian Lance Taylor
f14ad78e84 net: send EDNS(0) packet length in DNS query
We used to only accept up to 512 bytes in a DNS packet, per RFC 1035.
Increase the size we accept to 1232 bytes, per https://dnsflagday.net/2020/,
and advertise that larger limit in a EDNS(0) OPT record.

Fixes #6464
Fixes #21160
Fixes #44135
Fixes #51127

Change-Id: I496a294e9a8015de4161cbc1825b0dc5b4e9f5d8
Reviewed-on: https://go-review.googlesource.com/c/go/+/385035
Trust: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2022-02-12 05:44:16 +00:00
Robert Griesemer
badba359da go/types, types2: better error message for invalid array length
If an invalid array length is just an identifier, mention
"array length" so that it's clear this is an invalid array
declaration and not a (invalid) generic type declaration.

Fixes #51145.

Change-Id: I8878cbb6c7b1277fc0a9a014712ec8d55499c5c7
Reviewed-on: https://go-review.googlesource.com/c/go/+/385255
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-02-11 22:01:05 +00:00
Cherry Mui
bcee121ae4 cmd/compile, runtime: use unwrapped PC for goroutine creation tracing
With the switch to the register ABI, we now generate wrapper
functions for go statements in many cases. A new goroutine's start
PC now points to the wrapper function. This does not affect
execution, but the runtime tracer uses the start PC and the
function name as the name/label of that goroutine. If the start
function is a named function, using the name of the wrapper loses
that information. Furthur, the tracer's goroutine view groups
goroutines by start PC. For multiple go statements with the same
callee, they are grouped together. With the wrappers, which is
context-dependent as it is a closure, they are no longer grouped.

This CL fixes the problem by providing the underlying unwrapped
PC for tracing. The compiler emits metadata to link the unwrapped
PC to the wrapper function. And the runtime reads that metadata
and record that unwrapped PC for tracing.

(This doesn't work for shared buildmode. Unfortunate.)

TODO: is there a way to test?

Fixes #50622.

Change-Id: Iaa20e1b544111c0255eb0fc04427aab7a5e3b877
Reviewed-on: https://go-review.googlesource.com/c/go/+/384158
Trust: Cherry Mui <cherryyz@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-02-11 20:01:24 +00:00
Bryan C. Mills
0bde2cf5fe runtime: skip TestSegv/SegvInCgo failures with "runtime: unknown pc"
This test has failed on four different builders in the past month.
Moreover, because every Go program depends on "runtime", it is likely
to be run any time a user runs 'go test all' in their own program.

Since the test is known to be flaky, let's skip it to avoid
introducing testing noise until someone has time to investigate. It
seems like we have enough samples in the builder logs to at least
start with.

For #50979

Change-Id: I9748a82fbb97d4ed95d6f474427e5aa6ecdb023d
Reviewed-on: https://go-review.googlesource.com/c/go/+/385154
Trust: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-02-11 19:36:36 +00:00
Michael Matloob
23386b5f67 cmd/go: support workspaces in vet
Add modload.InitWorkfile to runVet so that the vet command recognizes
and uses the workspace.

Fixes #51072

Change-Id: Ia6727eff9b80eb33627f5ae23e4d72cde581e75f
Reviewed-on: https://go-review.googlesource.com/c/go/+/385176
Trust: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-02-11 18:50:49 +00:00
Bryan C. Mills
0a9d6a31b1 runtime: update TestGdbBacktrace skips for known GDB bugs
Fixes #50838

Change-Id: Ib7e7563cd63d85a508984e4162eda38232b250d3
Reviewed-on: https://go-review.googlesource.com/c/go/+/385175
Trust: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-02-11 17:05:42 +00:00
Robert Griesemer
18e1a5a085 spec: combine section on type parameters and type parameter lists
This change moves the relevant prose of the section on type parameters
into the section on type parameter lists and eliminates the former.

With this change, the section on types now exclusively describes all
Go composite types.

User-defined named types (defined types and type parameters) are
described with their declarations.

Change-Id: I3e421cd236e8801d31a4a81ff1e5ec9933e3ed20
Reviewed-on: https://go-review.googlesource.com/c/go/+/385037
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2022-02-11 16:26:49 +00:00
Robert Griesemer
ea9b1f1573 spec: add a section on implementing an interface
Also, fixed several closing header tags and removed a duplicate "the".
(Thanks to @hopehook and Hossein Zolfi for pointing these out.)

Change-Id: I85a40ba44b8570a578bce8d211dcc5ea3901fb1e
Reviewed-on: https://go-review.googlesource.com/c/go/+/385036
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2022-02-11 16:26:45 +00:00
Jonathan Amsterdam
f2ec001845 go/doc: mark comparable predeclared
Add comparable to the list of predeclared types.

Fixes golang/go#51141.

Change-Id: I4a2d4e7e5680e115de9bca03b6c8ad454551cb82
Reviewed-on: https://go-review.googlesource.com/c/go/+/385114
Trust: Jonathan Amsterdam <jba@google.com>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-02-11 16:05:02 +00:00
Robert Griesemer
e50f0f372b spec: describe processing of function arguments for type inference more precisely
The outcome of type inference depends critically on when function
argument type inference stops processing arguments. Describe this
and explain an example with some detail.

Also: In the section on the built-in function delete, refer to the
value rather than the type of the second argument, as it may be an
untyped constant.

Change-Id: Ice7fbb33f985afe082380b8d37eaf763238a3818
Reviewed-on: https://go-review.googlesource.com/c/go/+/385034
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2022-02-11 05:11:58 +00:00
Kevin Burke
9fdcfb7c10 doc: fix spelling error in link ID
Change-Id: I6de236442f213ab4b4f19ec881add4923d8bfd8d
Reviewed-on: https://go-review.googlesource.com/c/go/+/385054
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Kevin Burke <kevin@burke.dev>
2022-02-11 04:50:35 +00:00
Robert Griesemer
30501bbef9 spec: introduce notion of basic interface, misc. fine-tuning
A basic interface is a classical Go interface containing only
methods or embedding basic interfaces.

Use this to simplify rule about what interfaces may be used
where. The term "basic interface" will also be useful when
talking about various interfaces in general.

Fix rule restricting union terms: as it was written it also
excluded interface terms with non-empty method sets due to
embedded non-interface types with methods.

Split the large section on interfaces into three smaller
pieces by introducing section titles.

Change-Id: I142a4d5609eb48aaa0f7800b5b85c1d6c0703fcb
Reviewed-on: https://go-review.googlesource.com/c/go/+/384994
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2022-02-11 00:30:56 +00:00
Robert Griesemer
ca3fae1e0e spec: use the term "generic" rather than "(type-)parameterized"
This makes the prose easier to read while being just as precise.

Change-Id: Ie46c6c5042f419de9fdeb1c75bb72b5a40c37073
Reviewed-on: https://go-review.googlesource.com/c/go/+/384774
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-02-11 00:26:29 +00:00
Robert Griesemer
11788aa6e0 spec: adjust rules to use core or specific types as necessary
Change-Id: I64280c1bb9608d7781514f237ac70c6abbfde9f6
Reviewed-on: https://go-review.googlesource.com/c/go/+/384754
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2022-02-11 00:26:18 +00:00
Suvaditya Sur
c4b87b8d08 abi-internal: Fix typo in register assignment documentation
If register assignment fails, revert back the value to stack

Change-Id: I6f65092461ad4d793206a679a5fef1b560b387f0
Reviewed-on: https://go-review.googlesource.com/c/go/+/384455
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
2022-02-10 22:20:18 +00:00
Robert Griesemer
99b61be9f5 spec: move all sections describing type properties into one place
This change only shuffles sections for better organization; there
are no other changes except title and link adjustments.

Until now, the sections on underlying types and method sets were
immediately following the introduction of types. As it becomes
necessary to introduce the notion of a core type more centrally,
the natural place is immediately following the section on underlying
types. All together, these sections, immediately after the introduction
of types, would distract from purpose of the section on types, which
is to introduce the various types that Go offers.

The more natural place for the definition of underlying, core, and
specific types is the section on properties of types and values.

To accomplish this, the section on the structure of interfaces is
split into a section on core types and one on specific types, and
the various sections are reorganized appropriately.

The new organization of the section on types now simply introduces
all Go types as follows:

- boolean types
- numeric types
- string types
- array types
- slice types
- struct types
- pointer types
- function types
- interface types
- map types
- channel types
- type parameters

The new organization of the section on properties of types and values
is as follows:

- underlying types
- core types
- specific types
- type identity
- assignability
- representability
- method sets

Change-Id: I59e4d47571da9d4c89d47d777f5353fb1c5843e6
Reviewed-on: https://go-review.googlesource.com/c/go/+/384623
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-02-10 21:40:49 +00:00
Robert Griesemer
3b8c716e0f spec: document numeric operations behavior for generic types
Includes a few minor cosmetic changes.

Change-Id: I6c307d958b47d83671142688630ea7835168439f
Reviewed-on: https://go-review.googlesource.com/c/go/+/384622
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2022-02-10 21:40:12 +00:00
Michael Matloob
8ba3ad92eb cmd/go: mention go.work when local path outside modules in go.work
In workspace mode, if a user lists a package or patternthat's inside a
module that's not listed in go.work, mention that the package or pattern
is outside the modules listed in go.work so the user has a better idea
of how to fix the issue.

(Question: it's valid in those flows to add a pattern that points into
the module cache. Should we expand the error to say "package outside
modules listed in go.work file or contained in module cache"? That seems
clunky (and is the uncommon case) which is why I didn't do so in this
case, but it's possible)

Fixes #49632

Change-Id: I3f0ea1b2f566d52a8079b58593fcc5cc095e7a41
Reviewed-on: https://go-review.googlesource.com/c/go/+/384236
Trust: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-02-10 19:08:19 +00:00
Michael Anthony Knyszek
e4a173adf6 runtime: make piController much more defensive about overflow
If something goes horribly wrong with the assumptions surrounding a
piController, its internal error state might accumulate in an unbounded
manner. In practice this means unexpected Inf and NaN values.

Avoid this by identifying cases where the error overflows and resetting
controller state.

In the scavenger, this case is much more likely. All that has to happen
is the proportional relationship between sleep time and estimated CPU
usage has to break down. Unfortunately because we're just measuring
monotonic time for all this, there are lots of ways it could happen,
especially in an oversubscribed system. In these cases, just fall back
on a conservative pace for scavenging and try to wait out the issue.

In the pacer I'm pretty sure this is impossible. Because we wire the
output of the controller to the input, the response is very directly
correlated, so it's impossible for the controller's core assumption to
break down.

While we're in the pacer, add more detail about why that controller is
even there, as well as its purpose.

Finally, let's be proactive about other sources of overflow, namely
overflow from a very large input value. This change adds a check after
the first few operations to detect overflow issues from the input,
specifically the multiplication.

No tests for the pacer because I was unable to actually break the
pacer's controller under a fuzzer, and no tests for the scavenger because
it is not really in a testable state.

However:
* This change includes a fuzz test for the piController.
* I broke out the scavenger code locally and fuzz tested it, confirming
  that the patch eliminates the original failure mode.
* I tested that on a local heap-spike test, the scavenger continues
  operating as expected under normal conditions.

Fixes #51061.

Change-Id: I02a01d2dbf0eb9d2a8a8e7274d4165c2b6a3415a
Reviewed-on: https://go-review.googlesource.com/c/go/+/383954
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
Trust: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-02-10 18:55:42 +00:00
Bryan C. Mills
18c2033ba5 runtime/pprof: remove arbitrary sleeps in TestBlockProfile
The "block" helpers in TestBlockProfile previously slept for an
arbitrary duration and assumed that that duration was long enough for
the parent goroutine to have registered as blocking. However —
especially on slow or overloaded builders — the current arbitrary
duration is sometimes not quite long enough.

Rather than increasing the duration to a different arbitrary value
(which would make the test slower but not actually eliminate the
possibility of flakes!), we can use the runtime's own accounting to
detect when the goroutine is actually blocked: we obtain a goroutine
dump from the runtime, and assume that blocking has been registered in
the profile only if the runtime shows the test goroutine in the
appropriate blocked state.

That not only makes the test more reliable, but also makes it
significantly lower-latency when run on a fast machine.

Fixes #6999
Fixes #37844

Change-Id: I465ed2afd406fd2b621419e1f06925f283525f25
Reviewed-on: https://go-review.googlesource.com/c/go/+/384534
Trust: Bryan Mills <bcmills@google.com>
Trust: Benny Siegert <bsiegert@gmail.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2022-02-10 17:31:59 +00:00
Russ Cox
452f24ae94 regexp/syntax: reject very deeply nested regexps in Parse
The regexp code assumes it can recurse over the structure of
a regexp safely. Go's growable stacks make that reasonable
for all plausible regexps, but implausible ones can reach the
“infinite recursion?” stack limit.

This CL limits the depth of any parsed regexp to 1000.
That is, the depth of the parse tree is required to be ≤ 1000.
Regexps that require deeper parse trees will return ErrInternalError.
A future CL will change the error to ErrInvalidDepth,
but using ErrInternalError for now avoids introducing new API
in point releases when this is backported.

Fixes #51112.

Change-Id: I97d2cd82195946eb43a4ea8561f5b95f91fb14c5
Reviewed-on: https://go-review.googlesource.com/c/go/+/384616
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2022-02-10 15:23:05 +00:00
Carlos Amedee
656d3f4401 doc/go1.18: remove some TODOs for changes we aren't mentioning again
These TODOs were originally removed in CL 368794.

Updates #47694

Change-Id: I39d5c0ce5f96adbbc466585a5831f721057dbed5
Reviewed-on: https://go-review.googlesource.com/c/go/+/384619
Trust: Carlos Amedee <carlos@golang.org>
Run-TryBot: Carlos Amedee <carlos@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-02-10 01:08:52 +00:00
Michael Anthony Knyszek
2e9dcb5086 runtime: simplify histogram buckets considerably
There was an off-by-one error in the time histogram buckets calculation
that caused the linear sub-buckets distances to be off by 2x.

The fix was trivial, but in writing tests I realized there was a much
simpler way to express the calculation for the histogram buckets, and
took the opportunity to do that here. The new bucket calculation also
fixes the bug.

Fixes #50732.

Change-Id: Idae89986de1c415ee4e148f778e0e101ca003ade
Reviewed-on: https://go-review.googlesource.com/c/go/+/380094
Reviewed-by: Michael Pratt <mpratt@google.com>
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
Trust: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Michael Knyszek <mknyszek@google.com>
2022-02-10 00:07:14 +00:00
Robert Griesemer
2bf5ae0c28 go/types, types2: rename structuralType/String to coreType/String
This is a pure rename of the respective Go functions/methods
with corresponding adjustments to error messages and tests.
A couple of comments were manually rephrased.

With this change, the implementation and error messages match
the latest spec.

No functionality change.

Change-Id: Iaa92a08b64756356fb2c5abdaca5c943c9105c96
Reviewed-on: https://go-review.googlesource.com/c/go/+/384618
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-02-09 22:58:35 +00:00
Tamir Duberstein
ea3c546e9e syscall: use RLIMIT_CPU instead of RLIMIT_NOFILE
The latter is subject to kern.maxfilelimit restrictions on darwin which
are not reflected in the return value. This makes it difficult to
reliably restore the default after the test is complete. RLIMIT_CPU
should hopefully sidestep this problem.

Updates #40564.

Change-Id: Ifb33c7d46f2708130cef366dc245c643a2d5e465
Reviewed-on: https://go-review.googlesource.com/c/go/+/383234
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Trust: Bryan Mills <bcmills@google.com>
2022-02-09 22:06:20 +00:00
Robert Griesemer
2e2ef31778 go/types, types2: better error messages for append
For #49735.

Change-Id: Ib7343061dca0e8d848e0719d39be0393d7cfad93
Reviewed-on: https://go-review.googlesource.com/c/go/+/384615
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-02-09 21:52:21 +00:00
Robert Griesemer
9867262dfd spec: document behavior of generic type switch cases
Fixes #51110.

Change-Id: I11370417f1ef435b05dfab18eeabc2c3c1b7b8a1
Reviewed-on: https://go-review.googlesource.com/c/go/+/384674
Trust: Robert Griesemer <gri@golang.org>
Trust: Dan Scales <danscales@google.com>
Reviewed-by: Dan Scales <danscales@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2022-02-09 21:51:54 +00:00
Robert Griesemer
20c300bc70 spec: the type of a constant cannot be a type parameter
Add corresponding rules and a couple of examples.

Fixes #50202.

Change-Id: I4287b5e2d0fd29a0c871795e07f1bb529c9c6004
Reviewed-on: https://go-review.googlesource.com/c/go/+/384240
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2022-02-09 21:50:10 +00:00
Robert Griesemer
5d3476c3db spec: use "core type" rather than "structural type"
This change in terminology prevents potential confusion
that migth be caused by associating "structural type"
with "structural typing"; the two are not connected.

Also, adjusted introductory paragraph of section on
constraint type inference: type inference goes in both
directions, from type parameter to core type and vice
versa. The previous description was not quite accurate.

Change-Id: If4ca300f525eea660f68486302619aa6ad5dbc2c
Reviewed-on: https://go-review.googlesource.com/c/go/+/384238
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2022-02-09 21:50:07 +00:00
Eric Lagergren
9ed0d81fb5 crypto/aes: fix key size typo
AES-196 does not exist, but AES-192 does.

Signed-off-by: Eric Lagergren <eric@ericlagergren.com>
Change-Id: I8c9ac67735e99e5b2ee7fb9824029c1164221153
Reviewed-on: https://go-review.googlesource.com/c/go/+/384374
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Cherry Mui <cherryyz@google.com>
2022-02-09 21:39:49 +00:00
Carlos Amedee
a3aed62512 doc/go1.18: update Go 1.18 release note TODOs using relnote
For #47694.

Change-Id: I5f6850e171f574a5342671778df854dc68a5148f
Reviewed-on: https://go-review.googlesource.com/c/go/+/384554
Trust: Carlos Amedee <carlos@golang.org>
Run-TryBot: Carlos Amedee <carlos@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Alex Rakoczy <alex@golang.org>
Trust: Alex Rakoczy <alex@golang.org>
Run-TryBot: Alex Rakoczy <alex@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-02-09 21:15:07 +00:00
Bryan C. Mills
846c06d33b net: fix a race in TestLookupContextCancel
If the actual DNS lookup in LookupIPAddr completes quickly enough,
it may succeed even if the passed-in Context is already canceled.
That would (rarely) cause TestLookupContextCancel to fail due to an
unexpectedly-nil error.

This change uses the existing testHookLookupIP hook to delay the
cancellation until the lookup has started (to try to provoke the code
path for which the test was added), and then block the lookup result
until LookupIPAddr has noticed it.

Fixes #51084
Updates #22724

Change-Id: I331ac61a652ac88f6d4c85bf62466237b76d53ed
Reviewed-on: https://go-review.googlesource.com/c/go/+/384237
Trust: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2022-02-09 20:12:16 +00:00
Bryan C. Mills
9cec77ac11 runtime/debug: replace (*BuildInfo).Marshal methods with Parse and String
Since a String method cannot return an error, escape fields that may
contain unsanitized values, and unescape them during parsing.

Add a fuzz test to verify that calling the String method on any
BuildInfo returned by Parse produces a string that parses to the same
BuildInfo. (Note that this doesn't ensure that String always produces
a parseable input: we assume that a user constructing a BuildInfo
provides valid paths and versions, so we don't bother to escape those.
It also doesn't ensure that ParseBuildInfo accepts all inputs that
ought to be valid.)

Fixes #51026

Change-Id: Ida18010ce47622cfedb1494060f32bd7705df014
Reviewed-on: https://go-review.googlesource.com/c/go/+/384154
Trust: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
2022-02-09 19:44:03 +00:00
Meng Zhuo
be0d049a42 runtime: AES maphash scramble 3 times on 386
Issue #43130 shows flaky hash not inbalanced on 386 platform,
which is using AES hashing instead of wyhash.
This CL increase the scramble times to 3 that amd64 using right now.

Fixes #43130

Change-Id: I9d012eda99ff71c13a89448f46fcb9c5e7cec921
Reviewed-on: https://go-review.googlesource.com/c/go/+/384075
Trust: mzh <mzh@golangcn.org>
Run-TryBot: mzh <mzh@golangcn.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2022-02-09 06:35:15 +00:00
Robert Griesemer
255acb0c05 doc/go1.18: document behavior of go/types predicates for extended interfaces
For #47694.

Change-Id: Ic27193b65ef4b3c0c932107b8731b5f8d3190ad5
Reviewed-on: https://go-review.googlesource.com/c/go/+/383918
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2022-02-09 05:39:47 +00:00
Cherry Mui
e4ca3fa345 cmd/dist: test cgo internal linking on darwin-arm64
CL 383554 disables testing cgo internal linking on all ARM64 but
Windows, because it doesn't work with newer GCC. But
- darwin-arm64 works, and it does not use GCC
- we don't support cgo internal linking on windows-arm64 anyway.

This CL fixes the condition.

Change-Id: I9eb7b81ef75e482f5e95d2edae4863ba21396432
Reviewed-on: https://go-review.googlesource.com/c/go/+/384269
Trust: Cherry Mui <cherryyz@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2022-02-08 23:46:01 +00:00
Sean Liao
6749dd40b3 net/smtp: match actual behavior for Auth.Start
Looking at history, it appears to never have worked as documented.

Fixes #48759

Change-Id: I066307c28e3ed1875c1c4049bade62e2818dd400
Reviewed-on: https://go-review.googlesource.com/c/go/+/383998
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Cherry Mui <cherryyz@google.com>
2022-02-08 23:39:48 +00:00
Adrian Hesketh
0b7e586e48 os: add examples for Mkdir and MkdirAll
Provides example using value for the perm argument that matches the value set by the mkdir command on MacOS and Linux.

Change-Id: I98d9ac9668de4dc0efde2484f5b00d005628ac9e
GitHub-Last-Rev: 44e617912f
GitHub-Pull-Request: golang/go#50641
Reviewed-on: https://go-review.googlesource.com/c/go/+/378874
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Cherry Mui <cherryyz@google.com>
2022-02-08 23:38:05 +00:00
Robert Griesemer
c5bce7445e go/types, types2: AssertableTo is undefined for generalized interfaces
Document that AssertableTo is undefined (at least for 1.18) if
the first argument is a generalized interface; i.e., an interface
that may only be used as a constraint in Go code.

Still, implement it as we might expect it to be defined in the
future, to prevent problems down the road due to Hyrum's Law.

While at it, also removed the internal flag forceStrict and its
one use in Checker.assertableTo; forceStrict was never enabled
and if it would have been enabled, the behavior would not have
been correct.

Change-Id: Ie4dc9345c88d04c9640f881132154a002db22643
Reviewed-on: https://go-review.googlesource.com/c/go/+/383917
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-02-08 23:29:18 +00:00
Cherry Mui
0cbe3e00d8 runtime: fix an error message in TestCrashDumpsAllThreads
Change-Id: I04962c836fd448378b8bf071ba848f3b24253dce
Reviewed-on: https://go-review.googlesource.com/c/go/+/384159
Trust: Cherry Mui <cherryyz@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-02-08 22:39:05 +00:00
Ian Lance Taylor
5442f4d51b runtime: restore old mp.fastrand initialization
CL 337350 changed mp.fastrand from a [2]uint32 to a uint64 and changed
the initialization to a single call of int64Hash. However, int64Hash
returns uintptr, so 32-bit systems this always left the most
significant 32 bits of mp.fastrand initialized to 0. The new code also
did not protect against initializing mp.fastrand to 0, which on a
system that does not implement math.Mul64 (most 32-bit systems) would
lead fastrand to always return 0.

This CL restores the mp.fastrand initialization to what it was before
CL 337350, adjusted for the change from [2]uint32 to uint64.

Change-Id: I663b415d9424d967e8e665ce2d017604dcd5b204
Reviewed-on: https://go-review.googlesource.com/c/go/+/383916
Trust: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-02-08 22:26:40 +00:00
Ian Lance Taylor
540632841e bytes, strings: mention Cut in docs for Split and SplitN
For #46336

Change-Id: Idc23302085e14e24d571f5995d6d33ca964a0021
Reviewed-on: https://go-review.googlesource.com/c/go/+/382954
Trust: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
2022-02-08 22:25:54 +00:00