1
0
mirror of https://github.com/golang/go synced 2024-10-02 10:18:33 -06:00
Commit Graph

476 Commits

Author SHA1 Message Date
Robert Griesemer
187ee2cf2b spec: receiver declaration is just a parameter declaration
This CL removes the special syntax for method receivers and
makes it just like other parameters. Instead, the crucial
receiver-specific rules (exactly one receiver, receiver type
must be of the form T or *T) are specified verbally instead
of syntactically.

This is a fully backward-compatible (and minor) syntax
relaxation. As a result, the following syntactic restrictions
(which are completely irrelevant) and which were only in place
for receivers are removed:

a) receiver types cannot be parenthesized
b) receiver parameter lists cannot have a trailing comma

The result of this CL is a simplication of the spec and the
implementation, with no impact on existing (or future) code.

Noteworthy:

- gc already permits a trailing comma at the end of a receiver
  declaration:

  func (recv T,) m() {}

  This is technically a bug with the current spec; this CL will
  legalize this notation.

- gccgo produces a misleading error when a trailing comma is used:

  error: method has multiple receivers

  (even though there's only one receiver)

- Compilers and type-checkers won't need to report errors anymore
  if receiver types are parenthesized.

Fixes #4496.

LGTM=iant, rsc
R=r, rsc, iant, ken
CC=golang-codereviews
https://golang.org/cl/101500044
2014-06-24 16:25:09 -07:00
Robert Griesemer
94849d5a78 spec: clarify that break/continue do not work across function boundaries
Also made it extra clear for goto statements (even though label scopes
are already limited to the function defining a label).

Fixes #8040.

LGTM=r, rsc
R=r, rsc, iant, ken
CC=golang-codereviews
https://golang.org/cl/99550043
2014-05-28 08:43:47 -07:00
Robert Griesemer
2c83f1eaf9 spec: explicitly disallow blank methods in interface types
The spec was unclear about whether blank methods should be
permitted in interface types. gccgo permits at most one, gc
crashes if there are more than one, go/types permits at most
one.

Discussion:

Since method sets of non-interface types never contain methods
with blank names (blank methods are never declared), it is impossible
to satisfy an interface with a blank method.

It is possible to declare variables of assignable interface types
(but not necessarily identical types) containing blank methods, and
assign those variables to each other, but the values of those
variables can only be nil.

There appear to be two "reasonable" alternatives:

1) Permit at most one blank method (since method names must be unique),
and consider it part of the interface. This is what appears to happen
now, with corner-case bugs. Such interfaces can never be implemented.

2) Permit arbitrary many blank methods but ignore them. This appears
to be closer to the handling of blank identifiers in declarations.
However, an interface type literal is not a declaration (it's a type
literal). Also, for struct types, blank identifiers are not ignored;
so the analogy with declarations is flawed.

Both these alternatives don't seem to add any benefit and are likely
(if only slightly) more complicated to explain and implement than
disallowing blank methods in interfaces altogether.

Fixes #6604.

LGTM=r, rsc, iant
R=r, rsc, ken, iant
CC=golang-codereviews
https://golang.org/cl/99410046
2014-05-22 12:23:25 -07:00
Robert Griesemer
c00043b5d8 spec: specify order of init() calls
The spec did not specify the order in which
init() functions are called. Specify that
they are called in source order since we have
now also specified the initialization order
of independent variables.

While technically a language change, no
existing code could have relied on this,
so this should not break anything.

Per suggestion from rsc.

LGTM=r, iant
R=rsc, iant, r, ken
CC=golang-codereviews
https://golang.org/cl/98420046
2014-05-20 17:46:08 -07:00
Robert Griesemer
a43669843b spec: clarify section on package initialization
- split description of package initialization and
  program execution
- better grouping of concerns in section on package
  initialization
- more explicit definition of what constitues a
  dependency
- removed language about constant dependencies -
  they are computed at compile-time and not
  initialized at run-time
- clarified that independent variables are initialized
  in declaration order (rather than reference order)

Note that the last clarification is what distinguishes
gc and gccgo at the moment: gc uses reference order
(i.e., order in which variables are referenced in
initialization expressions), while gccgo uses declaration
order for independent variables.

Not a language change. But adopting this CL will
clarify what constitutes a dependency.

Fixes #6703.

LGTM=adonovan, r, iant, rsc
R=r, rsc, iant, ken, adonovan
CC=golang-codereviews
https://golang.org/cl/99020043
2014-05-20 13:51:39 -07:00
Rob Pike
4d36ad7791 doc/go_spec.html: fix broken anchor tag
LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/99420045
2014-05-20 11:57:58 -07:00
Robert Griesemer
7f1d62dcef spec: clarify when a program exits
Fixes #8023.

LGTM=rsc
R=r, iant, ken, rsc
CC=golang-codereviews
https://golang.org/cl/98340043
2014-05-19 08:54:19 -07:00
Ian Lance Taylor
2a627da326 spec: clarify that newlines are kept in raw string literals
Fixes #8007.

LGTM=r
R=gri, r
CC=golang-codereviews
https://golang.org/cl/91510044
2014-05-16 12:20:03 -07:00
Robert Griesemer
61d8a33719 spec: more precise description of select statement
- use previously defined terms (with links) throughout
- specify evaluation order more precisely (in particular,
  the evaluation time of rhs expressions in receive cases
  was not specified)
- added extra example case

Not a language change.

Description matches observed behavior of code compiled
with gc and gccgo.

Fixes #7669.

LGTM=iant, r, rsc
R=r, rsc, iant, ken, josharian
CC=golang-codereviews
https://golang.org/cl/91230043
2014-05-14 11:47:19 -07:00
Robert Griesemer
97aa90d251 spec: several clarifications to language on channels
- A channel may be used between any number of goroutines,
  not just two.
- Replace "passing a value" (which is not further defined)
  by "sending and receiving a value".
- Made syntax production more symmetric.
- Talk about unbuffered channels before buffered channels.
- Clarify what the comma,ok receive values mean (issue 7785).

Not a language change.

Fixes #7785.

LGTM=rsc, r, iant
R=r, rsc, iant, ken
CC=golang-codereviews
https://golang.org/cl/94030045
2014-05-07 10:40:39 -07:00
Robert Griesemer
dbe5f88804 spec: remove evaluation order inconsistency
This is a clarification of what happens already.
Not a language change.

Fixes #7137.

LGTM=iant, r, rsc
R=r, rsc, iant, ken
CC=golang-codereviews
https://golang.org/cl/96000044
2014-05-07 08:50:52 -07:00
Robert Griesemer
6f3b84a757 spec: clarify type properties
If the underlying type of a type T is a boolean, numeric,
or string type, then T is also a boolean, numeric, or
string type, respectively.

Not a language change.

Fixes #7551.

LGTM=iant, rsc, robert.hencke, r
R=r, rsc, iant, ken, robert.hencke
CC=golang-codereviews
https://golang.org/cl/100130044
2014-05-07 08:42:08 -07:00
Dmitriy Vyukov
2e1ddeb136 doc: replace absolute links to golang.org with relative links
Currently tip.golang.org leads to golang.org and
local godoc also leads to golang.org (when you don't have internet connectivity).

LGTM=crawshaw
R=golang-codereviews, crawshaw
CC=golang-codereviews
https://golang.org/cl/100200043
2014-05-07 18:49:13 +04:00
Robert Griesemer
6ffd235161 spec: clarify when constant slice indices must be in range
This documents the status quo for most implementations,
with one exception: gc generates a run-time error for
constant but out-of-range indices when slicing a constant
string. See issue 7200 for a detailed discussion.

LGTM=r
R=r, rsc, iant, ken
CC=golang-codereviews
https://golang.org/cl/72160044
2014-03-06 17:11:13 -08:00
Robert Griesemer
a766277742 spec: clarify value passed for final parameter of variadic functions
NOT A LANGUAGE CHANGE.

Fixes #7073.

LGTM=r
R=r, rsc, iant, ken
CC=golang-codereviews
https://golang.org/cl/68840045
2014-03-06 10:35:05 -08:00
Robert Griesemer
8d77d2c8f0 spec: be more precise about underlying types of predeclared types
The underlying type of the predeclared type error is not itself,
but the interface it is defined as.

Fixes #7444.

LGTM=r, rsc
R=r, rsc, iant, ken
CC=golang-codereviews
https://golang.org/cl/71790044
2014-03-05 19:37:44 -08:00
Robert Griesemer
c97778f430 spec: shadowed return parameters may be disallowed
This documents the implemented behavior of both
gc and gccgo as an implementation restriction.

NOT A LANGUAGE CHANGE.

Fixes #5425.

LGTM=rsc, r, iant
R=r, iant, rsc, ken
CC=golang-codereviews
https://golang.org/cl/71430043
2014-03-05 11:59:53 -08:00
Robert Griesemer
871698136d spec: clarify what is considered a function call for len/cap special case
gccgo considers built-in function calls returning a constant not as function call (issue 7386)
go/types considers any call (regular or built-in) as a function call

The wording and examples clarify that only "function calls" that are issued
at run-time (and thus do not result in a constant result) are considered
function calls in this case.

gc is inconsistent (issue 7385)
gccgo already interprets the spec accordingly and issue 7386 is moot.
go/types considers all calls (constant or not) as function calls (issue 7457).

Fixes #7387.
Fixes #7386.

LGTM=r, rsc, iant
R=r, rsc, iant, ken
CC=golang-codereviews
https://golang.org/cl/66860046
2014-03-03 20:07:34 -08:00
Robert Griesemer
a36b5b99cc spec: slightly rephrased wording on parsing ambiguity for composite literals
Fixes #4482.

LGTM=r
R=r, iant, rsc, ken
CC=golang-codereviews
https://golang.org/cl/69020045
2014-02-27 08:57:30 -08:00
Rob Pike
e6863e7d5b spec: libraries and implementation are now at Unicode 6.3
LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/68760043
2014-02-25 14:15:49 -08:00
Robert Griesemer
ab26623182 spec: clarify default "true" condition/tag in for/switch statements
An absent condition/tag in for and switch statements is equivalent
to the predeclared constant true; not simply the expression true
(which might lead to a locally defined true).

Not a language change.

Fixes #7404.

LGTM=iant, r
R=r, iant, rsc, ken
CC=golang-codereviews
https://golang.org/cl/68150046
2014-02-25 09:13:37 -08:00
Rob Pike
227fe5f64e spec: tighten the wording around . imports
Make it clear that if you do a . import, you cannot use a qualified identifier.

R=gri
CC=golang-codereviews
https://golang.org/cl/52390043
2014-01-14 15:16:01 -08:00
Rob Pike
82e2db70f6 spec: s/and/or/ for correctness and parallelism
No change to the meaning, just bad writing found by
Doug McIlroy.
Let's start the new year off with a bang.

R=golang-codereviews, bradfitz, dave
CC=golang-codereviews
https://golang.org/cl/47110044
2014-01-04 10:52:59 -08:00
Emil Hessman
13141315ad spec: Fix broken type identity link
Fixes #7003.

R=golang-codereviews, bradfitz
CC=golang-codereviews
https://golang.org/cl/47780043
2014-01-03 22:48:03 -08:00
Mihai Borobocea
8183ed19b9 spec: example shows wrong value for complex constant
Looks like a typo.
Fixes #7011.

R=golang-codereviews, r, bradfitz
CC=golang-codereviews
https://golang.org/cl/45350043
2013-12-30 13:29:56 -08:00
Robert Griesemer
f57bf7a556 spec: clarify rules for blank identifiers
This documents the status quo more precisely.
Not a language change.

Fixes #6006.

R=r, rsc, iant, ken
CC=golang-dev
https://golang.org/cl/14415043
2013-11-12 21:06:54 -05:00
Robert Griesemer
15da997c7e spec: clarify re-use of underlying arrays in slice operations
Please note the slight rewording for append: The spec now
requires that append reuses the underlying array if it is
sufficiently large. Per majority sentiment.

This is technically a language change but the current
implementation always worked this way.

Fixes #5818.
Fixes #5180.

R=rsc, iant, r, ken, minux.ma, dan.kortschak, rogpeppe, go.peter.90
CC=golang-dev
https://golang.org/cl/14419054
2013-10-16 16:16:54 -07:00
Robert Griesemer
e121de2f01 spec: unsafe.Pointers are pointers
But they cannot be dereferenced.
See also issue 6116.

Fixes #6358.

R=r, rsc, iant, ken
CC=golang-dev
https://golang.org/cl/14374046
2013-10-07 10:43:28 -07:00
Andrew Gerrand
48ba6fe553 doc: move spec and memory model back to /ref/
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/14364043
2013-10-04 09:45:06 +10:00
Robert Griesemer
4cc71e3363 spec: added additional links, added missing 'label'
No semantic spec changes.

R=r
CC=golang-dev
https://golang.org/cl/14363043
2013-10-03 16:38:22 -07:00
Robert Hencke
58d18e25af spec: fix small typo in comment for example
R=golang-dev, mirtchovski, r
CC=golang-dev
https://golang.org/cl/14227043
2013-10-03 12:46:02 -07:00
Rob Pike
cec0954dd0 spec: add example for continue to label
Make the break example slightly more interesting
Update #5725
Effective Go will be updated in a separate CL.

R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/13368054
2013-09-17 07:41:11 +10:00
Andrew Gerrand
5dd74175d4 doc: re-organize golang.org site content
Remove "References" section.
Remove most articles and redirect to blog.golang.org.
Move /ref/spec and /ref/mem to /doc/spec and /doc/mem.
Remove duplicate links from the remaining
"Documents", "The Project", and "Help" pages.
Defer to the wiki for more links and community content.
Update command reference and mention cover tool.
Add "Pop-out" text to the front page.
Pick one of four videos at random to feature on the front page.

Fixes #2547.
Fixes #5561.
Fixes #6321.

R=r, dominik.honnef
CC=golang-dev
https://golang.org/cl/13724043
2013-09-16 15:47:13 +10:00
Robert Griesemer
e333b96529 spec: define s[i:j:k]
R=rsc, r, iant, ken
CC=golang-dev
https://golang.org/cl/10243046
2013-09-11 17:18:52 -07:00
Russ Cox
5ce78b7cd2 spec: &x panics if x does
See golang.org/s/go12nil for the extended version.

R=golang-dev, r, adonovan
CC=golang-dev
https://golang.org/cl/12964043
2013-08-15 14:33:26 -04:00
Rob Pike
15e6ce2351 go_spec.html: clarify that tags are part of struct type identity
One sentence says they're ignored, another says they take part.
Fix the first.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/12741046
2013-08-15 13:15:55 +10:00
Robert Griesemer
2961d229de spec: clarify index and selector expressions
(Replacement for CL 11884043.)

1) Explain a[i] and a[i:j] where a is of type *A as
   shortcut for (*a)[i] and (*a)[i:j], respectively.

2) Together with 1), because len() of nil slices is
   well defined, there's no need to special case nil
   operands anymore.

3) The result of indexing or slicing a constant string
   is always a non-constant byte or string value.

4) The result of slicing an untyped string is a value
   of type string.

5) If the operand of a valid slice a[i:j] is nil (i, j
   must be 0 for it to be valid - this already follows
   from the in-range rules), the result is a nil slice.

Fixes #4913.
Fixes #5951.

R=r, rsc, iant, ken
CC=golang-dev
https://golang.org/cl/12198043
2013-07-31 22:25:47 -07:00
Rob Pike
bd65404eef spec: clarify a couple of issues about channels
1. They are FIFOs.
2. They are safe for concurrent access.

Fixes #5911.

R=golang-dev, dvyukov, adg
CC=golang-dev
https://golang.org/cl/11549043
2013-08-01 07:12:32 +10:00
Robert Griesemer
9f75dd7f25 undo CL 11884043 / bfd5ed8236d5
CL submitted prematurely by mistake.

««« original CL description
spec: clarify index and selector expressions

1) Explain a[i] and a[i:j] where a is of type *A as
   shortcut for (*a)[i] and (*a)[i:j], respectively.

2) Together with 1), because len() of nil slices is
   well defined, there's no need to special case nil
   operands anymore.

3) The result of indexing or slicing a constant string
   is always a non-constant byte or string value.

4) The result of slicing an untyped string is a value
   of type string.

5) If the operand of a valid slice a[i:j] is nil (i, j
   must be 0 for it to be valid - this already follows
   from the in-range rules), the result is a nil slice.

Fixes #4913.
Fixes #5951.

R=rsc, r, iant, ken
CC=golang-dev
https://golang.org/cl/11884043
»»»

R=r
CC=golang-dev
https://golang.org/cl/12170046
2013-07-31 14:10:46 -07:00
Robert Griesemer
58d2960655 spec: clarify index and selector expressions
1) Explain a[i] and a[i:j] where a is of type *A as
   shortcut for (*a)[i] and (*a)[i:j], respectively.

2) Together with 1), because len() of nil slices is
   well defined, there's no need to special case nil
   operands anymore.

3) The result of indexing or slicing a constant string
   is always a non-constant byte or string value.

4) The result of slicing an untyped string is a value
   of type string.

5) If the operand of a valid slice a[i:j] is nil (i, j
   must be 0 for it to be valid - this already follows
   from the in-range rules), the result is a nil slice.

Fixes #4913.
Fixes #5951.

R=rsc, r, iant, ken
CC=golang-dev
https://golang.org/cl/11884043
2013-07-31 13:40:01 -07:00
Robert Griesemer
f331012427 spec: update prose in Constants section
Fixes #5952.

R=r, rsc
CC=golang-dev
https://golang.org/cl/11812043
2013-07-25 09:35:55 -07:00
Robert Griesemer
63f54ae3c2 spec: move decl in example closer to use
Fixes #5862.

R=r
CC=golang-dev
https://golang.org/cl/11168043
2013-07-11 14:41:46 -07:00
Robert Griesemer
8268eadb9e spec: define notion of named type
The notion of a named type is crucial for the definition
of type identity, assignability, definitions of methods.
Explicitly introduce the notion with an extra sentence.

Fixes #5682.

R=r, rsc, iant
CC=golang-dev
https://golang.org/cl/11055043
2013-07-09 21:12:53 -07:00
Robert Griesemer
de47f68c99 spec: fix spec on conversions to match implementations
The existing compilers convert empty strings to empty
but non-nil byte and rune slices. The spec required
a nil byte and rune slice in those cases. That seems
an odd additional requirement. Adjust the spec to
match the reality.

Also, removed over-specification for conversions of
nil []byte and []rune: such nil slices already act
like empty slices and thus don't need extra language.
Added extra examples instead.

Fixes #5704.

R=rsc, r, iant
CC=golang-dev
https://golang.org/cl/10440045
2013-06-21 16:11:13 -07:00
Shenghou Ma
bdac989ef7 doc/go_spec: more examples for unspecified cases of the evaluation order
R=golang-dev, bradfitz, gri, iant, rsc
CC=golang-dev
https://golang.org/cl/7235044
2013-06-11 02:52:07 +08:00
Robert Griesemer
ab5c762a46 spec: better wording re: receiving from closed channels
As suggested by ej@evanjones.ca.

Fixes #5604.

R=r
CC=golang-dev
https://golang.org/cl/9899043
2013-05-31 11:21:37 -07:00
Robert Griesemer
6a3859f433 spec: removed old or invalid TODOs
Several old TODOs are either resolved now (e.g. when is a return
needed), or are from a time the language wasn't frozen (^ for uints
only). Consolidated the others.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/9599044
2013-05-20 14:01:07 -07:00
Robert Griesemer
bb3a32ef6e spec: fix language about "range" clause
Fixes #5434.

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/9595044
2013-05-20 13:27:53 -07:00
Shenghou Ma
df29cdd33d doc/go_spec: fix typos
Fixes #5456.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/9400044
2013-05-15 03:50:27 +08:00
Robert Griesemer
2d846f6521 spec: fix incorrect example
Fixes #5430.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/9305043
2013-05-08 10:42:08 -07:00