aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitri Shuralyov <dmitshur@golang.org>2024-01-08 15:05:45 -0500
committerDmitri Shuralyov <dmitshur@golang.org>2024-01-08 15:05:46 -0500
commit66f8e1e817777976c764ee857898a5acb44a8c31 (patch)
tree3fcb35b555ddccbeea276739974aa5042cab1219
parentfa72f3e034fdabc5922ac019281f53ea0a8328cf (diff)
parent8eaa7935db8c8b901f4dbb7d224a347bb3c33d7f (diff)
downloadgo-66f8e1e817777976c764ee857898a5acb44a8c31.tar.gz
go-66f8e1e817777976c764ee857898a5acb44a8c31.zip
[release-branch.go1.22] all: merge master (8eaa793) into release-branch.go1.22
Merge List: + 2024-01-08 8eaa7935db net: clarify maxListenerBacklog windows implementation + 2024-01-08 759849187f log/slog: clarify SetDefault behavior + 2024-01-08 10a66d6816 sync: use map[any]any instead of map[interface{}]interface{} in the godoc + 2024-01-08 881869dde0 cmd/compile: handle defined iter func type correctly + 2024-01-05 1ae729e6d3 doc: s/adjustements/adjustments + 2024-01-05 8088b6db23 slices: explicitly discard results of some functions + 2024-01-05 c0693f648a cmd/go: run cover tool before swig + 2024-01-04 8db131082d github: switch seen/expected order in issue forms + 2024-01-04 ead47b0ab3 net/http: respond with 400 Bad Request for empty hex number of chunk length + 2024-01-04 1e07c144c3 net/http/cgi: in TestCopyError, check for a Handler.ServeHTTP goroutine instead of a running PID + 2024-01-04 15dcdeb5aa cmd/api: fix panic on exported basic type aliases + 2024-01-03 6db1102605 pagetrace: fix build when experiment is on + 2024-01-03 7d1b82dbf1 net/http: make Request.Clone create fresh copies for matches and otherValues + 2024-01-03 aa0a6ad1db doc/go1.22: add links to go/types symbols + 2024-01-03 c95fe91d07 runtime: correct scavengeIndex.sysGrow min index handling + 2023-12-30 b25f5558c6 all: replace outdated links + 2023-12-30 3233542e85 reflect: fix typo in type.go + 2023-12-27 988b718f41 doc: fix typo in example in spec + 2023-12-27 26ba75fe59 doc: document new iteration variable semantics in spec + 2023-12-27 1dddd83c49 doc: document version at which new language features were introduced in spec + 2023-12-26 36a2463e7c lib/time: update to 2023d/2023d + 2023-12-21 2184a39477 runtime/metrics: godoc link fixes + 2023-12-21 9c01ecce48 doc: fix misspelling in go1.22 release notes + 2023-12-21 0b56804084 runtime: use racereleasemerge for godebugInc + 2023-12-21 f6509cf5cd cmd/compile: handle constant-folding of an out-of-range jump table index + 2023-12-20 adec22b9f7 doc/go1.22: document changes to vet loopclosure analyzer + 2023-12-20 a2a2c5b947 doc: update unsafe.Pointer rule in spec + 2023-12-19 35222eeb78 doc: add html/template release note Change-Id: I0709455dc512c94d2cbdb15c10d5c91f4bdaaa71
-rw-r--r--.github/ISSUE_TEMPLATE/00-bug.yml15
-rw-r--r--.github/ISSUE_TEMPLATE/01-pkgsite.yml8
-rw-r--r--.github/ISSUE_TEMPLATE/02-pkgsite-removal.yml19
-rw-r--r--.github/ISSUE_TEMPLATE/03-gopls.yml10
-rw-r--r--.github/ISSUE_TEMPLATE/04-vuln.yml14
-rw-r--r--doc/go1.22.html56
-rw-r--r--doc/go_spec.html278
-rwxr-xr-xlib/time/update.bash4
-rw-r--r--lib/time/zoneinfo.zipbin400280 -> 401728 bytes
-rw-r--r--src/cmd/api/api_test.go19
-rw-r--r--src/cmd/api/main_test.go10
-rw-r--r--src/cmd/api/testdata/src/issue64958/p/p.go3
-rw-r--r--src/cmd/compile/internal/rangefunc/rewrite.go2
-rw-r--r--src/cmd/compile/internal/ssa/sccp.go7
-rw-r--r--src/cmd/go/internal/work/exec.go29
-rw-r--r--src/cmd/go/testdata/script/cover_swig.txt72
-rw-r--r--src/debug/elf/elf.go2
-rw-r--r--src/log/slog/logger.go3
-rw-r--r--src/net/http/cgi/host_test.go56
-rw-r--r--src/net/http/cgi/plan9_test.go17
-rw-r--r--src/net/http/cgi/posix_test.go20
-rw-r--r--src/net/http/internal/chunked.go3
-rw-r--r--src/net/http/internal/chunked_test.go1
-rw-r--r--src/net/http/request.go16
-rw-r--r--src/net/http/request_test.go27
-rw-r--r--src/net/sock_windows.go5
-rw-r--r--src/reflect/type.go2
-rw-r--r--src/runtime/metrics/doc.go5
-rw-r--r--src/runtime/mpagealloc_64bit.go23
-rw-r--r--src/runtime/pagetrace_on.go2
-rw-r--r--src/runtime/pprof/pprof.go2
-rw-r--r--src/runtime/runtime.go5
-rw-r--r--src/runtime/runtime2.go2
-rw-r--r--src/runtime/trace2status.go1
-rw-r--r--src/slices/slices_test.go12
-rw-r--r--src/sync/map.go2
-rw-r--r--test/fixedbugs/issue64826.go38
-rw-r--r--test/range4.go25
38 files changed, 619 insertions, 196 deletions
diff --git a/.github/ISSUE_TEMPLATE/00-bug.yml b/.github/ISSUE_TEMPLATE/00-bug.yml
index f3997ec3c1..5b0fda4950 100644
--- a/.github/ISSUE_TEMPLATE/00-bug.yml
+++ b/.github/ISSUE_TEMPLATE/00-bug.yml
@@ -23,9 +23,9 @@ body:
required: true
- type: textarea
- id: os-and-processor
+ id: go-env
attributes:
- label: "What operating system and processor architecture are you using (`go env`)?"
+ label: "Output of `go env` in your module/workspace:"
placeholder: |
GO111MODULE=""
GOARCH="arm64"
@@ -78,16 +78,17 @@ body:
required: true
- type: textarea
- id: expected-behavior
+ id: actual-behavior
attributes:
- label: "What did you expect to see?"
+ label: "What did you see happen?"
+ description: Command invocations and their associated output, functions with their arguments and return results, full stacktraces for panics (upload a file if it is very long), etc. Prefer copying text output over using screenshots.
validations:
required: true
- type: textarea
- id: actual-behavior
+ id: expected-behavior
attributes:
- label: "What did you see instead?"
+ label: "What did you expect to see?"
+ description: Why is the current output incorrect, and any additional context we may need to understand the issue.
validations:
required: true
-
diff --git a/.github/ISSUE_TEMPLATE/01-pkgsite.yml b/.github/ISSUE_TEMPLATE/01-pkgsite.yml
index fb695857c7..aaf39b2928 100644
--- a/.github/ISSUE_TEMPLATE/01-pkgsite.yml
+++ b/.github/ISSUE_TEMPLATE/01-pkgsite.yml
@@ -34,14 +34,14 @@ body:
validations:
required: true
- type: textarea
- id: expected-behavior
+ id: actual-behavior
attributes:
- label: "What did you expect to see?"
+ label: "What did you see happen?"
validations:
required: true
- type: textarea
- id: actual-behavior
+ id: expected-behavior
attributes:
- label: "What did you see instead?"
+ label: "What did you expect to see?"
validations:
required: true
diff --git a/.github/ISSUE_TEMPLATE/02-pkgsite-removal.yml b/.github/ISSUE_TEMPLATE/02-pkgsite-removal.yml
index 71d0a19d71..693f4999dc 100644
--- a/.github/ISSUE_TEMPLATE/02-pkgsite-removal.yml
+++ b/.github/ISSUE_TEMPLATE/02-pkgsite-removal.yml
@@ -10,20 +10,33 @@ body:
id: package-path
attributes:
label: "What is the path of the package that you would like to have removed?"
- description: "We can remove packages with a shared path prefix. For example, a request for 'github.com/author' would remove all pkg.go.dev pages with that package path prefix."
+ description: |
+ We can remove packages with a shared path prefix.
+ For example, a request for 'github.com/author' would remove all pkg.go.dev pages with that package path prefix.
validations:
required: true
- type: textarea
id: package-owner
attributes:
label: "Are you the owner of this package?"
- description: "Only the package owners can request to have their packages removed from pkg.go.dev."
+ description: |
+ Only the package owners can request to have their packages removed from pkg.go.dev.
+ If the package path doesn't include your github username, please provide some other form of proof of ownership.
validations:
required: true
- type: textarea
id: retraction-reason
attributes:
label: "What is the reason that you could not retract this package instead?"
- description: "If you would like to have your module removed from pkg.go.dev, we recommend that you retract them, so that they can be removed from the go command and proxy.golang.org as well. Retracting a module version involves adding a retract directive to your go.mod file and publishing a new version. For example: https://github.com/jba/retract-demo/blob/main/go.mod#L5-L8. See https://pkg.go.dev/about#removing-a-package for additional tips on retractions."
+ description: |
+ Requesting we remove a module here only hides the generated documentation on pkg.go.dev.
+ It does not affect the behaviour of proxy.golang.org or the go command.
+ Instead we recommend using the retract directive which will be processed by all 3 of the above.
+
+ If you have deleted your repo, please recreate it and publish a retraction.
+
+ Retracting a module version involves adding a retract directive to your go.mod file and publishing a new version.
+ For example: https://github.com/jba/retract-demo/blob/main/go.mod#L5-L8.
+ See https://pkg.go.dev/about#removing-a-package for additional tips on retractions.
validations:
required: true
diff --git a/.github/ISSUE_TEMPLATE/03-gopls.yml b/.github/ISSUE_TEMPLATE/03-gopls.yml
index 83759d65d8..5db1315f27 100644
--- a/.github/ISSUE_TEMPLATE/03-gopls.yml
+++ b/.github/ISSUE_TEMPLATE/03-gopls.yml
@@ -25,19 +25,19 @@ body:
id: what-did-you-do
attributes:
label: "What did you do?"
- description: "If possible, provide a recipe for reproducing the error. A complete runnable program is good. A link on go.dev/play is better. A failing unit test is the best."
+ description: "If possible, provide a recipe for reproducing the error. A complete runnable program is good. A link on [go.dev/play](https://go.dev/play) is better. A failing unit test is the best."
validations:
required: true
- type: textarea
- id: expected-behavior
+ id: actual-behavior
attributes:
- label: "What did you expect to see?"
+ label: "What did you see happen?"
validations:
required: true
- type: textarea
- id: actual-behavior
+ id: expected-behavior
attributes:
- label: "What did you see instead?"
+ label: "What did you expect to see?"
validations:
required: true
- type: textarea
diff --git a/.github/ISSUE_TEMPLATE/04-vuln.yml b/.github/ISSUE_TEMPLATE/04-vuln.yml
index ae1356886c..dd40af99c6 100644
--- a/.github/ISSUE_TEMPLATE/04-vuln.yml
+++ b/.github/ISSUE_TEMPLATE/04-vuln.yml
@@ -6,7 +6,7 @@ body:
- type: markdown
attributes:
value: "Please answer these questions before submitting your issue. Thanks! To add a new vulnerability to the Go vulnerability database (https://vuln.go.dev), see https://go.dev/s/vulndb-report-new. To report an issue about a report, see https://go.dev/s/vulndb-report-feedback."
- - type: input
+ - type: textarea
id: govulncheck-version
attributes:
label: govulncheck version
@@ -25,9 +25,9 @@ body:
validations:
required: true
- type: textarea
- id: os-and-processor
+ id: go-env
attributes:
- label: "What operating system and processor architecture are you using (`go env`)?"
+ label: "Output of `go env` in your module/workspace:"
render: shell
validations:
required: true
@@ -39,14 +39,14 @@ body:
validations:
required: true
- type: textarea
- id: expected-behavior
+ id: actual-behavior
attributes:
- label: "What did you expect to see?"
+ label: "What did you see happen?"
validations:
required: true
- type: textarea
- id: actual-behavior
+ id: expected-behavior
attributes:
- label: "What did you see instead?"
+ label: "What did you expect to see?"
validations:
required: true
diff --git a/doc/go1.22.html b/doc/go1.22.html
index d265541a59..44d783e1bd 100644
--- a/doc/go1.22.html
+++ b/doc/go1.22.html
@@ -136,9 +136,20 @@ packages that do not have their own test files. Prior to Go 1.22 a
<h3 id="vet">Vet</h3>
-<!-- <p><\!-- CL 539016 -\-> -->
-<!-- TODO: <a href="https://go.dev/cl/539016">https://go.dev/cl/539016</a>: go/analysis/passes/loopclosure: disable checker after go1.22.; loopclosure was modified to only not report in files with GoVersion after 1.22. -->
-<!-- </p> -->
+<h4 id="vet-loopclosure">References to loop variables</h4>
+
+<p><!-- CL 539016, https://go.dev/issue/63888: cmd/vet: do not report variable capture for loop variables with the new lifetime rules -->
+ The behavior of the <code>vet</code> tool has changed to match
+ the new semantics (see above) of loop variables in Go 1.22.
+ When analyzing a file that requires Go 1.22 or newer
+ (due to its go.mod file or a per-file build constraint),
+ <code>vet</code>code> no longer reports references to
+ loop variables from within a function literal that
+ might outlive the iteration of the loop.
+ In Go 1.22, loop variables are created anew for each iteration,
+ so such references are no longer at risk of using a variable
+ after it has been updated by the loop.
+</p>
<h4 id="vet-appends">New warnings for missing values after append</h4>
@@ -393,7 +404,7 @@ We plan to include an API migration tool in a future release, likely Go 1.23.
</p>
<p>
- This change breaks backwards compatiblity in small ways, some obvious&mdash;patterns with "{" and "}" behave differently&mdash;
+ This change breaks backwards compatibility in small ways, some obvious&mdash;patterns with "{" and "}" behave differently&mdash;
and some less so&mdash;treatment of escaped paths has been improved.
The change is controlled by a <a href="/doc/godebug"><code>GODEBUG</code></a> field named <code>httpmuxgo121</code>.
Set <code>httpmuxgo121=1</code> to restore the old behavior.
@@ -566,18 +577,17 @@ We plan to include an API migration tool in a future release, likely Go 1.23.
<code>Importer</code>,
<code>Package</code>,
<code>NewPackage</code>.
- </p>
- <p>
- Identifiers cannot be accurately resolved without type information.
+
+ In general, identifiers cannot be accurately resolved without type information.
Consider, for example, the identifier <code>K</code>
in <code>T{K: ""}</code>: it could be the name of a local variable
if T is a map type, or the name of a field if T is a struct type.
- </p>
- <p>
+
New programs should use the <a href='/pkg/go/types'>go/types</a>
- package to resolve identifiers;
- see <code>Object</code>, <code>Info.Uses</code>,
- and <code>Info.Defs</code> for details.
+ package to resolve identifiers; see
+ <a href='https://pkg.go.dev/go/types#Object'><code>Object</code></a>,
+ <a href='https://pkg.go.dev/go/types#Info.Uses'><code>Info.Uses</code></a>, and
+ <a href='https://pkg.go.dev/go/types#Info.Defs'><code>Info.Defs</code></a> for details.
</p>
<p><!-- https://go.dev/issue/60061 -->
@@ -650,17 +660,15 @@ We plan to include an API migration tool in a future release, likely Go 1.23.
</dd>
</dl><!-- go/version -->
-<!-- <dl id="html/template"><dt><a href="/pkg/html/template/">html/template</a></dt> -->
-<!-- <dd> -->
-<!-- <p><\!-- https://go.dev/issue/61619 -\-> -->
-<!-- TODO: <a href="https://go.dev/issue/61619">https://go.dev/issue/61619</a>: allow actions in JS template literals -->
-<!-- </p> -->
-
-<!-- <p><\!-- CL 507995 -\-> -->
-<!-- TODO: <a href="https://go.dev/cl/507995">https://go.dev/cl/507995</a>: html/template: support parsing complex JS template literals; modified api/next/61619.txt -->
-<!-- </p> -->
-<!-- </dd> -->
-<!-- </dl><\!-- html/template -\-> -->
+<dl id="html/template"><dt><a href="/pkg/html/template/">html/template</a></dt>
+ <dd>
+ <p><!-- https://go.dev/issue/61619, CL 507995 -->
+ Javascript template literals may now contain Go template actions, and parsing a template containing one will
+ no longer return <code>ErrJSTemplate</code>. Similarly the GODEBUG setting <code>jstmpllitinterp</code> no
+ longer has any effect.
+ </p>
+ </dd>
+</dl><!-- html/template -->
<dl id="io"><dt><a href="/pkg/io/">io</a></dt>
<dd>
@@ -943,7 +951,7 @@ We plan to include an API migration tool in a future release, likely Go 1.23.
<p><!-- https://go.dev/issue/60797 -->
The <code>syscall</code> package has been <a href="https://golang.org/s/go1.4-syscall">frozen</a> since Go 1.4 and was marked as deprecated in Go 1.11, causing many editors to warn about any use of the package.
However, some non-deprecated functionality requires use of the <code>syscall</code> package, such as the <a href="/pkg/os/exec#Cmd"><code>os/exec.Cmd.SysProcAttr</code></a> field.
- To avoid unnecesary complaints on such code, the <code>syscall</code> package is no longer marked as deprecated.
+ To avoid unnecessary complaints on such code, the <code>syscall</code> package is no longer marked as deprecated.
The package remains frozen to most new functionality, and new code remains encouraged to use <a href="/pkg/golang.org/x/sys/unix"><code>golang.org/x/sys/unix</code></a> or <a href="/pkg/golang.org/x/sys/windows"><code>golang.org/x/sys/windows</code></a> where possible.
</p>
diff --git a/doc/go_spec.html b/doc/go_spec.html
index f68441e664..bd974b3c48 100644
--- a/doc/go_spec.html
+++ b/doc/go_spec.html
@@ -1,6 +1,6 @@
<!--{
"Title": "The Go Programming Language Specification",
- "Subtitle": "Version of Nov 1, 2023",
+ "Subtitle": "Version of Dec 27, 2023",
"Path": "/ref/spec"
}-->
@@ -70,6 +70,14 @@ enumerations or code snippets that are not further specified. The character <cod
language.
</p>
+<p>
+A link of the form [<a href="#Language_versions">Go 1.xx</a>] indicates that a described
+language feature (or some aspect of it) was changed or added with language version 1.xx and
+thus requires at minimum that language version to build.
+For details, see the <a href="#Language_versions">linked section</a>
+in the <a href="#Appendix">appendix</a>.
+</p>
+
<h2 id="Source_code_representation">Source code representation</h2>
<p>
@@ -263,7 +271,8 @@ continue for import return var
<p>
The following character sequences represent <a href="#Operators">operators</a>
-(including <a href="#Assignment_statements">assignment operators</a>) and punctuation:
+(including <a href="#Assignment_statements">assignment operators</a>) and punctuation
+[<a href="#Go_1.18">Go 1.18</a>]:
</p>
<pre class="grammar">
+ &amp; += &amp;= &amp;&amp; == != ( )
@@ -281,7 +290,8 @@ An integer literal is a sequence of digits representing an
<a href="#Constants">integer constant</a>.
An optional prefix sets a non-decimal base: <code>0b</code> or <code>0B</code>
for binary, <code>0</code>, <code>0o</code>, or <code>0O</code> for octal,
-and <code>0x</code> or <code>0X</code> for hexadecimal.
+and <code>0x</code> or <code>0X</code> for hexadecimal
+[<a href="#Go_1.13">Go 1.13</a>].
A single <code>0</code> is considered a decimal zero.
In hexadecimal literals, letters <code>a</code> through <code>f</code>
and <code>A</code> through <code>F</code> represent values 10 through 15.
@@ -347,7 +357,8 @@ prefix, an integer part (hexadecimal digits), a radix point, a fractional part (
and an exponent part (<code>p</code> or <code>P</code> followed by an optional sign and decimal digits).
One of the integer part or the fractional part may be elided; the radix point may be elided as well,
but the exponent part is required. (This syntax matches the one given in IEEE 754-2008 §5.12.3.)
-An exponent value exp scales the mantissa (integer and fractional part) by 2<sup>exp</sup>.
+An exponent value exp scales the mantissa (integer and fractional part) by 2<sup>exp</sup>
+[<a href="#Go_1.13">Go 1.13</a>].
</p>
<p>
@@ -411,7 +422,8 @@ It consists of an <a href="#Integer_literals">integer</a> or
<a href="#Floating-point_literals">floating-point</a> literal
followed by the lowercase letter <code>i</code>.
The value of an imaginary literal is the value of the respective
-integer or floating-point literal multiplied by the imaginary unit <i>i</i>.
+integer or floating-point literal multiplied by the imaginary unit <i>i</i>
+[<a href="#Go_1.13">Go 1.13</a>]
</p>
<pre class="ebnf">
@@ -1340,6 +1352,7 @@ interface{}
<p>
For convenience, the predeclared type <code>any</code> is an alias for the empty interface.
+[<a href="#Go_1.18">Go 1.18</a>]
</p>
<p>
@@ -1375,13 +1388,15 @@ as the <code>File</code> interface.
In a slightly more general form
an interface <code>T</code> may use a (possibly qualified) interface type
name <code>E</code> as an interface element. This is called
-<i>embedding</i> interface <code>E</code> in <code>T</code>.
+<i>embedding</i> interface <code>E</code> in <code>T</code>
+[<a href="#Go_1.14">Go 1.14</a>].
The type set of <code>T</code> is the <i>intersection</i> of the type sets
defined by <code>T</code>'s explicitly declared methods and the type sets
of <code>T</code>’s embedded interfaces.
In other words, the type set of <code>T</code> is the set of all types that implement all the
explicitly declared methods of <code>T</code> and also all the methods of
-<code>E</code>.
+<code>E</code>
+[<a href="#Go_1.18">Go 1.18</a>].
</p>
<pre>
@@ -1420,7 +1435,8 @@ type ReadCloser interface {
<p>
In their most general form, an interface element may also be an arbitrary type term
<code>T</code>, or a term of the form <code>~T</code> specifying the underlying type <code>T</code>,
-or a union of terms <code>t<sub>1</sub>|t<sub>2</sub>|…|t<sub>n</sub></code>.
+or a union of terms <code>t<sub>1</sub>|t<sub>2</sub>|…|t<sub>n</sub></code>
+[<a href="#Go_1.18">Go 1.18</a>].
Together with method specifications, these elements enable the precise
definition of an interface's type set as follows:
</p>
@@ -2303,7 +2319,9 @@ as an <a href="#Operands">operand</a>, and in <a href="#Assignment_statements">a
<p>
The following identifiers are implicitly declared in the
-<a href="#Blocks">universe block</a>:
+<a href="#Blocks">universe block</a>
+[<a href="#Go_1.18">Go 1.18</a>]
+[<a href="#Go_1.21">Go 1.21</a>]:
</p>
<pre class="grammar">
Types:
@@ -2487,7 +2505,8 @@ TypeSpec = AliasDecl | TypeDef .
<h4 id="Alias_declarations">Alias declarations</h4>
<p>
-An alias declaration binds an identifier to the given type.
+An alias declaration binds an identifier to the given type
+[<a href="#Go_1.9">Go 1.9</a>].
</p>
<pre class="ebnf">
@@ -2636,7 +2655,8 @@ func (l *List[T]) Len() int { … }
A type parameter list declares the <i>type parameters</i> of a generic function or type declaration.
The type parameter list looks like an ordinary <a href="#Function_types">function parameter list</a>
except that the type parameter names must all be present and the list is enclosed
-in square brackets rather than parentheses.
+in square brackets rather than parentheses
+[<a href="#Go_1.18">Go 1.18</a>].
</p>
<pre class="ebnf">
@@ -2719,7 +2739,8 @@ type T6[P int] struct{ f *T6[P] } // ok: reference to T6 is not in type para
<p>
A <i>type constraint</i> is an <a href="#Interface_types">interface</a> that defines the
set of permissible type arguments for the respective type parameter and controls the
-operations supported by values of that type parameter.
+operations supported by values of that type parameter
+[<a href="#Go_1.18">Go 1.18</a>].
</p>
<pre class="ebnf">
@@ -2749,7 +2770,8 @@ other interfaces based on their type sets. But this should get us going for now.
The <a href="#Predeclared_identifiers">predeclared</a>
<a href="#Interface_types">interface type</a> <code>comparable</code>
denotes the set of all non-interface types that are
-<a href="#Comparison_operators">strictly comparable</a>.
+<a href="#Comparison_operators">strictly comparable</a>
+[<a href="#Go_1.18">Go 1.18</a>].
</p>
<p>
@@ -2782,7 +2804,8 @@ if <code>T</code> is an element of the type set defined by <code>C</code>; i.e.,
if <code>T</code> <a href="#Implementing_an_interface">implements</a> <code>C</code>.
As an exception, a <a href="#Comparison_operators">strictly comparable</a>
type constraint may also be satisfied by a <a href="#Comparison_operators">comparable</a>
-(not necessarily strictly comparable) type argument.
+(not necessarily strictly comparable) type argument
+[<a href="#Go_1.20">Go 1.20</a>].
More precisely:
</p>
@@ -4306,7 +4329,7 @@ with the same underlying array.
<p>
A generic function or type is <i>instantiated</i> by substituting <i>type arguments</i>
-for the type parameters.
+for the type parameters [<a href="#Go_1.18">Go 1.18</a>].
Instantiation proceeds in two steps:
</p>
@@ -4759,6 +4782,7 @@ to the type of the other operand.
<p>
The right operand in a shift expression must have <a href="#Numeric_types">integer type</a>
+[<a href="#Go_1.13">Go 1.13</a>]
or be an untyped constant <a href="#Representability">representable</a> by a
value of type <code>uint</code>.
If the left operand of a non-constant shift expression is an untyped constant,
@@ -5426,7 +5450,8 @@ in any of these cases:
<code>x</code> is a string and <code>T</code> is a slice of bytes or runes.
</li>
<li>
- <code>x</code> is a slice, <code>T</code> is an array or a pointer to an array,
+ <code>x</code> is a slice, <code>T</code> is an array [<a href="#Go_1.20">Go 1.20</a>]
+ or a pointer to an array [<a href="#Go_1.17">Go 1.17</a>],
and the slice and array types have <a href="#Type_identity">identical</a> element types.
</li>
</ul>
@@ -6516,7 +6541,6 @@ additionally it may specify an <i>init</i>
and a <i>post</i> statement, such as an assignment,
an increment or decrement statement. The init statement may be a
<a href="#Short_variable_declarations">short variable declaration</a>, but the post statement must not.
-Variables declared by the init statement are re-used in each iteration.
</p>
<pre class="ebnf">
@@ -6548,12 +6572,54 @@ for cond { S() } is the same as for ; cond ; { S() }
for { S() } is the same as for true { S() }
</pre>
+<p>
+Each iteration has its own separate declared variable (or variables)
+[<a href="#Go_1.22">Go 1.22</a>].
+The variable used by the first iteration is declared by the init statement.
+The variable used by each subsequent iteration is declared implicitly before
+executing the post statement and initialized to the value of the previous
+iteration's variable at that moment.
+</p>
+
+<pre>
+var prints []func()
+for i := 0; i < 5; i++ {
+ prints = append(prints, func() { println(i) })
+ i++
+}
+for _, p := range prints {
+ p()
+}
+</pre>
+
+<p>
+prints
+</p>
+
+<pre>
+1
+3
+5
+</pre>
+
+<p>
+Prior to [<a href="#Go_1.22">Go 1.22</a>], iterations share one set of variables
+instead of having their own separate variables.
+In that case, the example above prints
+</p>
+
+<pre>
+6
+6
+6
+</pre>
+
<h4 id="For_range">For statements with <code>range</code> clause</h4>
<p>
A "for" statement with a "range" clause
iterates through all entries of an array, slice, string or map, values received on
-a channel, or integer values from zero to an upper limit.
+a channel, or integer values from zero to an upper limit [<a href="#Go_1.22">Go 1.22</a>].
For each entry it assigns <i>iteration values</i>
to corresponding <i>iteration variables</i> if present and then executes the block.
</p>
@@ -6652,9 +6718,10 @@ The iteration variables may be declared by the "range" clause using a form of
<a href="#Short_variable_declarations">short variable declaration</a>
(<code>:=</code>).
In this case their types are set to the types of the respective iteration values
-and their <a href="#Declarations_and_scope">scope</a> is the block of the "for"
-statement; they are re-used in each iteration.
-If the iteration variables are declared outside the "for" statement,
+and their <a href="#Declarations_and_scope">scope</a> is the block of the "for" statement;
+each iteration has its own separate variables [<a href="#Go_1.22">Go 1.22</a>]
+(see also <a href="#For_clause">"for" statements with a ForClause</a>).
+If the iteration variables are declared outside the “for” statement,
after execution their values will be those of the last iteration.
</p>
@@ -7249,7 +7316,8 @@ n3 := copy(b, "Hello, World!") // n3 == 5, b is []byte("Hello")
<p>
The built-in function <code>clear</code> takes an argument of <a href="#Map_types">map</a>,
<a href="#Slice_types">slice</a>, or <a href="#Type_parameter_declarations">type parameter</a> type,
-and deletes or zeroes out all elements.
+and deletes or zeroes out all elements
+[<a href="#Go_1.21">Go 1.21</a>].
</p>
<pre class="grammar">
@@ -7516,7 +7584,8 @@ The precise behavior is implementation-dependent.
The built-in functions <code>min</code> and <code>max</code> compute the
smallest&mdash;or largest, respectively&mdash;value of a fixed number of
arguments of <a href="#Comparison_operators">ordered types</a>.
-There must be at least one argument.
+There must be at least one argument
+[<a href="#Go_1.21">Go 1.21</a>].
</p>
<p>
@@ -8232,8 +8301,8 @@ of if the general conversion rules take care of this.
<p>
A <code>Pointer</code> is a <a href="#Pointer_types">pointer type</a> but a <code>Pointer</code>
value may not be <a href="#Address_operators">dereferenced</a>.
-Any pointer or value of <a href="#Underlying_types">underlying type</a> <code>uintptr</code> can be
-<a href="#Conversions">converted</a> to a type of underlying type <code>Pointer</code> and vice versa.
+Any pointer or value of <a href="#Core_types">core type</a> <code>uintptr</code> can be
+<a href="#Conversions">converted</a> to a type of core type <code>Pointer</code> and vice versa.
The effect of converting between <code>Pointer</code> and <code>uintptr</code> is implementation-defined.
</p>
@@ -8244,6 +8313,10 @@ bits = *(*uint64)(unsafe.Pointer(&amp;f))
type ptr unsafe.Pointer
bits = *(*uint64)(ptr(&amp;f))
+func f[P ~*B, B any](p P) uintptr {
+ return uintptr(unsafe.Pointer(p))
+}
+
var p ptr = nil
</pre>
@@ -8292,7 +8365,8 @@ of constant size.
<p>
The function <code>Add</code> adds <code>len</code> to <code>ptr</code>
-and returns the updated pointer <code>unsafe.Pointer(uintptr(ptr) + uintptr(len))</code>.
+and returns the updated pointer <code>unsafe.Pointer(uintptr(ptr) + uintptr(len))</code>
+[<a href="#Go_1.17">Go 1.17</a>].
The <code>len</code> argument must be of <a href="#Numeric_types">integer type</a> or an untyped <a href="#Constants">constant</a>.
A constant <code>len</code> argument must be <a href="#Representability">representable</a> by a value of type <code>int</code>;
if it is an untyped constant it is given type <code>int</code>.
@@ -8312,7 +8386,8 @@ and whose length and capacity are <code>len</code>.
<p>
except that, as a special case, if <code>ptr</code>
is <code>nil</code> and <code>len</code> is zero,
-<code>Slice</code> returns <code>nil</code>.
+<code>Slice</code> returns <code>nil</code>
+[<a href="#Go_1.17">Go 1.17</a>].
</p>
<p>
@@ -8321,14 +8396,16 @@ A constant <code>len</code> argument must be non-negative and <a href="#Represen
if it is an untyped constant it is given type <code>int</code>.
At run time, if <code>len</code> is negative,
or if <code>ptr</code> is <code>nil</code> and <code>len</code> is not zero,
-a <a href="#Run_time_panics">run-time panic</a> occurs.
+a <a href="#Run_time_panics">run-time panic</a> occurs
+[<a href="#Go_1.17">Go 1.17</a>].
</p>
<p>
The function <code>SliceData</code> returns a pointer to the underlying array of the <code>slice</code> argument.
If the slice's capacity <code>cap(slice)</code> is not zero, that pointer is <code>&slice[:1][0]</code>.
If <code>slice</code> is <code>nil</code>, the result is <code>nil</code>.
-Otherwise it is a non-<code>nil</code> pointer to an unspecified memory address.
+Otherwise it is a non-<code>nil</code> pointer to an unspecified memory address
+[<a href="#Go_1.20">Go 1.20</a>].
</p>
<p>
@@ -8337,12 +8414,14 @@ The function <code>String</code> returns a <code>string</code> value whose under
The same requirements apply to the <code>ptr</code> and <code>len</code> argument as in the function
<code>Slice</code>. If <code>len</code> is zero, the result is the empty string <code>""</code>.
Since Go strings are immutable, the bytes passed to <code>String</code> must not be modified afterwards.
+[<a href="#Go_1.20">Go 1.20</a>]
</p>
<p>
The function <code>StringData</code> returns a pointer to the underlying bytes of the <code>str</code> argument.
For an empty string the return value is unspecified, and may be <code>nil</code>.
-Since Go strings are immutable, the bytes returned by <code>StringData</code> must not be modified.
+Since Go strings are immutable, the bytes returned by <code>StringData</code> must not be modified
+[<a href="#Go_1.20">Go 1.20</a>].
</p>
<h3 id="Size_and_alignment_guarantees">Size and alignment guarantees</h3>
@@ -8383,6 +8462,145 @@ A struct or array type has size zero if it contains no fields (or elements, resp
<h2 id="Appendix">Appendix</h2>
+<h3 id="Language_versions">Language versions</h3>
+
+<p>
+The <a href="/doc/go1compat">Go 1 compatibility guarantee</a> ensures that
+programs written to the Go 1 specification will continue to compile and run
+correctly, unchanged, over the lifetime of that specification.
+More generally, as adjustments are made and features added to the language,
+the compatibility guarantee ensures that a Go program that works with a
+specific Go language version will continue to work with any subsequent version.
+</p>
+
+<p>
+For instance, the ability to use the prefix <code>0b</code> for binary
+integer literals was introduced with Go 1.13, indicated
+by [<a href="#Go_1.13">Go 1.13</a>] in the section on
+<a href="#Integer_literals">integer literals</a>.
+Source code containing an integer literal such as <code>0b1011</code>
+will be rejected if the implied or required language version used by
+the compiler is older than Go 1.13.
+</p>
+
+<p>
+The following table describes the minimum language version required for
+features introduced after Go 1.
+</p>
+
+<h4 id="Go_1.9">Go 1.9</h4>
+<ul>
+<li>
+An <a href="#Alias_declarations">alias declaration</a> may be used to declare an alias name for a type.
+</li>
+</ul>
+
+<h4 id="Go_1.13">Go 1.13</h4>
+<ul>
+<li>
+<a href="#Integer_literals">Integer literals</a> may use the prefixes <code>0b</code>, <code>0B</code>, <code>0o</code>,
+and <code>0O</code> for binary, and octal literals, respectively.
+</li>
+<li>
+Hexadecimal <a href="#Floating-point_literals">floating-point literals</a> may be written using the prefixes
+<code>0x</code> and <code>0X</code>.
+</li>
+<li>
+The <a href="#Imaginary_literals">imaginary suffix</a> <code>i</code> may be used with any (binary, decimal, hexadecimal)
+integer or floating-point literal, not just decimal literals.
+</li>
+<li>
+The digits of any number literal may be <a href="#Integer_literals">separated</a> (grouped)
+using underscores <code>_</code>.
+</li>
+<li>
+The shift count in a <a href="#Operators">shift operation</a> may be a signed integer type.
+</li>
+</ul>
+
+<h4 id="Go_1.14">Go 1.14</h4>
+<ul>
+<li>
+Emdedding a method more than once through different <a href="#Embedded_interfaces">embedded interfaces</a>
+is not an error.
+</li>
+</ul>
+
+<h4 id="Go_1.17">Go 1.17</h4>
+<ul>
+<li>
+A slice may be <a href="#Conversions">converted</a> to an array pointer if the slice and array element
+types match, and the array is not longer than the slice.
+</li>
+<li>
+The built-in <a href="#Package_unsafe">package <code>unsafe</code></a> includes the new functions
+<code>Add</code> and <code>Slice</code>.
+</li>
+</ul>
+
+<h4 id="Go_1.18">Go 1.18</h4>
+<p>
+The 1.18 release adds polymorphic functions and types ("generics") to the language.
+Specifically:
+</p>
+<ul>
+<li>
+The set of <a href="#Operators_and_punctuation">operators and punctuation</a> includes the new token <code>~</code>.
+</li>
+<li>
+Function and type declarations may declare <a href="#Type_parameter_declarations">type parameters</a>.
+</li>
+<li>
+Interface types may <a href="#General_interfaces">embed arbitrary types</a> (not just type names of interfaces)
+as well as union and <code>~T</code> type elements.
+</li>
+<li>
+The set of <a href="#Predeclared_identifiers">predeclared</a> types includes the new types
+<code>any</code> and <code>comparable</code>.
+</li>
+</ul>
+
+<h4 id="Go_1.20">Go 1.20</h4>
+<ul>
+<li>
+A slice may be <a href="#Conversions">converted</a> to an array if the slice and array element
+types match and the array is not longer than the slice.
+</li>
+<li>
+The built-in <a href="#Package_unsafe">package <code>unsafe</code></a> includes the new functions
+<code>SliceData</code>, <code>String</code>, and <code>StringData</code>.
+</li>
+<li>
+<a href="#Comparison_operators">Comparable types</a> (such as ordinary interfaces) may satisfy
+<code>comparable</code> constraints, even if the type arguments are not strictly comparable.
+</li>
+</ul>
+
+<h4 id="Go_1.21">Go 1.21</h4>
+<ul>
+<li>
+The set of <a href="#Predeclared_identifiers">predeclared</a> functions includes the new functions
+<code>min</code>, <code>max</code>, and <code>clear</code>.
+</li>
+<li>
+<a href="#Type_inference">Type inference</a> uses the types of interface methods for inference.
+It also infers type arguments for generic functions assigned to variables or
+passed as arguments to other (possibly generic) functions.
+</li>
+</ul>
+
+<h4 id="Go_1.22">Go 1.22</h4>
+<ul>
+<li>
+In a <a href="#For_statements">"for" statement</a>, each iteration has its own set of iteration
+variables rather than sharing the same variables in each iteration.
+</li>
+<li>
+A "for" statement with <a href="#For_range">"range" clause</a> may iterate over
+integer values from zero to an upper limit.
+</li>
+</ul>
+
<h3 id="Type_unification_rules">Type unification rules</h3>
<p>
diff --git a/lib/time/update.bash b/lib/time/update.bash
index 605afa76d3..e72850079f 100755
--- a/lib/time/update.bash
+++ b/lib/time/update.bash
@@ -24,8 +24,8 @@
# in the CL match the update.bash in the CL.
# Versions to use.
-CODE=2023c
-DATA=2023c
+CODE=2023d
+DATA=2023d
set -e
diff --git a/lib/time/zoneinfo.zip b/lib/time/zoneinfo.zip
index 417ee2b194..7cf689f830 100644
--- a/lib/time/zoneinfo.zip
+++ b/lib/time/zoneinfo.zip
Binary files differ
diff --git a/src/cmd/api/api_test.go b/src/cmd/api/api_test.go
index 910e046f12..ba358d364d 100644
--- a/src/cmd/api/api_test.go
+++ b/src/cmd/api/api_test.go
@@ -285,6 +285,25 @@ func TestIssue41358(t *testing.T) {
}
}
+func TestIssue64958(t *testing.T) {
+ defer func() {
+ if x := recover(); x != nil {
+ t.Errorf("expected no panic; recovered %v", x)
+ }
+ }()
+
+ testenv.MustHaveGoBuild(t)
+
+ for _, context := range contexts {
+ w := NewWalker(context, "testdata/src/issue64958")
+ pkg, err := w.importFrom("p", "", 0)
+ if err != nil {
+ t.Errorf("expected no error importing; got %T", err)
+ }
+ w.export(pkg)
+ }
+}
+
func TestCheck(t *testing.T) {
if !*flagCheck {
t.Skip("-check not specified")
diff --git a/src/cmd/api/main_test.go b/src/cmd/api/main_test.go
index 94e159e7d8..7985055b5c 100644
--- a/src/cmd/api/main_test.go
+++ b/src/cmd/api/main_test.go
@@ -957,17 +957,17 @@ func (w *Walker) emitType(obj *types.TypeName) {
if w.isDeprecated(obj) {
w.emitf("type %s //deprecated", name)
}
+ typ := obj.Type()
+ if obj.IsAlias() {
+ w.emitf("type %s = %s", name, w.typeString(typ))
+ return
+ }
if tparams := obj.Type().(*types.Named).TypeParams(); tparams != nil {
var buf bytes.Buffer
buf.WriteString(name)
w.writeTypeParams(&buf, tparams, true)
name = buf.String()
}
- typ := obj.Type()
- if obj.IsAlias() {
- w.emitf("type %s = %s", name, w.typeString(typ))
- return
- }
switch typ := typ.Underlying().(type) {
case *types.Struct:
w.emitStructType(name, typ)
diff --git a/src/cmd/api/testdata/src/issue64958/p/p.go b/src/cmd/api/testdata/src/issue64958/p/p.go
new file mode 100644
index 0000000000..feba86797f
--- /dev/null
+++ b/src/cmd/api/testdata/src/issue64958/p/p.go
@@ -0,0 +1,3 @@
+package p
+
+type BasicAlias = uint8
diff --git a/src/cmd/compile/internal/rangefunc/rewrite.go b/src/cmd/compile/internal/rangefunc/rewrite.go
index 7475c570aa..d439412ea8 100644
--- a/src/cmd/compile/internal/rangefunc/rewrite.go
+++ b/src/cmd/compile/internal/rangefunc/rewrite.go
@@ -934,7 +934,7 @@ func (r *rewriter) endLoop(loop *forLoop) {
if rfunc.Params().Len() != 1 {
base.Fatalf("invalid typecheck of range func")
}
- ftyp := rfunc.Params().At(0).Type().(*types2.Signature) // func(...) bool
+ ftyp := types2.CoreType(rfunc.Params().At(0).Type()).(*types2.Signature) // func(...) bool
if ftyp.Results().Len() != 1 {
base.Fatalf("invalid typecheck of range func")
}
diff --git a/src/cmd/compile/internal/ssa/sccp.go b/src/cmd/compile/internal/ssa/sccp.go
index 86c6117d87..77a6f50961 100644
--- a/src/cmd/compile/internal/ssa/sccp.go
+++ b/src/cmd/compile/internal/ssa/sccp.go
@@ -535,6 +535,13 @@ func rewireSuccessor(block *Block, constVal *Value) bool {
case BlockJumpTable:
// Remove everything but the known taken branch.
idx := int(constVal.AuxInt)
+ if idx < 0 || idx >= len(block.Succs) {
+ // This can only happen in unreachable code,
+ // as an invariant of jump tables is that their
+ // input index is in range.
+ // See issue 64826.
+ return false
+ }
block.swapSuccessorsByIdx(0, idx)
for len(block.Succs) > 1 {
block.removeEdge(1)
diff --git a/src/cmd/go/internal/work/exec.go b/src/cmd/go/internal/work/exec.go
index ecad324886..e05471b06c 100644
--- a/src/cmd/go/internal/work/exec.go
+++ b/src/cmd/go/internal/work/exec.go
@@ -629,19 +629,6 @@ OverlayLoop:
}
}
- // Run SWIG on each .swig and .swigcxx file.
- // Each run will generate two files, a .go file and a .c or .cxx file.
- // The .go file will use import "C" and is to be processed by cgo.
- if p.UsesSwig() {
- outGo, outC, outCXX, err := b.swig(a, objdir, pcCFLAGS)
- if err != nil {
- return err
- }
- cgofiles = append(cgofiles, outGo...)
- cfiles = append(cfiles, outC...)
- cxxfiles = append(cxxfiles, outCXX...)
- }
-
// If we're doing coverage, preprocess the .go files and put them in the work directory
if p.Internal.Cover.Mode != "" {
outfiles := []string{}
@@ -722,6 +709,22 @@ OverlayLoop:
}
}
+ // Run SWIG on each .swig and .swigcxx file.
+ // Each run will generate two files, a .go file and a .c or .cxx file.
+ // The .go file will use import "C" and is to be processed by cgo.
+ // For -cover test or build runs, this needs to happen after the cover
+ // tool is run; we don't want to instrument swig-generated Go files,
+ // see issue #64661.
+ if p.UsesSwig() {
+ outGo, outC, outCXX, err := b.swig(a, objdir, pcCFLAGS)
+ if err != nil {
+ return err
+ }
+ cgofiles = append(cgofiles, outGo...)
+ cfiles = append(cfiles, outC...)
+ cxxfiles = append(cxxfiles, outCXX...)
+ }
+
// Run cgo.
if p.UsesCgo() || p.UsesSwig() {
// In a package using cgo, cgo compiles the C, C++ and assembly files with gcc.
diff --git a/src/cmd/go/testdata/script/cover_swig.txt b/src/cmd/go/testdata/script/cover_swig.txt
new file mode 100644
index 0000000000..decb29aaec
--- /dev/null
+++ b/src/cmd/go/testdata/script/cover_swig.txt
@@ -0,0 +1,72 @@
+
+# Testcase for issue 64661. This testcase is intended to verify that
+# we don't try to send swig-generated Go files through the cover tool
+# for "go test -cover" runs on packages that have *.swig source files.
+
+[!exec:swig] skip
+[!cgo] skip
+
+go test -v -count=1 -coverprofile=foo.p
+stdout 'coverage: 100.0% of statements'
+
+-- go.mod --
+module simple
+
+go 1.21
+-- main.c --
+/* A global variable */
+double Foo = 3.0;
+
+/* Compute the greatest common divisor of positive integers */
+int gcd(int x, int y) {
+ int g;
+ g = y;
+ while (x > 0) {
+ g = x;
+ x = y % x;
+ y = g;
+ }
+ return g;
+}
+
+
+-- main.go --
+package main
+
+import (
+ "fmt"
+)
+
+func main() {
+ // Call our gcd() function
+ x := 42
+ y := 105
+ g := Gcd(x, y)
+ fmt.Println("The gcd of", x, "and", y, "is", g)
+
+ // Manipulate the Foo global variable
+
+ // Output its current value
+ fmt.Println("Foo =", GetFoo())
+
+ // Change its value
+ SetFoo(3.1415926)
+
+ // See if the change took effect
+ fmt.Println("Foo =", GetFoo())
+}
+-- main.swig --
+%module main
+
+%inline %{
+extern int gcd(int x, int y);
+extern double Foo;
+%}
+-- main_test.go --
+package main
+
+import "testing"
+
+func TestSwigFuncs(t *testing.T) {
+ main()
+}
diff --git a/src/debug/elf/elf.go b/src/debug/elf/elf.go
index 534cfa9127..e78367750f 100644
--- a/src/debug/elf/elf.go
+++ b/src/debug/elf/elf.go
@@ -13,7 +13,7 @@
* $FreeBSD: src/sys/sparc64/include/elf.h,v 1.12 2003/09/25 01:10:26 peter Exp $
* "System V ABI" (http://www.sco.com/developers/gabi/latest/ch4.eheader.html)
* "ELF for the ARM® 64-bit Architecture (AArch64)" (ARM IHI 0056B)
- * "RISC-V ELF psABI specification" (https://github.com/riscv/riscv-elf-psabi-doc/blob/master/riscv-elf.adoc)
+ * "RISC-V ELF psABI specification" (https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/master/riscv-elf.adoc)
* llvm/BinaryFormat/ELF.h - ELF constants and structures
*
* Copyright (c) 1996-1998 John D. Polstra. All rights reserved.
diff --git a/src/log/slog/logger.go b/src/log/slog/logger.go
index 4d21ee7990..10aa6a2b31 100644
--- a/src/log/slog/logger.go
+++ b/src/log/slog/logger.go
@@ -53,7 +53,8 @@ func init() {
// Default returns the default [Logger].
func Default() *Logger { return defaultLogger.Load() }
-// SetDefault makes l the default [Logger].
+// SetDefault makes l the default [Logger], which is used by
+// the top-level functions [Info], [Debug] and so on.
// After this call, output from the log package's default Logger
// (as with [log.Print], etc.) will be logged using l's Handler,
// at a level controlled by [SetLogLoggerLevel].
diff --git a/src/net/http/cgi/host_test.go b/src/net/http/cgi/host_test.go
index 78e05d592a..f29395fe84 100644
--- a/src/net/http/cgi/host_test.go
+++ b/src/net/http/cgi/host_test.go
@@ -17,8 +17,8 @@ import (
"os"
"path/filepath"
"reflect"
+ "regexp"
"runtime"
- "strconv"
"strings"
"testing"
"time"
@@ -363,11 +363,12 @@ func TestInternalRedirect(t *testing.T) {
// TestCopyError tests that we kill the process if there's an error copying
// its output. (for example, from the client having gone away)
+//
+// If we fail to do so, the test will time out (and dump its goroutines) with a
+// call to [Handler.ServeHTTP] blocked on a deferred call to [exec.Cmd.Wait].
func TestCopyError(t *testing.T) {
testenv.MustHaveExec(t)
- if runtime.GOOS == "windows" {
- t.Skipf("skipping test on %q", runtime.GOOS)
- }
+
h := &Handler{
Path: os.Args[0],
Root: "/test.cgi",
@@ -390,37 +391,42 @@ func TestCopyError(t *testing.T) {
t.Fatalf("ReadResponse: %v", err)
}
- pidstr := res.Header.Get("X-CGI-Pid")
- if pidstr == "" {
- t.Fatalf("expected an X-CGI-Pid header in response")
- }
- pid, err := strconv.Atoi(pidstr)
- if err != nil {
- t.Fatalf("invalid X-CGI-Pid value")
- }
-
var buf [5000]byte
n, err := io.ReadFull(res.Body, buf[:])
if err != nil {
t.Fatalf("ReadFull: %d bytes, %v", n, err)
}
- childRunning := func() bool {
- return isProcessRunning(pid)
- }
-
- if !childRunning() {
- t.Fatalf("pre-conn.Close, expected child to be running")
+ if !handlerRunning() {
+ t.Fatalf("pre-conn.Close, expected handler to still be running")
}
conn.Close()
+ closed := time.Now()
- tries := 0
- for tries < 25 && childRunning() {
- time.Sleep(50 * time.Millisecond * time.Duration(tries))
- tries++
+ nextSleep := 1 * time.Millisecond
+ for {
+ time.Sleep(nextSleep)
+ nextSleep *= 2
+ if !handlerRunning() {
+ break
+ }
+ t.Logf("handler still running %v after conn.Close", time.Since(closed))
}
- if childRunning() {
- t.Fatalf("post-conn.Close, expected child to be gone")
+}
+
+// handlerRunning reports whether any goroutine is currently running
+// [Handler.ServeHTTP].
+func handlerRunning() bool {
+ r := regexp.MustCompile(`net/http/cgi\.\(\*Handler\)\.ServeHTTP`)
+ buf := make([]byte, 64<<10)
+ for {
+ n := runtime.Stack(buf, true)
+ if n < len(buf) {
+ return r.Match(buf[:n])
+ }
+ // Buffer wasn't large enough for a full goroutine dump.
+ // Resize it and try again.
+ buf = make([]byte, 2*len(buf))
}
}
diff --git a/src/net/http/cgi/plan9_test.go b/src/net/http/cgi/plan9_test.go
deleted file mode 100644
index b7ace3f81c..0000000000
--- a/src/net/http/cgi/plan9_test.go
+++ /dev/null
@@ -1,17 +0,0 @@
-// Copyright 2013 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-//go:build plan9
-
-package cgi
-
-import (
- "os"
- "strconv"
-)
-
-func isProcessRunning(pid int) bool {
- _, err := os.Stat("/proc/" + strconv.Itoa(pid))
- return err == nil
-}
diff --git a/src/net/http/cgi/posix_test.go b/src/net/http/cgi/posix_test.go
deleted file mode 100644
index 49b9470d4a..0000000000
--- a/src/net/http/cgi/posix_test.go
+++ /dev/null
@@ -1,20 +0,0 @@
-// Copyright 2013 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-//go:build !plan9
-
-package cgi
-
-import (
- "os"
- "syscall"
-)
-
-func isProcessRunning(pid int) bool {
- p, err := os.FindProcess(pid)
- if err != nil {
- return false
- }
- return p.Signal(syscall.Signal(0)) == nil
-}
diff --git a/src/net/http/internal/chunked.go b/src/net/http/internal/chunked.go
index aad8e5aa09..c0fa4ccac7 100644
--- a/src/net/http/internal/chunked.go
+++ b/src/net/http/internal/chunked.go
@@ -263,6 +263,9 @@ type FlushAfterChunkWriter struct {
}
func parseHexUint(v []byte) (n uint64, err error) {
+ if len(v) == 0 {
+ return 0, errors.New("empty hex number for chunk length")
+ }
for i, b := range v {
switch {
case '0' <= b && b <= '9':
diff --git a/src/net/http/internal/chunked_test.go b/src/net/http/internal/chunked_test.go
index b99090c1f8..af79711781 100644
--- a/src/net/http/internal/chunked_test.go
+++ b/src/net/http/internal/chunked_test.go
@@ -153,6 +153,7 @@ func TestParseHexUint(t *testing.T) {
{"00000000000000000", 0, "http chunk length too large"}, // could accept if we wanted
{"10000000000000000", 0, "http chunk length too large"},
{"00000000000000001", 0, "http chunk length too large"}, // could accept if we wanted
+ {"", 0, "empty hex number for chunk length"},
}
for i := uint64(0); i <= 1234; i++ {
tests = append(tests, testCase{in: fmt.Sprintf("%x", i), want: i})
diff --git a/src/net/http/request.go b/src/net/http/request.go
index ed2cdac136..fce2d16f95 100644
--- a/src/net/http/request.go
+++ b/src/net/http/request.go
@@ -397,6 +397,20 @@ func (r *Request) Clone(ctx context.Context) *Request {
r2.Form = cloneURLValues(r.Form)
r2.PostForm = cloneURLValues(r.PostForm)
r2.MultipartForm = cloneMultipartForm(r.MultipartForm)
+
+ // Copy matches and otherValues. See issue 61410.
+ if s := r.matches; s != nil {
+ s2 := make([]string, len(s))
+ copy(s2, s)
+ r2.matches = s2
+ }
+ if s := r.otherValues; s != nil {
+ s2 := make(map[string]string, len(s))
+ for k, v := range s {
+ s2[k] = v
+ }
+ r2.otherValues = s2
+ }
return r2
}
@@ -1427,6 +1441,8 @@ func (r *Request) PathValue(name string) string {
return r.otherValues[name]
}
+// SetPathValue sets name to value, so that subsequent calls to r.PathValue(name)
+// return value.
func (r *Request) SetPathValue(name, value string) {
if i := r.patIndex(name); i >= 0 {
r.matches[i] = value
diff --git a/src/net/http/request_test.go b/src/net/http/request_test.go
index 1531da3d8c..6ce32332e7 100644
--- a/src/net/http/request_test.go
+++ b/src/net/http/request_test.go
@@ -1053,6 +1053,33 @@ func TestRequestCloneTransferEncoding(t *testing.T) {
}
}
+// Ensure that Request.Clone works correctly with PathValue.
+// See issue 64911.
+func TestRequestClonePathValue(t *testing.T) {
+ req, _ := http.NewRequest("GET", "https://example.org/", nil)
+ req.SetPathValue("p1", "orig")
+
+ clonedReq := req.Clone(context.Background())
+ clonedReq.SetPathValue("p2", "copy")
+
+ // Ensure that any modifications to the cloned
+ // request do not pollute the original request.
+ if g, w := req.PathValue("p2"), ""; g != w {
+ t.Fatalf("p2 mismatch got %q, want %q", g, w)
+ }
+ if g, w := req.PathValue("p1"), "orig"; g != w {
+ t.Fatalf("p1 mismatch got %q, want %q", g, w)
+ }
+
+ // Assert on the changes to the cloned request.
+ if g, w := clonedReq.PathValue("p1"), "orig"; g != w {
+ t.Fatalf("p1 mismatch got %q, want %q", g, w)
+ }
+ if g, w := clonedReq.PathValue("p2"), "copy"; g != w {
+ t.Fatalf("p2 mismatch got %q, want %q", g, w)
+ }
+}
+
// Issue 34878: verify we don't panic when including basic auth (Go 1.13 regression)
func TestNoPanicOnRoundTripWithBasicAuth(t *testing.T) { run(t, testNoPanicWithBasicAuth) }
func testNoPanicWithBasicAuth(t *testing.T, mode testMode) {
diff --git a/src/net/sock_windows.go b/src/net/sock_windows.go
index 5540135a2c..a519909bb0 100644
--- a/src/net/sock_windows.go
+++ b/src/net/sock_windows.go
@@ -11,8 +11,9 @@ import (
)
func maxListenerBacklog() int {
- // TODO: Implement this
- // NOTE: Never return a number bigger than 1<<16 - 1. See issue 5030.
+ // When the socket backlog is SOMAXCONN, Windows will set the backlog to
+ // "a reasonable maximum value".
+ // See: https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-listen
return syscall.SOMAXCONN
}
diff --git a/src/reflect/type.go b/src/reflect/type.go
index a35898547a..89c5015530 100644
--- a/src/reflect/type.go
+++ b/src/reflect/type.go
@@ -1914,7 +1914,7 @@ func needKeyUpdate(t *abi.Type) bool {
case Float32, Float64, Complex64, Complex128, Interface, String:
// Float keys can be updated from +0 to -0.
// String keys can be updated to use a smaller backing store.
- // Interfaces might have floats of strings in them.
+ // Interfaces might have floats or strings in them.
return true
case Array:
tt := (*arrayType)(unsafe.Pointer(t))
diff --git a/src/runtime/metrics/doc.go b/src/runtime/metrics/doc.go
index e5a1fbc8d2..fb2f44da29 100644
--- a/src/runtime/metrics/doc.go
+++ b/src/runtime/metrics/doc.go
@@ -8,7 +8,7 @@
/*
Package metrics provides a stable interface to access implementation-defined
metrics exported by the Go runtime. This package is similar to existing functions
-like [runtime.ReadMemStats] and [debug.ReadGCStats], but significantly more general.
+like [runtime.ReadMemStats] and [runtime/debug.ReadGCStats], but significantly more general.
The set of metrics defined by this package may evolve as the runtime itself
evolves, and also enables variation across Go implementations, whose relevant
@@ -28,7 +28,8 @@ encouraged to use build tags, and although metrics may be deprecated and removed
users should consider this to be an exceptional and rare event, coinciding with a
very large change in a particular Go implementation.
-Each metric key also has a "kind" that describes the format of the metric's value.
+Each metric key also has a "kind" (see [ValueKind]) that describes the format of the
+metric's value.
In the interest of not breaking users of this package, the "kind" for a given metric
is guaranteed not to change. If it must change, then a new metric will be introduced
with a new key and a new "kind."
diff --git a/src/runtime/mpagealloc_64bit.go b/src/runtime/mpagealloc_64bit.go
index 1418831a50..36cd222360 100644
--- a/src/runtime/mpagealloc_64bit.go
+++ b/src/runtime/mpagealloc_64bit.go
@@ -209,23 +209,20 @@ func (s *scavengeIndex) sysGrow(base, limit uintptr, sysStat *sysMemStat) uintpt
haveMax := s.max.Load()
needMin := alignDown(uintptr(chunkIndex(base)), physPageSize/scSize)
needMax := alignUp(uintptr(chunkIndex(limit)), physPageSize/scSize)
- // Extend the range down to what we have, if there's no overlap.
+
+ // We need a contiguous range, so extend the range if there's no overlap.
if needMax < haveMin {
needMax = haveMin
}
if haveMax != 0 && needMin > haveMax {
needMin = haveMax
}
- have := makeAddrRange(
- // Avoid a panic from indexing one past the last element.
- uintptr(unsafe.Pointer(&s.chunks[0]))+haveMin*scSize,
- uintptr(unsafe.Pointer(&s.chunks[0]))+haveMax*scSize,
- )
- need := makeAddrRange(
- // Avoid a panic from indexing one past the last element.
- uintptr(unsafe.Pointer(&s.chunks[0]))+needMin*scSize,
- uintptr(unsafe.Pointer(&s.chunks[0]))+needMax*scSize,
- )
+
+ // Avoid a panic from indexing one past the last element.
+ chunksBase := uintptr(unsafe.Pointer(&s.chunks[0]))
+ have := makeAddrRange(chunksBase+haveMin*scSize, chunksBase+haveMax*scSize)
+ need := makeAddrRange(chunksBase+needMin*scSize, chunksBase+needMax*scSize)
+
// Subtract any overlap from rounding. We can't re-map memory because
// it'll be zeroed.
need = need.subtract(have)
@@ -235,10 +232,10 @@ func (s *scavengeIndex) sysGrow(base, limit uintptr, sysStat *sysMemStat) uintpt
sysMap(unsafe.Pointer(need.base.addr()), need.size(), sysStat)
sysUsed(unsafe.Pointer(need.base.addr()), need.size(), need.size())
// Update the indices only after the new memory is valid.
- if haveMin == 0 || needMin < haveMin {
+ if haveMax == 0 || needMin < haveMin {
s.min.Store(needMin)
}
- if haveMax == 0 || needMax > haveMax {
+ if needMax > haveMax {
s.max.Store(needMax)
}
}
diff --git a/src/runtime/pagetrace_on.go b/src/runtime/pagetrace_on.go
index 0e621cb6ca..f82521caad 100644
--- a/src/runtime/pagetrace_on.go
+++ b/src/runtime/pagetrace_on.go
@@ -317,7 +317,7 @@ func finishPageTrace() {
pageTrace.enabled = false
// Execute a ragged barrier, flushing each trace buffer.
- forEachP(func(pp *p) {
+ forEachP(waitReasonPageTraceFlush, func(pp *p) {
if pp.pageTraceBuf.buf != nil {
pp.pageTraceBuf = pp.pageTraceBuf.flush(pp.id, nanotime())
}
diff --git a/src/runtime/pprof/pprof.go b/src/runtime/pprof/pprof.go
index 1e698425d7..a4dcf33508 100644
--- a/src/runtime/pprof/pprof.go
+++ b/src/runtime/pprof/pprof.go
@@ -69,7 +69,7 @@
// all pprof commands.
//
// For more information about pprof, see
-// https://github.com/google/pprof/blob/master/doc/README.md.
+// https://github.com/google/pprof/blob/main/doc/README.md.
package pprof
import (
diff --git a/src/runtime/runtime.go b/src/runtime/runtime.go
index 92cdfc310e..c70a76e409 100644
--- a/src/runtime/runtime.go
+++ b/src/runtime/runtime.go
@@ -167,13 +167,10 @@ func (g *godebugInc) IncNonDefault() {
if newInc == nil {
return
}
- // If other goroutines are racing here, no big deal. One will win,
- // and all the inc functions will be using the same underlying
- // *godebug.Setting.
inc = new(func())
*inc = (*newInc)(g.name)
if raceenabled {
- racerelease(unsafe.Pointer(&g.inc))
+ racereleasemerge(unsafe.Pointer(&g.inc))
}
if !g.inc.CompareAndSwap(nil, inc) {
inc = g.inc.Load()
diff --git a/src/runtime/runtime2.go b/src/runtime/runtime2.go
index 2d3fd30e63..63320d4a8a 100644
--- a/src/runtime/runtime2.go
+++ b/src/runtime/runtime2.go
@@ -1127,6 +1127,7 @@ const (
waitReasonFlushProcCaches // "flushing proc caches"
waitReasonTraceGoroutineStatus // "trace goroutine status"
waitReasonTraceProcStatus // "trace proc status"
+ waitReasonPageTraceFlush // "page trace flush"
waitReasonCoroutine // "coroutine"
)
@@ -1166,6 +1167,7 @@ var waitReasonStrings = [...]string{
waitReasonFlushProcCaches: "flushing proc caches",
waitReasonTraceGoroutineStatus: "trace goroutine status",
waitReasonTraceProcStatus: "trace proc status",
+ waitReasonPageTraceFlush: "page trace flush",
waitReasonCoroutine: "coroutine",
}
diff --git a/src/runtime/trace2status.go b/src/runtime/trace2status.go
index a4a8905196..5016e08656 100644
--- a/src/runtime/trace2status.go
+++ b/src/runtime/trace2status.go
@@ -147,6 +147,7 @@ func goStatusToTraceGoStatus(status uint32, wr waitReason) traceGoStatus {
wr == waitReasonGCMarkTermination ||
wr == waitReasonGarbageCollection ||
wr == waitReasonTraceProcStatus ||
+ wr == waitReasonPageTraceFlush ||
wr == waitReasonGCWorkerActive {
tgs = traceGoRunning
}
diff --git a/src/slices/slices_test.go b/src/slices/slices_test.go
index ab25bd8dfd..31d59abe17 100644
--- a/src/slices/slices_test.go
+++ b/src/slices/slices_test.go
@@ -557,7 +557,7 @@ func TestInsertPanics(t *testing.T) {
{"with out-of-bounds index and = cap", a[:1:2], 2, b[:]},
{"with out-of-bounds index and < cap", a[:1:3], 2, b[:]},
} {
- if !panics(func() { Insert(test.s, test.i, test.v...) }) {
+ if !panics(func() { _ = Insert(test.s, test.i, test.v...) }) {
t.Errorf("Insert %s: got no panic, want panic", test.name)
}
}
@@ -684,7 +684,7 @@ func TestDeletePanics(t *testing.T) {
{"s[i:j] is valid and j > len(s)", s, 0, 4},
{"s[i:j] is valid and i == j > len(s)", s, 3, 3},
} {
- if !panics(func() { Delete(test.s, test.i, test.j) }) {
+ if !panics(func() { _ = Delete(test.s, test.i, test.j) }) {
t.Errorf("Delete %s: got no panic, want panic", test.name)
}
}
@@ -906,10 +906,10 @@ func TestGrow(t *testing.T) {
}
// Test number of allocations.
- if n := testing.AllocsPerRun(100, func() { Grow(s2, cap(s2)-len(s2)) }); n != 0 {
+ if n := testing.AllocsPerRun(100, func() { _ = Grow(s2, cap(s2)-len(s2)) }); n != 0 {
t.Errorf("Grow should not allocate when given sufficient capacity; allocated %v times", n)
}
- if n := testing.AllocsPerRun(100, func() { Grow(s2, cap(s2)-len(s2)+1) }); n != 1 {
+ if n := testing.AllocsPerRun(100, func() { _ = Grow(s2, cap(s2)-len(s2)+1) }); n != 1 {
errorf := t.Errorf
if race.Enabled || testenv.OptimizationOff() {
errorf = t.Logf // this allocates multiple times in race detector mode
@@ -921,7 +921,7 @@ func TestGrow(t *testing.T) {
var gotPanic bool
func() {
defer func() { gotPanic = recover() != nil }()
- Grow(s1, -1)
+ _ = Grow(s1, -1)
}()
if !gotPanic {
t.Errorf("Grow(-1) did not panic; expected a panic")
@@ -1037,7 +1037,7 @@ func TestReplacePanics(t *testing.T) {
{"s[i:j] is valid and j > len(s)", s, nil, 0, 4},
} {
ss, vv := Clone(test.s), Clone(test.v)
- if !panics(func() { Replace(ss, test.i, test.j, vv...) }) {
+ if !panics(func() { _ = Replace(ss, test.i, test.j, vv...) }) {
t.Errorf("Replace %s: should have panicked", test.name)
}
}
diff --git a/src/sync/map.go b/src/sync/map.go
index 00b2446153..7a9eebdce3 100644
--- a/src/sync/map.go
+++ b/src/sync/map.go
@@ -8,7 +8,7 @@ import (
"sync/atomic"
)
-// Map is like a Go map[interface{}]interface{} but is safe for concurrent use
+// Map is like a Go map[any]any but is safe for concurrent use
// by multiple goroutines without additional locking or coordination.
// Loads, stores, and deletes run in amortized constant time.
//
diff --git a/test/fixedbugs/issue64826.go b/test/fixedbugs/issue64826.go
new file mode 100644
index 0000000000..864c474a64
--- /dev/null
+++ b/test/fixedbugs/issue64826.go
@@ -0,0 +1,38 @@
+// build
+
+// Copyright 2023 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+func main() {
+ f(g(false))
+}
+func g(b bool) string {
+ if b {
+ return "z"
+ }
+ return "q"
+}
+func f(x string) int {
+ switch len(x) {
+ case 4:
+ return 4
+ case 5:
+ return 5
+ case 6:
+ return 6
+ case 7:
+ return 7
+ case 8:
+ return 8
+ case 9:
+ return 9
+ case 10:
+ return 10
+ case 11:
+ return 11
+ }
+ return 0
+}
diff --git a/test/range4.go b/test/range4.go
index 696b205ab7..0b051f6d3c 100644
--- a/test/range4.go
+++ b/test/range4.go
@@ -311,6 +311,30 @@ func testcalls() {
}
}
+type iter3YieldFunc func(int, int) bool
+
+func iter3(list ...int) func(iter3YieldFunc) {
+ return func(yield iter3YieldFunc) {
+ for k, v := range list {
+ if !yield(k, v) {
+ return
+ }
+ }
+ }
+}
+
+func testcalls1() {
+ ncalls := 0
+ for k, v := range iter3(1, 2, 3) {
+ _, _ = k, v
+ ncalls++
+ }
+ if ncalls != 3 {
+ println("wrong number of calls:", ncalls, "!= 3")
+ panic("fail")
+ }
+}
+
func main() {
testfunc0()
testfunc1()
@@ -323,4 +347,5 @@ func main() {
testfunc8()
testfunc9()
testcalls()
+ testcalls1()
}