1
0
mirror of https://github.com/golang/go synced 2024-11-06 04:36:15 -07:00
Commit Graph

681 Commits

Author SHA1 Message Date
Robert Griesemer
a287c4aa38 spec: add type parameter types
- add section on type parameters
- added two sections on the scope of type parameters
- expanded general section on types accordingly
- introduced the notion of a named type which will
  help in simplifying various rules (subsequent CLs)

Change-Id: I49c1ed7d6d4f951d751f0a3ca5dfb637e49829f2
Reviewed-on: https://go-review.googlesource.com/c/go/+/365414
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-11-22 03:24:07 +00:00
Robert Griesemer
0c3b4a358a spec: add type parameter lists
Change-Id: I29e9188a0fa1326c2755a9b86aeb47feaa8019be
Reviewed-on: https://go-review.googlesource.com/c/go/+/365274
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-11-22 03:24:01 +00:00
Robert Griesemer
24898d6948 spec: various clarifications/fixes for method sets and interfaces
- fixed a typo in the method set section
- express in the syntax that ~T denotes an underlying type
- be more precise when talking about types vs type terms
- refer to "unions" rather than "union expressions"
- make it clear in the spec title that this is WIP

Change-Id: I9b2c4b1f77bc50dd574ed6893bedd40529c320fc
Reviewed-on: https://go-review.googlesource.com/c/go/+/365154
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-11-18 20:11:45 +00:00
Robert Griesemer
f6647f2e3b spec: generalize method sets and interface types to type sets
This is the first of several CLs that update the existing
Go 1.17 spec for type parameters.

This CL updates the section on method sets and interface types.
It also adds "any", "comparable" to the list of predeclared
identifiers.

Change-Id: I0ce25dc02791c33150c0d949528512610faf3eab
Reviewed-on: https://go-review.googlesource.com/c/go/+/362999
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-11-18 06:05:29 +00:00
Robert Griesemer
d60a4e69f1 spec: fix a broken link
Thanks for jtagcat@ for finding this.

Change-Id: If7324808edbae19ec8bf503b04e0426f3fb3b47a
Reviewed-on: https://go-review.googlesource.com/c/go/+/363394
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-11-11 19:44:13 +00:00
Keith Randall
22951fbc89 cmd/compile: make for loops with range statements not terminating
Fixes #49003

Change-Id: If09c6f028dce5440b1be238612653ffdd626113a
Reviewed-on: https://go-review.googlesource.com/c/go/+/356189
Trust: Keith Randall <khr@golang.org>
Reviewed-by: roger peppe <rogpeppe@gmail.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2021-10-15 19:54:44 +00:00
Robert Griesemer
5402b4376c spec: fix incorrect type in a shift example
Thanks to @bodar (Github) for finding this.

Fixes #48422.

Change-Id: I031c3d82a02db1d204e2b86b494d89784d37f073
Reviewed-on: https://go-review.googlesource.com/c/go/+/350409
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-09-16 23:13:48 +00:00
Robert Griesemer
9a58aa267e spec: fix prose about terminating statements
CL 85215 added prose to provide some minimal intuition for the
definition of a "terminating statement". While the original definition
was perfectly fine, the added prose was actually incorrect: If the
terminating statement is a goto, it might jump to a labeled statement
following that goto in the same block (it could be the very next
statement), and thus a terminating statement does not in fact
"prevent execution of all statements that lexically appear after
it in the same block".

Rather than explaining the special case for gotos with targets that
are lexically following the goto in the same block, this CL opts for
a simpler approach.

Thanks to @3bodar (Github) for finding this.

Fixes #48323.

Change-Id: I8031346250341d038938a1ce6a75d3e687d32c37
Reviewed-on: https://go-review.googlesource.com/c/go/+/349172
Trust: Robert Griesemer <gri@golang.org>
Trust: Emmanuel Odeke <emmanuel@orijtech.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-09-13 22:57:34 +00:00
seifchen
592ee433f5 spec: adjust example for consistency
Change-Id: I5ff9078907b78f31aec42abf749a193b15bc5109
GitHub-Last-Rev: 1f96d84f20
GitHub-Pull-Request: golang/go#47732
Reviewed-on: https://go-review.googlesource.com/c/go/+/342789
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Cherry Mui <cherryyz@google.com>
2021-09-01 19:23:15 +00:00
Cuong Manh Le
aeec6dbfe0 spec: add example for method value in case of embedded method
So it's clear to the reader that if "M" is a promoted method from
embedded field "T", then "x.M" will be expanded to "x.T.M" during the
evaluation of the method value.

Fixes #47863

Change-Id: Id3b82127a2054584b6842c487f6e15c3102dc9fe
Reviewed-on: https://go-review.googlesource.com/c/go/+/344209
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-08-23 17:29:25 +00:00
Cuong Manh Le
507cc341ec doc: add example for conversion from slice expressions to array ptr
Fixes #47599

Change-Id: I8f4ccd3b0c2bcdb057ee853163b4421229141333
Reviewed-on: https://go-review.googlesource.com/c/go/+/340351
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2021-08-08 18:37:08 +00:00
Cuong Manh Le
ecaa6816bf doc: clarify non-nil zero length slice to array pointer conversion
There is an example for nil slice already, so adding example for non-nil
zero length slice, too, clarifying to the reader that the result is also
non-nil and different from nil slice case.

Updates #395

Change-Id: I019db1b1a1c0c621161ecaaacab5a4d888764b1a
Reviewed-on: https://go-review.googlesource.com/c/go/+/336890
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-07-26 17:47:47 +00:00
Ian Lance Taylor
849b791129 spec: use consistent capitalization for rune literal hex constants
Fixes #47368

Change-Id: I2f65c0008658532123f04d08e99e5d083f33461a
Reviewed-on: https://go-review.googlesource.com/c/go/+/337234
Trust: Ian Lance Taylor <iant@golang.org>
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-07-25 17:16:20 +00:00
Piers
c8f4e6152d spec: correct example comment in Conversions from slice to array
Fixes #47280

Change-Id: I78a8d235949b4878c7f075ac4ca37700e7e6c31c
GitHub-Last-Rev: 067f96eeb2
GitHub-Pull-Request: golang/go#47282
Reviewed-on: https://go-review.googlesource.com/c/go/+/335470
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Robert Griesemer <gri@golang.org>
Trust: Than McIntosh <thanm@google.com>
2021-07-19 21:59:24 +00:00
Ian Lance Taylor
743f03eeb0 spec, unsafe: clarify unsafe.Slice docs
For #19367

Change-Id: If0ff8ddba3b6b48e2e198cf3653e73284c7572a3
Reviewed-on: https://go-review.googlesource.com/c/go/+/332409
Trust: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2021-07-02 19:26:52 +00:00
Matthew Dempsky
1519271a93 spec: change unsafe.Slice((*T)(nil), 0) to return []T(nil)
Updates #46742.

Change-Id: I044933a657cd1a5cdb29863e49751df5fe9c258a
Reviewed-on: https://go-review.googlesource.com/c/go/+/331069
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Trust: Matthew Dempsky <mdempsky@google.com>
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-06-28 23:31:05 +00:00
Robert Griesemer
5bd09e5efc spec: unsafe.Add/Slice are not permitted in statement context
Add unsafe.Add and unsafe.Slice to the list of built-in functions
which are not permitted in statement context. The compiler and
type checker already enforce this restriction, this just fixes
a documentation oversight.

For #19367.
For #40481.

Change-Id: Iabc63a8db048eaf40a5f5b5573fdf00b79d54119
Reviewed-on: https://go-review.googlesource.com/c/go/+/329925
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Rob Pike <r@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
2021-06-22 16:01:58 +00:00
DQNEO
e1fa26026d spec: improve wording consistency by eliminating "specifier"
The word "specifier" is used once only here and technically not defined.

Change-Id: Ifc9f0582f4eb3c3011ba60d8008234de511d4be6
Reviewed-on: https://go-review.googlesource.com/c/go/+/323730
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Ian Lance Taylor <iant@golang.org>
Trust: Robert Griesemer <gri@golang.org>
2021-06-05 19:52:26 +00:00
DQNEO
f490134126 spec: improve wording by choosing an official term "keyword"
Replace "reserved word" by "keyword" as the latter is the official term.

Change-Id: I9f269759b872026034a9f47e4a761cff2d348ca0
Reviewed-on: https://go-review.googlesource.com/c/go/+/323729
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Ian Lance Taylor <iant@golang.org>
Trust: Robert Griesemer <gri@golang.org>
2021-06-05 19:51:45 +00:00
Robert Griesemer
764f53eb6c spec: clarify conditions for switch expression type
1. The existing prose implied that a switch expression type must
   be comparable because it is tested for equality against all case
   expressions. But for an empty switch (no case expressions), it
   was not clear if the switch expression needed to be comparable.
   Require it to match the behavior of compiler and type checkers.

2. While making this change, remove redundant language explaining
   what happens with untyped boolean switch expression values: the
   default type of an untyped boolean value is bool, this is already
   covered by the first part of the relevant sentence.

Fixes #43200.

Change-Id: Id8e0f29cfa8722b57cd2b7b58cba85b58c5f842b
Reviewed-on: https://go-review.googlesource.com/c/go/+/314411
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Rob Pike <r@golang.org>
2021-04-28 18:50:51 +00:00
lixianyang
c249491572 doc: change <a/> to </a> in spec
Change-Id: I21d0ee83c9204d51c587bd944209df2232b460ad
GitHub-Last-Rev: 47fab8dc58
GitHub-Pull-Request: golang/go#45771
Reviewed-on: https://go-review.googlesource.com/c/go/+/313449
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-04-27 04:44:55 +00:00
Matthew Dempsky
1da05eb0ce spec: add unsafe.Add and unsafe.Slice
Updates #19367.
Updates #40481.

Change-Id: I578066ad68d2cd6bea50df1a534cf799e4404a7f
Reviewed-on: https://go-review.googlesource.com/c/go/+/312212
Trust: Matthew Dempsky <mdempsky@google.com>
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
2021-04-22 22:03:10 +00:00
Josh Bleecher Snyder
1c268431f4 spec: allow conversion from slice to array ptr
Implementation follows in subsequent changes.

Updates #395

Change-Id: Ic97ee822805e4c236fdd9d224e776cb2ae62c817
Reviewed-on: https://go-review.googlesource.com/c/go/+/216424
Trust: Josh Bleecher Snyder <josharian@gmail.com>
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
2021-04-20 23:47:34 +00:00
Robert Griesemer
63b0a0a5b8 spec: fix rendering of >=
Follow-up on https://golang.org/cl/297249.

Change-Id: Ib4df91df530e4e7d7dd8c54d89c834cee55031f8
Reviewed-on: https://go-review.googlesource.com/c/go/+/302370
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
2021-03-17 00:18:28 +00:00
nobishino
13a0f7b502 spec: clarify that signed integers>=0 are permitted as shift counts
In Go1.13 and above, signed integers are permitted as shift counts as long as they are >=0.
However, the comments in the "Arithmetic operators" section says shift operators accept "unsigned integer" as of right operands. Replacing this with "integer>=0" resolves the misunderstanding that shift
operators permit only unsigned integers.

Reference: Go1.13 Release Notes: https://golang.org/doc/go1.13

Change-Id: Icd3c7734d539ab702590e992a618c9251c653c37
GitHub-Last-Rev: 4f263a48d3
GitHub-Pull-Request: golang/go#44664
Reviewed-on: https://go-review.googlesource.com/c/go/+/297249
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Emmanuel Odeke <emmanuel@orijtech.com>
Trust: Robert Griesemer <gri@golang.org>
2021-03-16 19:51:31 +00:00
DQNEO
084b07d6f6 spec: improve sentence structure for passing a slice
Change-Id: I453d06da2f596eb0b99905aec46a05547d73c62c
Reviewed-on: https://go-review.googlesource.com/c/go/+/290872
Trust: Emmanuel Odeke <emmanuel@orijtech.com>
Trust: Robert Griesemer <gri@golang.org>
Trust: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
2021-02-24 05:23:32 +00:00
Robert Griesemer
078f08f0ee spec: every type has a method set (minor clarification)
The spec states that a type "may" have a method set associated with it.
Yet every type has a method set, which may be empty. This is clarified
later in the same paragraph. Be clear in the first sentence as well.

Per the suggestion from https://github.com/DQNEO.

Fixes #44318.

Change-Id: I6097b1c7062853e404b7fead56d18a7f9c576fc3
Reviewed-on: https://go-review.googlesource.com/c/go/+/292853
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-02-20 00:01:22 +00:00
DQNEO
26ceae85a8 spec: More precise wording in section on function calls.
A caller is not always in a function.

For example, a call can appear in top level declarations.

e.g. var x = f()

Change-Id: I29c4c3b7663249434fb2b8a6d0003267c77268cf
Reviewed-on: https://go-review.googlesource.com/c/go/+/290849
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Robert Griesemer <gri@golang.org>
2021-02-11 17:55:50 +00:00
task4233
fca94ab3ab spec: improve the example in Type assertions section
The example, var v, ok T1 = x.(T), can be interpreted as type T1 interface{} or type T = bool; type T1 = T.
Separating the example would help understanding for readers.

Change-Id: I179f4564e67f4d503815d29307df2cebb50c82f9
GitHub-Last-Rev: b34fffb6bb
GitHub-Pull-Request: golang/go#44040
Reviewed-on: https://go-review.googlesource.com/c/go/+/288472
Reviewed-by: Robert Griesemer <gri@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Robert Griesemer <gri@golang.org>
2021-02-02 16:35:53 +00:00
Robert Griesemer
2b9b2720b8 spec: split shift examples into groups for 32- and 64-bit ints
In the current (pre-CL) version of the spec, the 2nd last shift
example appears to be using the array declared in the last example.
On a 32-bit platform, that array would have length 0, which would
lead to a panic in the 2nd last example. Also, if this code were
inside a function, it wouldn't compile (array declared after use).

Use an explicitly declared array for that specific shift example.
Also, split out all cases that produce different results for 32-
vs 64-bit ints.

Fixes #41835.

Change-Id: Ie45114224509e4999197226f91f7f6f934449abb
Reviewed-on: https://go-review.googlesource.com/c/go/+/260398
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-10-30 16:20:05 +00:00
Robert Griesemer
23cc16cdd2 spec: better variable name for operator example
Suggested by @yaxinlx.

Fixes #41612.

Change-Id: I98b9968a95d090ee3c67ff02678e1874e6d98c33
Reviewed-on: https://go-review.googlesource.com/c/go/+/257159
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-09-24 20:41:14 +00:00
yah01
ee55dd6b64 spec: add missing space in EBNF
Fixes #36520

Change-Id: I698ab235f82f7c81caa09318c954847cf3833153
GitHub-Last-Rev: 368a1dc788
GitHub-Pull-Request: golang/go#36559
Reviewed-on: https://go-review.googlesource.com/c/go/+/214821
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-01-15 05:32:51 +00:00
Rob Pike
cae9a9fd65 doc: fix up some HTML issues in go_spec.html
The HTML linter 'tidy' reports:

	go_spec.html:2556: Warning: unescaped & which should be written as &amp;
	go_spec.html:3293: Warning: unescaped & or unknown entity "&s1"
	go_spec.html:3293: Warning: unescaped & or unknown entity "&a"
	go_spec.html:3294: Warning: unescaped & or unknown entity "&s2"
	go_spec.html:3294: Warning: unescaped & or unknown entity "&a"
	go_spec.html:2045: Warning: trimming empty <p>
	go_spec.html:4526: Warning: trimming empty <ul>
	go_spec.html:4533: Warning: trimming empty <ul>
	go_spec.html:4539: Warning: trimming empty <ul>

This CL fixes all but the <ul> ones, which I think should be fixed
but are defended by a comment.

Change-Id: I0ca88f5e80755024801877ab1298025ecf8f10c5
Reviewed-on: https://go-review.googlesource.com/c/go/+/214457
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
2020-01-14 22:24:11 +00:00
Robert Griesemer
9ead772a92 spec: uniformly format empty interfaces as "interface{}"
Fixes #36526.

Change-Id: Ic51a287579f139422cc1a7b2fb82d6732114b031
Reviewed-on: https://go-review.googlesource.com/c/go/+/214597
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-01-13 21:49:46 +00:00
Alberto Donizetti
7d30af8e17 spec: reword claim about the grammar being regular
Since the word "regular" has a precise meaning in the context of
formal languages, the Introduction sentence claiming that Go's grammar
is "compact and regular" may mislead readers.

Reword it using Rob's suggestion.

Fixes #36037

Change-Id: I00c1a5714bdab8878d9a77b36d67dae67d63da0f
Reviewed-on: https://go-review.googlesource.com/c/go/+/211277
Reviewed-by: Robert Griesemer <gri@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
2019-12-13 20:41:04 +00:00
Robert Griesemer
6fcc2d85be spec: clarify that shift count must be non-negative
Fixes #34056.

Change-Id: I2c9b7a20d19f458df5dcc376e29bee6be1f09f7a
Reviewed-on: https://go-review.googlesource.com/c/go/+/193277
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-09-04 16:01:24 +00:00
Robert Griesemer
bc405df391 spec: allow embedding overlapping interfaces
Updates #6977.

Change-Id: I6eda4be550e7c7ea1e1bac3222850002d90a81a8
Reviewed-on: https://go-review.googlesource.com/c/go/+/190378
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2019-08-26 16:39:30 +00:00
Robert Griesemer
39d4178735 spec: add an example of a trivially invalid interface
In preparation for the forthcoming spec changes for #6977.
While at it, modernize existing File example that dates
back all the way to commit 18c5b488a3.

Change-Id: Id10e4df0513e3de15bd58867222923eefa9473ea
Reviewed-on: https://go-review.googlesource.com/c/go/+/187978
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-07-31 05:45:43 +00:00
Robert Griesemer
1e3ffb0c90 spec: clarify that slice a expression shares underlying array with operand
The spec was not very precise as to what happens with respect to sharing
if a sliced operand is (a pointer to) an array. Added a small clarification
and a supporting example.

Fixes #31689.

Change-Id: Ic49351bec2033abd3f5428154ec3e9a7c2c9eaa5
Reviewed-on: https://go-review.googlesource.com/c/go/+/177139
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2019-05-14 22:30:48 +00:00
Robert Griesemer
eebb9db0ef spec: clarify the difference between &T{} and new(T)
Add a small paragraph and example pointing out
the difference for the case where T is a slice
or map. This is a common error for Go novices.

Fixes #29425.

Change-Id: Icdb59f25361e9f6a09b190fbfcc9ae0c7d90077b
Reviewed-on: https://go-review.googlesource.com/c/go/+/176338
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2019-05-13 21:24:51 +00:00
Robert Griesemer
451cf3e2cd spec: clarify language on package-level variable initialization
The very first paragraph on "Package initialization" stated that
"variables are initialized in declaration order, but after any
variables they might depend on". This phrasing was easily
misread as "declaration order is the first sorting criteria"
and then contradicted what the subsequent paragraphs spelled
out in precise detail.

Instead, variable initialization proceeds by repeatedly determining
a set of ready to initialize variables, and then selecting from that
set the variable declared earliest. That is, declaration order is the
second sorting criteria.

Also, for the purpose of variable initialization, declarations
introducing blank (_) variables are considered like any other
variables (their initialization expressions may have side-effects
and affect initialization order), even though blank identifiers
are not "declared".

This CL adds clarifying language regarding these two issues
and the supporting example.

Both gccgo and go/types implement this behavior. cmd/compile
has a long-standing issue (#22326).

The spec also did not state in which order multiple variables
initialized by a single (multi-value) initialization expression are
handled. This CL adds a clarifying paragraph: If any such variable
is initialized, all that declaration's variables are initialized at
the same time.

This behavior matches user expectation: We are not expecting to
observe partially initialized sets of variables in declarations
such as "var a, b, c = f()".

It also matches existing cmd/compile and go/types (but not gccgo)
behavior.

Finally, cmd/compile, gccgo, and go/types produce different
initialization orders in (esoteric) cases where hidden (not
detected with existing rules) dependencies exist. Added a
sentence and example clarifying how much leeway compilers have
in those situations. The goal is to preserve the ability to
use static initialization while at the same time maintain
the relative initialization order of variables with detected
dependencies.

Fixes   #31292.
Updates #22326.

Change-Id: I0a369abff8cfce27afc975998db875f5c580caa2
Reviewed-on: https://go-review.googlesource.com/c/go/+/175980
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2019-05-13 20:57:02 +00:00
Robert Griesemer
1024b25d0c spec: clarify wording on passing slice arguments to variadic functions
Per discussion on #30769.

Fixes #30769.

Change-Id: I620dbac936de1a0b5deec03926dd11d690a918e5
Reviewed-on: https://go-review.googlesource.com/c/go/+/167380
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Rob Pike <r@golang.org>
2019-03-14 00:32:43 +00:00
Robert Griesemer
a083648165 spec: document new Go2 number literals
This CL documents the new binary and octal integer literals,
hexadecimal floats, generalized imaginary literals and digit
separators for all number literals in the spec.

Added empty lines between abutting paragraphs in some places
(a more thorough cleanup can be done in a separate CL).

A minor detail: A single 0 was considered an octal zero per the
syntax (decimal integer literals always started with a non-zero
digit). The new octal literal syntax allows 0o and 0O prefixes
and when keeping the respective octal_lit syntax symmetric with
all the others (binary_lit, hex_lit), a single 0 is not automatically
part of it anymore. Rather than complicating the new octal_lit syntax
to include 0 as before, it is simpler (and more natural) to accept
a single 0 as part of a decimal_lit. This is purely a notational
change.

R=Go1.13

Updates #12711.
Updates #19308.
Updates #28493.
Updates #29008.

Change-Id: Ib9fdc6e781f6031cceeed37aaed9d05c7141adec
Reviewed-on: https://go-review.googlesource.com/c/go/+/161098
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-03-12 16:13:39 +00:00
Robert Griesemer
a10b4cff91 spec: document signed integer shift counts
Updates #19113.

Change-Id: I4726f51c5061c33979cdd061f6d4616fa97edb9a
Reviewed-on: https://go-review.googlesource.com/c/161201
Reviewed-by: Rob Pike <r@golang.org>
2019-02-17 04:46:20 +00:00
Russ Cox
b7ba523355 doc/go_spec: tweak wording to avoid 'explicit assignment' misreading
This text changed in CL 139099 to add "explicit" in front of "conversion".
But now "explicit conversion or assignment" reads like it might mean
"explicit [conversion or assignment]" when what is meant is
"[explicit conversion] or assignment". To make clear that explicit does
not apply to assignment, use "assignment or explicit conversion".

Change-Id: I8ff7a5b3ecd9f562793502fa6808242f22264f28
Reviewed-on: https://go-review.googlesource.com/c/149340
Reviewed-by: Robert Griesemer <gri@golang.org>
2018-11-16 17:50:06 +00:00
Robert Griesemer
de578dcdd6 spec: be clearer about definition of string length
Adjusted spec to explicitly define the string length as the
number of bytes of the string; the prose now matches the prose
for arrays. Made analogous change for slices.

Fixes #28736.

Change-Id: I47cab321c87de0a4c482f5466b819b2cc8993fd1
Reviewed-on: https://go-review.googlesource.com/c/149077
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2018-11-13 00:42:32 +00:00
Robert Griesemer
1e38ecdbbe spec: refer to "run-time panic" rather than "exception" (cleanup)
Fixes #28341.

Change-Id: If8ae844c9b5e843ce9229c0a555f7006426baed7
Reviewed-on: https://go-review.googlesource.com/c/144260
Reviewed-by: Rob Pike <r@golang.org>
2018-10-23 23:03:59 +00:00
Robert Griesemer
bb3e211777 spec: clarify rules for receiver base types
The spec currently provides a syntactic rule for receiver base types,
and a strict reading of those rules prohibits the use of type aliases
referring to pointer types as receiver types.

This strict interpretation breaks an assumed rule for aliases, which
is that a type literal can always be replaced by an alias denoting
that literal.

Furthermore, cmd/compile always accepted this new formulation of the
receiver type rules and so this change will simply validate what has
been implemented all along.

Fixes #27995.

Change-Id: I032289c926a4f070d6f7795431d86635fe64d907
Reviewed-on: https://go-review.googlesource.com/c/142757
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2018-10-17 20:03:35 +00:00
Robert Griesemer
26d22609c3 spec: distinguish between explicit and implicit conversions (clarification)
The spec used the term "conversion" somewhat indiscriminately for
explicit conversions that appear literally in the source, and implicit
conversions that are implied by the context of an expression.
Be clearer about it by defining the terms.

Also, state that integer to string conversions of the form string(x)
are never implicit. This clarifies situations where implicit conversions
might require an integer to change to a string (but don't and never have
done so). See line 3948.

Fixes #26313.

Change-Id: I8939466df6b5950933ae7c987662ef9f88827fda
Reviewed-on: https://go-review.googlesource.com/c/139099
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-10-08 17:47:49 +00:00
Robert Griesemer
206fd7886b spec: be more precise about the moment deferred functions are executed
Fixes #27802.

Change-Id: I7ea9f7279300a55b0cb851893edc591a6f84e324
Reviewed-on: https://go-review.googlesource.com/136758
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-09-24 21:15:27 +00:00
Dina Garmash
8a2b5f1f39 doc: fix os.Pipe() call in the example.
Short variable declarations example passes an fd argument to os.Pipe call.
However, os.Pipe() takes no arguments and returns 2 Files and an error:
https://golang.org/src/os/pipe_linux.go?s=319:360#L1

Fixes: #27384

Change-Id: I0a709f51e0878c57185d901b899d209f001dfcce
Reviewed-on: https://go-review.googlesource.com/132284
Reviewed-by: Robert Griesemer <gri@golang.org>
2018-08-31 06:39:16 +00:00
Suriyaa Sundararuban
1041ac8781 doc: use HTTPS for links
Change-Id: I9d2d25df067ca573589db5ff18296a5ec33866be
Reviewed-on: https://go-review.googlesource.com/118595
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-06-13 13:45:01 +00:00
Bryan C. Mills
df48003618 spec: clarify “Constant expressions” for untyped operands
This change addresses the grammatical complexity described in
https://groups.google.com/forum/#!topic/golang-dev/RmP-LMC3g58.

Change-Id: Ib292b4ca9c880c7c1c8c992e7c033a0f8f951f2c
Reviewed-on: https://go-review.googlesource.com/106855
Reviewed-by: Robert Griesemer <gri@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
2018-05-09 20:36:22 +00:00
Andrew Bonventre
7974f0815e Revert "doc: remove non-prime from list of primes in spec"
This reverts commit 4b06d9d727.

Reason for revert: It's a reference to a legendary article
from the Journal of Irreproducible Results.

Updates golang/go#24451

Change-Id: I0288177f4e286bd6ace5774f2e5e0acb02370305
Reviewed-on: https://go-review.googlesource.com/101495
Reviewed-by: Andrew Bonventre <andybons@golang.org>
2018-03-19 21:51:23 +00:00
Andrew Bonventre
4b06d9d727 doc: remove non-prime from list of primes in spec
Fixes golang/go#24451

Change-Id: Id9b4cbd1a1ff032f1cc4606e9734ddcc64892ae5
Reviewed-on: https://go-review.googlesource.com/101457
Reviewed-by: Filippo Valsorda <filippo@golang.org>
2018-03-19 18:26:12 +00:00
Yazen2017
a4e950ec9e doc: improve clarity of map index examples
The fourth example for map indexing states you have a map of type [K]V
and attempts to read in a variable of type T.  Further, the example
is meant to showcase the boolean return variable saying whether the
map contained a key, but overrides to type T.  This will not compile.

Changed last updated date to February 18

Fixes: #23895

Change-Id: I63c52adbcd989afd4855e329e6c727f4c01f7881
Reviewed-on: https://go-review.googlesource.com/94906
Reviewed-by: Robert Griesemer <gri@golang.org>
2018-02-19 05:48:39 +00:00
Robert Griesemer
851e98f0ee spec: remove need for separate Function production (cleanup)
The EBNF production

	Function = Signature FunctionBody .

was used in FunctionDecl, MethodDecl, and FunctionLit, but only
for the latter it shortened the syntax slightly.

This change "inlines" Function which simplifies FunctionDecl and
MethodDecl and gets rid of the Function production.

This has no impact on the specified language. Also, the Function
production is never referred to by the prose, so it's safe to
remove it from the spec.

Finally, neither go/ast nor go/parser have a representation of
this production via a corresponding node or parse function, so
no possibly valuable documentation is lost, either.

Change-Id: Ia2875d31c6ec2d2079081ef481e50bad4f43c694
Reviewed-on: https://go-review.googlesource.com/91515
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
2018-02-02 00:22:16 +00:00
Robert Griesemer
9b49ac0366 spec: consistently use "defined type" and "type name" (cleanup)
When we introduced the notion of alias type declarations, we renamed
"named type" to "defined type" to avoid confusion with types denoted
by aliases and thus are also types with names, or "named types".

Some of the old uses of "named types" remained; this change removes
them.

Now the spec consistently uses the terms:

- "defined type"  for a type declared via a type definition
- "type name"     for any name denoting an (alias or defined) type
- "alias"         for a type name declared in an alias declaration

New prose is encouraged to avoid the term "named type" to counter-
act further confusion.

Fixes #23474.

Change-Id: I5fb59f1208baf958da79cf51ed3eb1411cd18e03
Reviewed-on: https://go-review.googlesource.com/89115
Reviewed-by: Rob Pike <r@golang.org>
2018-01-23 17:39:18 +00:00
Robert Griesemer
18d527b3f0 spec: mention that special case for integer division is due to overflow
Fixes #23443.

Change-Id: If60c39b582ee5308e9fa902f93c1b6ae7890346c
Reviewed-on: https://go-review.googlesource.com/87975
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
2018-01-17 18:59:44 +00:00
Robert Griesemer
c13e0e8cee spec: remove example explaining that type B0 and B0 are identical
Every few months we get a new error report claiming that there
is a typo in the spec related to this specific example. Clearly,
the fact that two types with the same identifier are identical
seems exceedingly obvious to readers; thus the example seems not
worth the trouble. Removing it.

For #9226.
For #22202.
For #22495.
For #23096.
For #23409.

There may be more.

Change-Id: I003ba79dc460ffb028a4ecb5f29efd60f2551912
Reviewed-on: https://go-review.googlesource.com/87417
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2018-01-11 21:04:11 +00:00
Robert Griesemer
8c916a2f6d spec: use consistent quoting style in prose
Fixes #23389.

Change-Id: Id6e86eebe44809db12a0e14014c474bf4fbf5108
Reviewed-on: https://go-review.googlesource.com/87035
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-01-09 23:31:06 +00:00
Robert Griesemer
4de1d1d5cd spec: consistently use "element" rather than "value" for map entry values
The spec refers to a map's key and element types; thus the respective
values are "keys" and "elements". Also, a map value is the value of
the entire map.

Similar fix for channels, where appropriate.

Fixes #23254.

Change-Id: I6f03ea6d86586c7b0b3e84f0c2e9446b8109fa53
Reviewed-on: https://go-review.googlesource.com/85999
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Russ Cox <rsc@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
2018-01-04 20:17:19 +00:00
Robert Griesemer
f3f507b2d8 spec: provide some (minimal) intuition for the notion of "terminating statement"
Fixes #23215.

Change-Id: Ib20825bf08915b4daaabbfd91f168e24973c512d
Reviewed-on: https://go-review.googlesource.com/85215
Reviewed-by: Rob Pike <r@golang.org>
2017-12-22 21:13:38 +00:00
griesemer
f2d52519e1 spec: match syntax for method expressions with implementations
A method expression is of the form T.m where T is a type and m
is a method of that type. The spec restricted T essentially to
a type name. Both cmd/compile and go/types accepted any type
syntactically, and a method expression was really just a form
of a selector expression x.f where x denotes a type.

This CL removes the spec syntax restriction from MethodExpr
to match the actual implementation. It also moves MethodExpr
from Operand to PrimaryExpr, because that's what it is.

It still keeps the separate notion of MethodExpr even though
it looks just like a selector expresion, since a MethodExpr
must start with a type rather than a value, and the spec's
syntax expresses this bit of semantics via distinct productions
(e.g., conversions look like calls but also must start with
a type).

Fixes #9060.

Change-Id: Idd84655b5b4f85d7ee53ebf749f73f0414a05f4a
Reviewed-on: https://go-review.googlesource.com/73233
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Russ Cox <rsc@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-10-25 22:49:03 +00:00
griesemer
0c5b00d0cd spec: remove sentence discussing existing implementations
Fixes #22282.

Change-Id: I4097e9cbd590ab6c8b1511a3b752c6ac98ac819b
Reviewed-on: https://go-review.googlesource.com/72792
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-10-23 21:39:03 +00:00
griesemer
85177f4276 spec: remove vestiges referring to iotas being incremented
https://golang.org/cl/71750 specifies iota values as indices,
thus making them independent from nested constant declarations.
This CL removes some of the comments in the examples that were
still referring to the old notion of iotas being incremented
and reset.

As an aside, please note that the spec still permits the use
of iota in a nested function (like before). Specifically, the
following cases are permitted by the spec (as before):

1) const _ = len([iota]int{})
2) const _ = unsafe.Sizeof(func(){ _ = iota })

For #15550.

Change-Id: I9e5fec75daf7b628b1e08d970512397e9c348923
Reviewed-on: https://go-review.googlesource.com/71912
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-10-19 22:22:55 +00:00
griesemer
52dd39965e spec: clarify that each block has its own version of iota
Issue #15550 is clearly an esoteric case but the spec was silent
about it and we had diverging implementations. By making `iota`
and index that is relative to the respective constant declaration,
nested const declarations won't affect outer values of `iota`.

cmd/compile and go/types already follow this semantics.

Fixes #15550.

Change-Id: If138189e3ea4373f8ba50ac6fb1d219b481f8698
Reviewed-on: https://go-review.googlesource.com/71750
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-10-19 15:30:37 +00:00
griesemer
ada6557593 spec: simplify paragraph on certain range expressions over arrays
Fixes #22258.

Change-Id: I43e68f1cf3163e1a041ebff2734ff2cb7943f695
Reviewed-on: https://go-review.googlesource.com/71431
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-10-19 00:29:56 +00:00
griesemer
ddc64def0f spec: explicitly state the import path for package unsafe
Nowhere in the spec did we mention the import path for package
unsafe. Now we do.

Fixes #22308.

Change-Id: Ifd42c873188e898c597cdee4284e7a9d234a9282
Reviewed-on: https://go-review.googlesource.com/71373
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-10-17 23:30:58 +00:00
griesemer
4a2391e7c9 spec: state which predeclared types are defined or alias types (clarification)
When we introduced the distinction between "defined" and "alias" types
we retained the notion of a "named" type (any type with a name). The
predeclared types (which all have names) simply remained named types.

This CL clarifies the spec by stating excplicitly which predeclared
types are defined types (or at least "act" like defined types), and
which ones are alias types.

Fixes #21785.

Change-Id: Ia8ae133509eb5d738e6757b3442c9992355e3535
Reviewed-on: https://go-review.googlesource.com/64591
Reviewed-by: Russ Cox <rsc@golang.org>
2017-09-19 14:33:25 +00:00
griesemer
9690d245d5 spec: clarify context type for certain non-constant shifts
The spec is not conclusive about whether a non-constant shift of
certain untyped constant left operands is valid when the shift
expression appears as an index in an index or slice expression,
or as a size in a `make` function call.

Despite identical spec rules in all these cases, cmd/compile accepts

	make([]byte, 1.0 << s)

but pronounces an error for

	a[1.0 << s]

(go/types accepts both).

This change clarifies the spec by explicitly stating that an
untyped constant left operand in a non-constant shift (1.0 in
the above examples) will be given type `int` in these contexts.

A separate issue #21693 addresses the cmd/compile bug.

Fixes #14844.

Change-Id: I4b52125e487a607fae377fcbed55463cdce9836c
Reviewed-on: https://go-review.googlesource.com/60230
Reviewed-by: Russ Cox <rsc@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-09-01 15:46:24 +00:00
griesemer
2ac43d5be2 doc: minor clarification regarding the sharing of underlying arrays
The last sentence in the section on slice expressions could be read
as if it might apply to strings. Changed the sentence a bit to
emphasize its applicability to slices only. See also the issue for
more background.

Fixes #19220.

Change-Id: I8551f34230e4ed93f951e7b871cc81f54a5874a9
Reviewed-on: https://go-review.googlesource.com/59890
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-08-30 15:24:12 +00:00
griesemer
b40831b115 spec: explicitly define notion of "representability" (clarification)
Throughout the spec we use the notion of a constant x being
representable by a value of type T. While intuitively clear,
at least for floating-point and complex constants types, the
concept was not well-defined. In the section on Conversions
there was an extra rule for floating-point types only and it
missed the case of floating-point values overflowing to an
infinity after rounding.

Since the concept is important to Go, and a compiler most
certainly will have a function to test "representability",
it seems warranted to define the term explicitly in the spec.

This change introduces a new entry "Representability" under
the section on "Properties of types and values", and defines
the term explicitly, together with examples.

The phrase used is "representable by" rather than "representable as"
because the former use is prevalent in the spec.

Additionally, it clarifies that a floating-point constant
that overflows to an infinity after rounding is never
representable by a value of a floating-point type, even though
infinities are valid values of IEEE floating point types.
This is required because there are not infinite value constants
in the language (like there is also no -0.0) and representability
also matters for constant conversions. This is not a language
change, and type-checkers have been following this rule before.

The change also introduces links throughout the spec to the new
section as appropriate and removes duplicate text and examples
elsewhere (Constants and Conversions sections), leading to
simplifications in the relevant paragraphs.

Fixes #15389.

Change-Id: I8be0e071552df0f18998ef4c5ef521f64ffe8c44
Reviewed-on: https://go-review.googlesource.com/57530
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-08-25 19:54:57 +00:00
griesemer
a9f832a6ae spec: clarify zero value for complex types
The enumeration of numeric types missed the complex types.
Clarify by removing the explicit enumeration and referring
to numeric types instead.

Fixes #21579.

Change-Id: If36c2421f8501eeec82a07f442ac2e16a35927ba
Reviewed-on: https://go-review.googlesource.com/58491
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
2017-08-25 08:12:51 +00:00
griesemer
84ac90ebf1 spec: clarify nil case in type switches
The old wording seemed to imply that nil is a kind of type.
Slightly reworded for clarity.

Fixes #21580.

Change-Id: I29898bf0125a10cb8dbb5c7e63ec5399ebc590ca
Reviewed-on: https://go-review.googlesource.com/58490
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Rob Pike <r@golang.org>
2017-08-25 08:09:57 +00:00
griesemer
5abc8c897c spec: better comment in example for type definition
The old comment for the example

	type PtrMutex *Mutex

talked about the method set of the base type of PtrMutex.
It's more direct and clearer to talk about the underlying
type of PtrMutex for this specific example.
Also removed link inside pre-formatted region of text.

Fixes #20900.

Change-Id: Ie37340e53670e34ebe13e780ba8ccb1bba67795c
Reviewed-on: https://go-review.googlesource.com/55070
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-08-14 13:35:43 +00:00
Robert Griesemer
4e9c86ab8e spec: minor grammar fix
Fixes #20830.

Change-Id: I18178064c955ad8d259df05ee954075ae42909b0
Reviewed-on: https://go-review.googlesource.com/47030
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2017-06-28 17:33:40 +00:00
Robert Griesemer
e4ce08afe0 spec: clarify restrictions on RHS of non-constant shifts
For non-constant shifts with an untyped constant shift count, the
spec only said that it must "be converted to unsigned integer type".
go/types accepts any (arbitrarily large) integer value. Both cmd/compile
and gccgo require that the shift count be representable as a uint value
in that case (if the shift count is typed, it may be any unsigned integer
type).

This change adjusts the spec to state what the compilers have been doing
all along. The new wording matches similar rules elsewhere (e.g., for
untyped array and slice indices). Also, while technically this is a
restriction (we could permit arbitrarily large shift counts), in practice
this is irrelevant.

Fixes #14822.

Change-Id: Ia75834c67483cf761c10025c8df758f225ef67c2
Reviewed-on: https://go-review.googlesource.com/45072
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-06-08 16:46:15 +00:00
Robert Griesemer
86f5f7fdfa spec: clarify unsafe.Pointer conversions
A pointer type of underlying type unsafe.Pointer can be used in
unsafe conversions. Document unfortunate status quo.

Fixes #19306.

Change-Id: I28172508a200561f8df366bbf2c2807ef3b48c97
Reviewed-on: https://go-review.googlesource.com/42132
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Russ Cox <rsc@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-05-09 18:35:13 +00:00
Brad Fitzpatrick
e963510330 spec: remove an unnecessary semicolon from code example
Change-Id: Ie4c92da0e3cbb97d3d7e03c7d15196c34f58a2cd
Reviewed-on: https://go-review.googlesource.com/42613
Reviewed-by: Robert Griesemer <gri@golang.org>
2017-05-04 02:46:51 +00:00
Robert Griesemer
50f67add81 spec: clarify admissible argument types for print, println
Fixes #19885.

Change-Id: I55420aace1b0f714df2d6460d2d1595f6863dd06
Reviewed-on: https://go-review.googlesource.com/42023
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
2017-04-28 16:37:31 +00:00
Robert Griesemer
94b6011c78 spec: clarify use of fused-floating point operations
Added a paragraph and examples explaining when an implementation
may use fused floating-point operations (such as FMA) and how to
prevent operation fusion.

For #17895.

Change-Id: I64c9559fc1097e597525caca420cfa7032d67014
Reviewed-on: https://go-review.googlesource.com/40391
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
2017-04-17 21:56:51 +00:00
Robert Griesemer
b0e5a0c93c spec: clarify size hint for make of maps
For #19903.

Change-Id: Ib28d08d45bfad653bcc1446f160b7b4a485529af
Reviewed-on: https://go-review.googlesource.com/40393
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
2017-04-13 16:15:45 +00:00
Robert Griesemer
369d1083a7 spec: for non-constant map keys, add reference to evaluation order section
The section on map literals mentions constant map keys but doesn't say
what happens for equal non-constant map keys - that is covered in the
section on evaluation order. Added respective link for clarity.

Fixes #19689.

Change-Id: If9a5368ba02e8250d4bb0a1d60d0de26a1f37bbb
Reviewed-on: https://go-review.googlesource.com/38598
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-03-24 18:51:10 +00:00
Robert Griesemer
26e726c309 spec: remove superfluous terms "delimiter" and "special tokens"
The (original) section on "Operators and Delimiters" introduced
superfluous terminology ("delimiter", "special token") which
didn't matter and was used inconsistently.

Removed any mention of "delimiter" or "special token" and now
simply group the special character tokens into "operators"
(clearly defined via links), and "punctuation" (everything else).

Fixes #19450.

Change-Id: Ife31b24b95167ace096f93ed180b7eae41c66808
Reviewed-on: https://go-review.googlesource.com/38073
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Rob Pike <r@golang.org>
2017-03-13 18:02:57 +00:00
Robert Griesemer
866f63e84e spec: refer to "not defined type" rather than "unnamed type" in conversions
We missed this in https://golang.org/cl/36213.
Thanks to Chris Hines for pointing it out.

For #18130.

Change-Id: I6279ab19966c4391c4b4458b21fd2527d3f949dd
Reviewed-on: https://go-review.googlesource.com/36691
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-02-10 01:23:13 +00:00
Robert Griesemer
e62aab1274 spec: clarify alignment of arrays
Fixes #18950.

Change-Id: I9f94748f36a896bcadc96f0642eb1f3bff387950
Reviewed-on: https://go-review.googlesource.com/36481
Reviewed-by: Russ Cox <rsc@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-02-07 16:28:06 +00:00
Robert Griesemer
c0bd4f33cc spec: pick up a few corrections missed in prior commit
This CL picks up a couple of minor fixes that were present
in https://go-review.googlesource.com/#/c/36213/6..5 but
accidentally got dropped in https://go-review.googlesource.com/#/c/36213/
because I submitted from the wrong client.

Change-Id: I3ad0d20457152ea9a116cbb65a23eb0dc3a8525e
Reviewed-on: https://go-review.googlesource.com/36471
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-02-07 00:03:00 +00:00
Robert Griesemer
56c9b51b93 spec: introduce alias declarations and type definitions
To avoid confusion caused by the term "named type" (which now just
means a type with a name, but formerly meant a type declared with
a non-alias type declaration), a type declaration now comes in two
forms: alias declarations and type definitions. Both declare a type
name, but type definitions also define new types.

Replace the use of "named type" with "defined type" elsewhere in
the spec.

For #18130.

Change-Id: I49f5ddacefce90354eb65ee5fbf10ba737221995
Reviewed-on: https://go-review.googlesource.com/36213
Reviewed-by: Rob Pike <r@golang.org>
2017-02-06 23:51:47 +00:00
Robert Griesemer
f8b4123613 [dev.typealias] spec: use term 'embedded field' rather than 'anonymous field'
First steps towards defining type aliases in the spec.
This is a nomenclature clarification, not a language change.

The spec used all three terms 'embedded type', 'anonymous field',
and 'embedded field'. Users where using the terms inconsistently.

The notion of an 'anonymous' field was always misleading since they
always had a de-facto name. With type aliases that name becomes even
more important because we may have different names for the same type.

Use the term 'embedded field' consistently and remove competing
terminology.

For #18130.

Change-Id: I2083bbc85788cab0b2e2cb1ff58b2f979491f001
Reviewed-on: https://go-review.googlesource.com/35108
Reviewed-by: Alan Donovan <adonovan@google.com>
Reviewed-by: Russ Cox <rsc@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
2017-01-31 17:12:17 +00:00
Robert Griesemer
b01f612a69 spec: add subtitles to section on "for" statements
This matches what we already do for switch statements and makes
this large section more visibly organized. No other changes besides
introducing the titles.

Fixes #4486.

Change-Id: I73f274e4fdd27c6cfeaed79090b4553e57a9c479
Reviewed-on: https://go-review.googlesource.com/33410
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-11-18 20:26:11 +00:00
Robert Griesemer
0eb26fa8ba spec: remove => (alias) operator from Operators and Delimiters section
(Revert of https://go-review.googlesource.com/#/c/32310/)

For #16339.
Fixes #17975.

Change-Id: I36062703c423a81ea1c5b00f4429a4faf00b3782
Reviewed-on: https://go-review.googlesource.com/33365
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-11-18 17:45:45 +00:00
Robert Griesemer
120cf676ca spec: clarify type elision rules for composite literals
- organize examples better
- add an example illustrating behavior if element type is a named pointer type
- both compilers and go/types (per https://go-review.googlesource.com/33358)
  follow this now

See the issue for detailed discussion.

Fixes #17954.

Change-Id: I8d90507ff2347d9493813f75b73233819880d2b4
Reviewed-on: https://go-review.googlesource.com/33361
Reviewed-by: Rob Pike <r@golang.org>
2016-11-18 17:25:07 +00:00
Robert Griesemer
87f4e36ce7 Revert "spec: add new language for alias declarations"
This reverts commit aff37662d1.

Reason: Decision to back out current alias implementation.
https://github.com/golang/go/issues/16339#issuecomment-258527920

Fixes #16339.
Fixes #17746.
Fixes #17784.

Change-Id: I5737b830d7f6fb79cf36f26403b4ad8533ba1dfe
Reviewed-on: https://go-review.googlesource.com/32813
Reviewed-by: Russ Cox <rsc@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
2016-11-04 19:57:23 +00:00
Robert Griesemer
7fd6b925e3 spec: update operator and delimiter section
Follow-up on https://go-review.googlesource.com/30601.

Change-Id: I51b603a6c4877b571e83cd7c4e78a8988cc831ca
Reviewed-on: https://go-review.googlesource.com/32310
Reviewed-by: Rob Pike <r@golang.org>
2016-10-28 17:05:48 +00:00
Robert Griesemer
aff37662d1 spec: add new language for alias declarations
For #16339.

Change-Id: I7d912ea634bbfacfc0217f97dccb270fde06f16b
Reviewed-on: https://go-review.googlesource.com/30601
Reviewed-by: Russ Cox <rsc@golang.org>
2016-10-27 17:48:02 +00:00
Robert Griesemer
023bb034e9 spec: slightly more realistic example for type assertions
For #17428.

Change-Id: Ia902b50cf0c40e3c2167fb573a39d328331c38c7
Reviewed-on: https://go-review.googlesource.com/31449
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-10-19 17:16:55 +00:00
Robert Griesemer
8fbfdad281 spec: require 16 bit minimum exponent in constants rather than 32
A 16bit binary exponent permits a constant range covering roughly the range
from 7e-9865 to 7e9863 which is more than enough for any practical and
hypothetical constant arithmetic.

Furthermore, until recently cmd/compile could not handle very large exponents
correctly anyway; i.e., the chance that any real programs (but for tests that
explore corner cases) are affected are close to zero.

Finally, restricting the minimum supported range significantly reduces the
implementation complexity in an area that hardly matters in reality for new
or alternative spec-compliant implementations that don't or cannot rely on
pre-existing arbitratry precision arithmetic packages that support a 32bit
exponent range.

This is technically a language change but for the reasons mentioned above
this is unlikely to affect any real programs, and certainly not programs
compiled with the gc or gccgo compilers as they currently support up to
32bit exponents.

Fixes #13572.

Change-Id: I970f919c57fc82c0175844364cf48ea335f17d39
Reviewed-on: https://go-review.googlesource.com/17711
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
2016-10-18 22:36:50 +00:00
Robert Griesemer
5567b87891 spec: fix examples for predeclared function complex
Fixes #17398.

Change-Id: Iac7899031c1bfbadc4f84e5b374eaf1f01dff8c8
Reviewed-on: https://go-review.googlesource.com/31190
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-10-14 19:58:27 +00:00
Robert Griesemer
a016ecfdcb spec: clarify acceptable indices in array/slice composite literals
This simply documents the status quo accepted by cmd/compile, gccgo,
and go/types. The new language matches the language used for indices
of index expressions for arrays and slices.

Fixes #16679.

Change-Id: I65447889fbda9d222f2a9e6c10334d1b38c555f0
Reviewed-on: https://go-review.googlesource.com/30474
Reviewed-by: Rob Pike <r@golang.org>
2016-10-06 20:37:39 +00:00