1
0
mirror of https://github.com/golang/go synced 2024-09-28 23:24:33 -06:00
Commit Graph

721 Commits

Author SHA1 Message Date
Robert Griesemer
1aaf1b219a spec: clarify min/max rules for numeric arguments (exclude NaNs)
Fixes #60570.

Change-Id: I7ef834731ea26ceee5ec9b7438fdd8323aaf828e
Reviewed-on: https://go-review.googlesource.com/c/go/+/500416
TryBot-Bypass: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
2023-06-06 21:23:09 +00:00
Robert Griesemer
f9d114d0e8 spec: document min and max built-ins
For #59488.

Change-Id: I50f65216bf02b42c1e0619702833f4a6dbed8925
Reviewed-on: https://go-review.googlesource.com/c/go/+/498136
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Bypass: Robert Griesemer <gri@google.com>
2023-05-25 21:09:38 +00:00
Robert Griesemer
15a4e0d970 spec: re-order built-ins sections alphabetically (more or less)
Put the sections for the various built-ins into alphabetical order
based on the built-in name, while keeping built-ins that belong
together together.

The order is now (captialized letter determines order):

- Append
- Clear
- Close
- Complex, real, imag
- Delete
- Len, cap
- Make
- Min, max (to be inserted here)
- New
- Panic, recover
- Print, println

There are some white space adjustments but no changes to the prose
of the moved sections.

Change-Id: Iaec509918c6bc965df3f28656374de03279bdc9e
Reviewed-on: https://go-review.googlesource.com/c/go/+/498135
Reviewed-by: Robert Griesemer <gri@google.com>
TryBot-Bypass: Robert Griesemer <gri@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2023-05-24 22:24:59 +00:00
Daniel Frederick Crisman
e7b04a3e16 doc: correct spelling on placeholder
"placeholder" (no space) is already used in the spec and seems to be
the preferred option.

Removed space from "place holder".

Change-Id: I9b98f62f0e3f5adb019b99f5271cc9d19abf505e
GitHub-Last-Rev: ed5aaf9d02
GitHub-Pull-Request: golang/go#59626
Reviewed-on: https://go-review.googlesource.com/c/go/+/484576
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
2023-04-13 23:15:09 +00:00
Daniel Frederick Crisman
6e8eec7328 doc: add missing oxford comma in Constants
In the language specification under "Constants" the lists matching default
types to untyped contstant types is missing an Oxford comma in the first
list. I found a number of other places in the spec and #23442 that use the
Oxford comma to support its use.

Add missing Oxford comma in Constants default type list.

Change-Id: I4562d692610334bc82452db076145d2414617a04
GitHub-Last-Rev: 8acdb60d6e
GitHub-Pull-Request: golang/go#59528
Reviewed-on: https://go-review.googlesource.com/c/go/+/483555
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
2023-04-11 17:02:02 +00:00
cui fliter
df6d442c38 doc: fix "are" to "or" in core types
Fixes #59506

Change-Id: I2f8b92e93b706b061ca0eb0bd52e5cf798ce9ede
Reviewed-on: https://go-review.googlesource.com/c/go/+/483358
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Bypass: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
2023-04-11 01:45:40 +00:00
Cuong Manh Le
99bc53f5e8 doc: add clear builtin to spec
Fixes #56351

Change-Id: Ia87bf594553b7d0464b591106840f849571c5f39
Reviewed-on: https://go-review.googlesource.com/c/go/+/467755
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Robert Griesemer <gri@google.com>
TryBot-Bypass: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2023-02-20 02:28:50 +00:00
Cuong Manh Le
2baf8ad831 doc: do not use "==" in slice examples
There's no slice comparison in Go.

Change-Id: I5de1766c2adeb56ed12a577a4c46c12b2582b1c8
Reviewed-on: https://go-review.googlesource.com/c/go/+/469015
Reviewed-by: Robert Griesemer <gri@google.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2023-02-19 23:51:51 +00:00
Cuong Manh Le
135c470b22 doc: add missing builtin functions not permitted in statement context
The typechecker already enforces this semantic, but the spec is not
updated when unsafe.{SliceData,String,StringData} were added.

Change-Id: I4ee8c564d5681b2a5fd31ff424a31bdf065d9f3b
Reviewed-on: https://go-review.googlesource.com/c/go/+/467756
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2023-02-16 19:49:55 +00:00
Oleksandr Redko
f63ee8b2c7 doc: fix spec typo
Change-Id: I5e3aca2b8fc78f38c9e2cdc67adf86d57ac85b1c
GitHub-Last-Rev: 0e5ddffe33
GitHub-Pull-Request: golang/go#58353
Reviewed-on: https://go-review.googlesource.com/c/go/+/465615
Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2023-02-07 23:37:57 +00:00
Russ Cox
aa51c40b1c runtime: replace panic(nil) with panic(new(runtime.PanicNilError))
Long ago we decided that panic(nil) was too unlikely to bother
making a special case for purposes of recover. Unfortunately,
it has turned out not to be a special case. There are many examples
of code in the Go ecosystem where an author has written panic(nil)
because they want to panic and don't care about the panic value.

Using panic(nil) in this case has the unfortunate behavior of
making recover behave as though the goroutine isn't panicking.
As a result, code like:

	func f() {
		defer func() {
			if err := recover(); err != nil {
				log.Fatalf("panicked! %v", err)
			}
		}()
		call1()
		call2()
	}

looks like it guarantees that call2 has been run any time f returns,
but that turns out not to be strictly true. If call1 does panic(nil),
then f returns "successfully", having recovered the panic, but
without calling call2.

Instead you have to write something like:

	func f() {
		done := false
		defer func() {
			if err := recover(); !done {
				log.Fatalf("panicked! %v", err)
			}
		}()
		call1()
		call2()
		done = true
	}

which defeats nearly the whole point of recover. No one does this,
with the result that almost all uses of recover are subtly broken.

One specific broken use along these lines is in net/http, which
recovers from panics in handlers and sends back an HTTP error.
Users discovered in the early days of Go that panic(nil) was a
convenient way to jump out of a handler up to the serving loop
without sending back an HTTP error. This was a bug, not a feature.
Go 1.8 added panic(http.ErrAbortHandler) as a better way to access the feature.
Any lingering code that uses panic(nil) to abort an HTTP handler
without a failure message should be changed to use http.ErrAbortHandler.

Programs that need the old, unintended behavior from net/http
or other packages can set GODEBUG=panicnil=1 to stop the run-time error.

Uses of recover that want to detect panic(nil) in new programs
can check for recover returning a value of type *runtime.PanicNilError.

Because the new GODEBUG is used inside the runtime, we can't
import internal/godebug, so there is some new machinery to
cross-connect those in this CL, to allow a mutable GODEBUG setting.
That won't be necessary if we add any other mutable GODEBUG settings
in the future. The CL also corrects the handling of defaulted GODEBUG
values in the runtime, for #56986.

Fixes #25448.

Change-Id: I2b39c7e83e4f7aa308777dabf2edae54773e03f5
Reviewed-on: https://go-review.googlesource.com/c/go/+/461956
Reviewed-by: Robert Griesemer <gri@google.com>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Russ Cox <rsc@golang.org>
2023-01-19 22:21:50 +00:00
Robert Griesemer
357ea85892 spec: fix typo
Fixes #57323.

Change-Id: I77d3d747aa4746bb9a8cca0c0500ff8fa6ae33a3
Reviewed-on: https://go-review.googlesource.com/c/go/+/457915
Reviewed-by: Robert Griesemer <gri@google.com>
TryBot-Bypass: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
2022-12-15 16:18:42 +00:00
Robert Griesemer
ea14d1b6e1 spec: document which recursive arrays and structs are valid/invalid
Fixes #5069.

Change-Id: I4bc0f52a9cd1e64a49846dffeb4be5cbecc29a96
Reviewed-on: https://go-review.googlesource.com/c/go/+/457342
TryBot-Bypass: Robert Griesemer <gri@google.com>
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-12-14 22:29:38 +00:00
Robert Griesemer
5c682f94c6 spec: document illegal recursive type parameter lists
Fixes #40882.

Change-Id: I90f99d75e6d66f857b6ab8789c6d436f85d20993
Reviewed-on: https://go-review.googlesource.com/c/go/+/457515
TryBot-Bypass: Robert Griesemer <gri@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-12-14 19:13:24 +00:00
Robert Griesemer
bd42aa86d3 spec: describe new semantics for comparable and constraint satisfaction
For #56548.
Fixes #57012.

Change-Id: I44f850522e52b1811025fb31bcef289da8f8089d
Reviewed-on: https://go-review.googlesource.com/c/go/+/457437
TryBot-Bypass: Robert Griesemer <gri@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
2022-12-14 19:13:10 +00:00
Robert Griesemer
ffefcd360b spec: introduce notion of strict comparability
- Rephrase the notion of "comparability" from a property
  of values (operands) to a property of types and adjust
  dependent prose.
- Introduce the notion of "strict comparability".
- Fix the definitions of comparability for type interfaces
  and type parameters.
- Define the predeclared identifier "comparable" as stricly
  comparable.

These changes address existing problems in the spec as outlined
in the section on "Related spec issues" in issue #56548.

For #56548.

Change-Id: Ibc8c2f36d92857a5134eadc18358624803d3dd21
Reviewed-on: https://go-review.googlesource.com/c/go/+/457095
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Bypass: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
2022-12-14 19:12:15 +00:00
Zhizhen He
8247b9f17a doc: fix typo
Change-Id: Ie639fe39b83336c0d885cdcb2fddc06f2b06c2dd
GitHub-Last-Rev: b5cc78ad42
GitHub-Pull-Request: golang/go#57082
Reviewed-on: https://go-review.googlesource.com/c/go/+/455196
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
2022-12-08 19:06:14 +00:00
Tim King
60525dc31d spec: document conversion from slice to array
Document that a slice can be converted to either an array or a pointer
to an array of a matching underlying array type. This was documented in
the "Conversions from slice to array or array pointer" subsection, but
not in the list of conversion rules.

Updates #46505.

Change-Id: I16a89a63ef23c33580129952415e977a8f334009
Reviewed-on: https://go-review.googlesource.com/c/go/+/452936
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@google.com>
Run-TryBot: Tim King <taking@google.com>
2022-11-30 17:03:21 +00:00
Robert Griesemer
72fdecafc0 spec: add a link to Allocation section in section on append built-in
If needed, the built-in function append allocates a new underlying
array. While we (probably) don't want to specify exactly how much
is allocated (the prose is deliberately vague), if there's more
space allocated than needed (cap > len after allocation), that
extra space is zeroed. Use an explicit link to the section on
Allocation which explicitly states that newly allocated memory
is zeroed.

Fixes #56684.

Change-Id: I9805d37c263b87860ea703ad143f738a0846247e
Reviewed-on: https://go-review.googlesource.com/c/go/+/452619
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Joseph Tsai <joetsai@digital-static.net>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2022-11-23 00:25:09 +00:00
Robert Griesemer
753ad5e1d5 spec: document that trailing comma is valid after index in index expressions
At parse time we don't know if a[i] is an index expression or a
type (or function) instantiation. Because instantiations accept
a list of type arguments, and argument lists permit a trailing
comma, a[i,] is either an instantiation or index expression.

Document that a trailing comma is permitted in the syntax for
index expressions.

For comparison, the same problem arises with conversions which
cannot be distinguished from function calls at parse time. The
spec also permits a trailing comma for conversions T(x,). The
grammar adjustment is the same (see line 5239).

Fixes #55007.

Change-Id: Ib9101efe52031589eb95a428cc6dff940d939f9e
Reviewed-on: https://go-review.googlesource.com/c/go/+/452618
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
2022-11-23 00:25:08 +00:00
Robert Griesemer
c55d184151 spec: document the new unsafe functions SliceData, String, and StringData
For #53003.

Change-Id: If5d76c7b8dfcbcab919cad9c333c0225fc155859
Reviewed-on: https://go-review.googlesource.com/c/go/+/449537
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@google.com>
2022-11-14 05:30:16 +00:00
Robert Griesemer
2041bde2b6 spec: clarify struct field and array element comparison order
Fixes #8606.

Change-Id: I64b13b2ed61ecae4641264deb47c9f7653a80356
Reviewed-on: https://go-review.googlesource.com/c/go/+/449536
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-11-14 01:28:11 +00:00
Cuong Manh Le
334984a92a spec: describe an edge case for slice expression of nil slice
Change-Id: I8c0e2b37e7e8cb4db6ad0b456fde7eb908ffbd04
Reviewed-on: https://go-review.googlesource.com/c/go/+/430836
Reviewed-by: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
2022-09-21 14:06:17 +00:00
Cuong Manh Le
4b58b30778 spec: describe an edge case of slice-to-array conversions
Converting from nil slice to zero element array is ok, so explicitly
describe the behavior in the spec.

For #46505

Change-Id: I68f432deb6c21a7549bf7e870185fc62504b37f7
Reviewed-on: https://go-review.googlesource.com/c/go/+/430835
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2022-09-21 14:06:15 +00:00
VRDighe
0bfa9f0435 spec: fix typo in a type parameter example
Fixes #54973

Change-Id: Ibad9dd124617a1bbc23abd17cbd6e9e9928e3ed9
GitHub-Last-Rev: 1c6affb967
GitHub-Pull-Request: golang/go#55021
Reviewed-on: https://go-review.googlesource.com/c/go/+/430316
Reviewed-by: Cherry Mui <cherryyz@google.com>
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-09-20 15:50:36 +00:00
Robert Griesemer
2c3187cd42 spec: describe slice-to-array conversions
For #46505.

Change-Id: I1a30fd895496befd16626afb48717ac837ed5778
Reviewed-on: https://go-review.googlesource.com/c/go/+/429315
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Robert Griesemer <gri@google.com>
2022-09-08 16:37:47 +00:00
Robert Griesemer
17083a2fdf spec: retitle section on "Assignments" to "Assignment statements"
This permits a clear distinction between an individual assignment
and an assignment statement which may assign more than one value.
It also makes this section title consistent with all other section
titles about statements. Adjust internal links and prose where
appropriate. (Note that the spec already referred to assignment
statements in a couple of places, even before this change.)

Add an introductory paragraph to the section on assignment statements.

Preparation for adding a section on value vs reference types
(issue #5083).

Change-Id: Ie140ac296e653c67da2a5a203b63352b3dc4f9f5
Reviewed-on: https://go-review.googlesource.com/c/go/+/413615
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-06-30 00:58:41 +00:00
Robert Griesemer
f2c7e78592 spec: document operations which accept []byte|string constrained types
Pre-1.18, as special cases, the built-in operations append and copy
accepted strings as second arguments if the first argument was a byte
slice. With Go 1.18, these two built-ins as well as slice expressions
rely on the notion of core types in their specification.

Because we want to permit slice expressions, append, and copy to
operate on (1st or 2nd operands) that are type parameters restricted
by []byte | string (and variations thereof), the simple notion of
core type is not sufficient for these three operations. (The compiler
already permits such more relaxed operations).

In the section on core types, add a paragraph and examples introducing
the (artificial) core type "bypestring", which describes the core type
of type sets whose underlying types are []byte or string. Adjust the
rules for slice expressions, append, and copy accordingly.

Also (unrelated): Adjust prose in the only paragraph where we used
personal speech ("we") to impersonal speech, to match the rest of
the spec.

Fixes #52859.

Change-Id: I1cbda3095a1136fb99334cc3a62a9a349a27ce1e
Reviewed-on: https://go-review.googlesource.com/c/go/+/412234
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
2022-06-21 23:17:35 +00:00
Robert Griesemer
bcce8ef498 spec: adjust incorrect sentence in section on rune literals
Add an additional example.

Fixes #53217.

Change-Id: I899376b9c1fa8dc5d475d8d3d6c8788ab79b0847
Reviewed-on: https://go-review.googlesource.com/c/go/+/412238
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-06-16 16:22:37 +00:00
Robert Griesemer
0dffda1383 spec: clarify "slice of bytes" and "slice of runes" through examples
The spec section on conversions uses the terms "slice of bytes" and
"slice of runes". While not obviously clear, what is meant are slice
types whose element types are byte or rune types; specifically the
underlying types of the slices' element types must be byte or rune.

Some of this was evident from the examples, but not all of it. Made
this clearer by adding more examples illustrating various permitted
conversions.

Note that the 1.17 compiler did not accept the following conversions:

        string([]myByte{...})
        string([]myRune{...})
        myString([]myByte{...})
        myString([]myRune{...})

(where myByte, myRune, and myString have underlying types of byte,
rune, and string respectively) - it reported an internal error.
But it did accept the inverse conversions:

        []myByte("...")
        []myRune("...")
        []myByte(myString("..."))
        []myRune(myString("..."))

The 1.18 compiler made those conversions symmetric and they are now
permitted in both directions.

The extra examples reflect this reality.

Fixes #23814.

Change-Id: I5a1c200b45ddd0e8c0dc0d11da3a6c39cb2dc848
Reviewed-on: https://go-review.googlesource.com/c/go/+/412094
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-06-14 23:44:35 +00:00
Robert Griesemer
5ee939b819 spec: clarify behavior of map size hint for make built-in
The spec already states that the precise behavior of the map size
hint provided to the make built-in is implementation-dependent.

Exclude requiring specific run-time behavior for maps.
(The current Go compiler does not panic if the size hint is negative
at run-time.)

Fixes #53219.

Change-Id: I2f3618bf9ba4ed921e18dc4f2273eaa770805bd7
Reviewed-on: https://go-review.googlesource.com/c/go/+/411919
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
2022-06-13 19:06:53 +00:00
Robert Griesemer
4703546a29 spec: add missing optional type arguments after TypeName in syntax
Types may be generic, so each occurrence of a TypeName may be
followed by optional type arguments. Add the missing syntactic
(EBNF) factor.

The syntax of type names followed by type arguments matches the
syntax of operand names followed by type arguments (operands may
also be types, or generic functions, among other things). This
opens the door to factoring out this shared syntax, but it will
also require some adjustments to prose to make it work well.
Leaving for another change.

Fixes #53240.

Change-Id: I15212225c28b27f7621e3ca80dfbd131f6b7eada
Reviewed-on: https://go-review.googlesource.com/c/go/+/411918
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
2022-06-13 19:06:49 +00:00
George Looshch
fd0ffedae2 doc: replace tabs with spaces for alignment in code snippets
Fixes #52255

Change-Id: Ibb518cf2f6bac9e1ffc426a014afe80cc4c0df5e
Reviewed-on: https://go-review.googlesource.com/c/go/+/399394
Reviewed-by: Jamal Carvalho <jamal@golang.org>
Reviewed-by: Robert Griesemer <gri@google.com>
2022-05-26 23:22:37 +00:00
Robert Griesemer
da0a6f4b57 spec: fix prose about promoted methods of embedded fields
The types of embedded fields must be named, but they don't
need to be defined types (e.g. if the type name is an alias).

Fixes #41687.

Change-Id: Ib9de65dfab0e23c27d8303875fa45c217aa03331
Reviewed-on: https://go-review.googlesource.com/c/go/+/406054
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
2022-05-12 22:29:02 +00:00
Robert Griesemer
f269d90bf2 spec: use original terminology in metasyntax (cleanup)
The metasyntax used in the spec is exactly the Wirth Syntax
Notation (WSN), which eventually influenced EBNF. Add a link
but keep mentioning EBNF which is likely more commonly known.

Use the original terms in the productions. Specifically, use
the words "Term" and "Factor" rather than "Alternative" and
"Term".

The terminology cleanup also resolves an inconsistency in the
subsequent prose which is referring to the correct "terms" now.

While at it, add a production for the entire Syntax itself,
matching the original WSN definition.

Also, replace the two uses of "grammar" with "syntax" for
consistency ("syntax" is the prevalent term used throughout
the spec).

Fixes #50074.

Change-Id: If770d5f32f56f509f85893782c1dafbb0eb29b2e
Reviewed-on: https://go-review.googlesource.com/c/go/+/405814
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2022-05-12 19:04:52 +00:00
Robert Griesemer
1dfe994fe9 spec: use Unicode terminology consistently
- refer to character "categories" rather than "classes" per the
  definitions in the Unicode standard
- use "uppercase", "lowercase" (one word) instead of "upper case"
  or "upper-case", matching the spelling in the Unicode standard
- clarify that that the blank character "_" is considered a lowercase
  letter for Go's purposes (export of identifiers)

Fixes #44715.

Change-Id: I54ef177d26c6c56624662fcdd6d1da60b9bb8d02
Reviewed-on: https://go-review.googlesource.com/c/go/+/405758
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-05-12 19:04:46 +00:00
Robert Griesemer
2bea43b0e7 spec: state that variable names must be unique in short var decls
Fixes #45652.

Change-Id: I5e1434480c12815369a6ce204f3729eb63139125
Reviewed-on: https://go-review.googlesource.com/c/go/+/405757
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2022-05-12 04:47:29 +00:00
Robert Griesemer
c01feba15d spec: clarify "continue" statement
Taking into account the discussion and relevant feedback on a
change proposed in 2013 (see e-mail thread mentioned in issue).

Fixes #48864.

Change-Id: I811d518b7cbdf6b815695174f1da3d4251f491c3
Reviewed-on: https://go-review.googlesource.com/c/go/+/405756
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2022-05-12 04:47:23 +00:00
Robert Griesemer
7e11ff3816 spec: correct assignment rules with respect to type parameters
Fixes #52628.

Change-Id: If4261abc25868d62f7689253d40f872692c23a4d
Reviewed-on: https://go-review.googlesource.com/c/go/+/405755
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
2022-05-12 04:47:18 +00:00
Robert Griesemer
5d0400c72d spec: adjust scope of function/method type parameters
Change scope rules per the accepted proposal #52038.
Match prose for type parameters of type declarations.
Fixing the implementation is tracked by #51503.

Fixes #52038.
For #51503.

Change-Id: Iebd88a82c896b7b2e8520cd514ef6a2cc903e807
Reviewed-on: https://go-review.googlesource.com/c/go/+/405754
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-05-12 04:47:13 +00:00
Robert Griesemer
0e08b02ac5 spec: clarify rules for type set construction of an interface
Be explicit that we always mean non-interface types when we
talk about sets of types.

Also, clarify that the quantification "all non-interface types"
means all such types in all possible programs, not just the
current program.

Per suggestion from Philip Wadler.

Change-Id: Ibc7b5823164e547bfcee85d4e523e58c7c27ac8a
Reviewed-on: https://go-review.googlesource.com/c/go/+/398655
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
2022-04-19 23:42:38 +00:00
Jared Horvat
0b3cb1a56c doc/go_spec.html: update type identity example
In the Type identity section, the example provides various types as givens.

The example refers to the type *T5, but it is not provided in the givens.

I am assuming this was a typo, and was meant to refer to *A1 or *B1.
*B1 seems to be in alignment with the rest of the provided examples.

Change-Id: I554319ee8bca185c3643559321417e8b2a544ba0
GitHub-Last-Rev: e80560d32a
GitHub-Pull-Request: golang/go#52143
Reviewed-on: https://go-review.googlesource.com/c/go/+/398075
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Ian Lance Taylor <iant@golang.org>
2022-04-04 21:36:50 +00:00
Zach Collier
01c83be793 doc: add illegal octal over 255 example
Octal values over 255, like \400 or \777, are illegal.  It wasn't clear if the expected behavior was a compile error, encoding the value as two characters, or if the value would be capped at 255.

This example explicitly shows that octal values over 255 are illegal.

Change-Id: I45d94680107029c5f083e5d434e6270cc5b258c1
GitHub-Last-Rev: f6bef0379f
GitHub-Pull-Request: golang/go#52111
Reviewed-on: https://go-review.googlesource.com/c/go/+/397555
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Emmanuel Odeke <emmanuel@orijtech.com>
2022-04-02 17:45:45 +00:00
Robert Griesemer
ea858734be spec: clarify type term restriction for type parameters
Be clear that the type of a term (not the term itself, which may
be of the form ~P) cannot be a type parameter.

For #50420.

Change-Id: I388d57be0618393d7ebe2c74ec04c1ebe3f33f7d
Reviewed-on: https://go-review.googlesource.com/c/go/+/396915
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-03-31 01:01:43 +00:00
Robert Griesemer
fe75fe3c7a spec: various minor clarifications
- Allow for a type parameter as length/capacity to make.
- Be slightly more precise in prose for append.
- Add a couple of links.

Change-Id: Ib97e528bab1ab55d271beeeb53d9bb7a07047b9b
Reviewed-on: https://go-review.googlesource.com/c/go/+/391754
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2022-03-11 06:00:18 +00:00
Robert Griesemer
59d80227ef spec: clean up intro and replace bolded text with prose
- Remove "Draft" disclaimer. We're not done but the spec
  is in usable shape with respect to generics features.

- Remove section on "Earlier version" and fold information
  into the "Intro" section.

- Remove caveat for shifts: the rules for arithmetic operators
  on type parameters apply for them as well.

- Simply state that we don't support arguments of type parameter
  type for the built-ins real, imag, and complex.

Fixes #51182.

Change-Id: I6df1427de685cfe7055b64e91753aa7ebff70565
Reviewed-on: https://go-review.googlesource.com/c/go/+/391695
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2022-03-11 06:00:14 +00:00
Robert Griesemer
00535b8398 spec: remove note re: field accesses on type literals
For #51576.

Change-Id: I43f72c3fb618e724d46360a70ab9f8abc3d63273
Reviewed-on: https://go-review.googlesource.com/c/go/+/391137
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2022-03-10 01:57:27 +00:00
Robert Griesemer
6fb07317e5 spec: more adjustments/corrections
- Change section title from "Type parameters lists" to
  "Type parameter declarations" as the enclosing section
  is about declarations.

- Correct section on parsing ambiguity in type parameter
  lists.

- Rephrase paragraphs on type parameters for method receivers
  and adjust examples.

- Remove duplicate prose in section on function argument type
  inference.

- Clarified "after substitution" column in Instantiations section.

Change-Id: Id76be9804ad96a3f1221e5c4942552dde015dfcb
Reviewed-on: https://go-review.googlesource.com/c/go/+/390994
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2022-03-10 01:57:22 +00:00
Robert Griesemer
46f352de2d spec: remove notion of specific types
Specific types were introduced to explain rules for operands of
type parameter type. Specific types are really an implementation
mechanism to represent (possibly infinite) type sets in the machine;
they are not needed in the specification.

A specific type is either standing for a single named or unnamed
type, or it is the underlying (unnamed) type of an infinite set of
types. Each rule that applies to a type T of the set of specific
types must also apply to all types T' in the type set for which T
is a representative of. Thus, in the spec we can simply refer to
the type set directly, infinite or not.

Rather then excluding operands with empty type sets in each instance,
leave unspecified what happens when such an operand is used. Instead
give an implementation some leeway with an implementation restriction.

(The implementation restriction also needs to be formulated for types,
such as in conversions, which technically are not "operands". Left for
another CL.)

Minor: Remove the two uses of the word "concrete" to refer to non-
interface types; instead just say "non-interface type" for clarity.

Change-Id: I67ac89a640c995369c9d421a03820a0c0435835a
Reviewed-on: https://go-review.googlesource.com/c/go/+/390694
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2022-03-10 01:57:17 +00:00
Robert Griesemer
6e63be7b69 spec: document that type inference doesn't apply to generic types
Type inference for types was always a "nice to have" feature.
Given the under-appreciated complexity of making it work in all
cases, and the fact that we don't have a good understanding of
how it might affect readability of generic code, require explicit
type arguments for generic types.

This matches the current implementation.

Change-Id: Ie7ff6293d3fbea92ddc54c46285a4cabece7fe01
Reviewed-on: https://go-review.googlesource.com/c/go/+/390577
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>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-03-08 02:22:37 +00:00