Commit 4023dce7 authored by Robert Griesemer's avatar Robert Griesemer

- remove language on forward decls

- remove language on (in-)complete types

DELTA=95  (8 added, 62 deleted, 25 changed)
OCL=33310
CL=33322
parent 6f911cca
...@@ -10,7 +10,9 @@ Open issues: ...@@ -10,7 +10,9 @@ Open issues:
Todo's: Todo's:
[ ] need language about function/method calls and parameter passing rules [ ] need language about function/method calls and parameter passing rules
[ ] update language with respect to forward declarations [ ] clarify new scope rules for package-level identifiers
[ ] clarify scope of identifiers denoting imported packages (file scope)
[ ] package identifier not in any scope
[ ] clarify what a field name is in struct declarations [ ] clarify what a field name is in struct declarations
(struct{T} vs struct {T T} vs struct {t T}) (struct{T} vs struct {T T} vs struct {t T})
[ ] need explicit language about the result type of operations [ ] need explicit language about the result type of operations
...@@ -450,17 +452,6 @@ including arrays, structs, pointers, functions, interfaces, slices, maps, and ...@@ -450,17 +452,6 @@ including arrays, structs, pointers, functions, interfaces, slices, maps, and
channels. channels.
</p> </p>
<p>
At any point in the source code, a type may be <i>complete</i> or
<i>incomplete</i>. An incomplete type is one whose size is not
yet known, such as a struct whose fields are not yet fully
defined or a forward declared type (§Forward declarations).
Most types are always complete; for instance, a pointer
type is always complete even if it points to an incomplete type
because the size of the pointer itself is always known.
(TODO: Need to figure out how forward declarations of
interface fit in here.)
</p>
<p> <p>
A type may have a <i>method set</i> associated with it A type may have a <i>method set</i> associated with it
(§Interface types, §Method declarations). (§Interface types, §Method declarations).
...@@ -569,15 +560,15 @@ is a string literal. ...@@ -569,15 +560,15 @@ is a string literal.
<p> <p>
An array is a numbered sequence of elements of a single An array is a numbered sequence of elements of a single
type, called the element type, which must be complete type, called the element type.
(§Types). The number of elements is called the length and is never The number of elements is called the length and is never
negative. negative.
</p> </p>
<pre class="ebnf"> <pre class="ebnf">
ArrayType = "[" ArrayLength "]" ElementType . ArrayType = "[" ArrayLength "]" ElementType .
ArrayLength = Expression . ArrayLength = Expression .
ElementType = CompleteType . ElementType = Type .
</pre> </pre>
<p> <p>
...@@ -677,13 +668,13 @@ new([100]int)[0:50] ...@@ -677,13 +668,13 @@ new([100]int)[0:50]
A struct is a sequence of named A struct is a sequence of named
elements, called fields, with various types. A struct type declares elements, called fields, with various types. A struct type declares
an identifier and type for each field. Within a struct, field identifiers an identifier and type for each field. Within a struct, field identifiers
must be unique and field types must be complete (§Types). must be unique.
</p> </p>
<pre class="ebnf"> <pre class="ebnf">
StructType = "struct" "{" [ FieldDeclList ] "}" . StructType = "struct" "{" [ FieldDeclList ] "}" .
FieldDeclList = FieldDecl { ";" FieldDecl } [ ";" ] . FieldDeclList = FieldDecl { ";" FieldDecl } [ ";" ] .
FieldDecl = (IdentifierList CompleteType | [ "*" ] TypeName) [ Tag ] . FieldDecl = (IdentifierList Type | [ "*" ] TypeName) [ Tag ] .
Tag = StringLit . Tag = StringLit .
</pre> </pre>
...@@ -802,10 +793,10 @@ A function value may be <code>nil</code>. ...@@ -802,10 +793,10 @@ A function value may be <code>nil</code>.
<pre class="ebnf"> <pre class="ebnf">
FunctionType = "func" Signature . FunctionType = "func" Signature .
Signature = Parameters [ Result ] . Signature = Parameters [ Result ] .
Result = Parameters | CompleteType . Result = Parameters | Type .
Parameters = "(" [ ParameterList ] ")" . Parameters = "(" [ ParameterList ] ")" .
ParameterList = ParameterDecl { "," ParameterDecl } . ParameterList = ParameterDecl { "," ParameterDecl } .
ParameterDecl = [ IdentifierList ] ( CompleteType | "..." ) . ParameterDecl = [ IdentifierList ] ( Type | "..." ) .
</pre> </pre>
<p> <p>
...@@ -815,8 +806,6 @@ stands for one item (parameter or result) of the specified type; if absent, each ...@@ -815,8 +806,6 @@ stands for one item (parameter or result) of the specified type; if absent, each
type stands for one item of that type. Parameter and result type stands for one item of that type. Parameter and result
lists are always parenthesized except that if there is exactly lists are always parenthesized except that if there is exactly
one unnamed result that is not a function type it may writen as an unparenthesized type. one unnamed result that is not a function type it may writen as an unparenthesized type.
The types of parameters and results must be complete.
(TODO: is completeness necessary?)
</p> </p>
<p> <p>
For the last parameter only, instead of a type one may write For the last parameter only, instead of a type one may write
...@@ -920,7 +909,7 @@ as the <code>File</code> interface. ...@@ -920,7 +909,7 @@ as the <code>File</code> interface.
<p> <p>
An interface may contain an interface type name <code>T</code> An interface may contain an interface type name <code>T</code>
in place of a method specification. in place of a method specification.
In this notation, <code>T</code> must denote a different, complete interface type In this notation, <code>T</code> must denote a different interface type
and the effect is equivalent to enumerating the methods of <code>T</code> explicitly and the effect is equivalent to enumerating the methods of <code>T</code> explicitly
in the interface. in the interface.
</p> </p>
...@@ -942,17 +931,15 @@ type File interface { ...@@ -942,17 +931,15 @@ type File interface {
<p> <p>
A map is an unordered group of elements of one type, called the A map is an unordered group of elements of one type, called the
value type, indexed by a set of unique <i>keys</i> of another type, value type, indexed by a set of unique <i>keys</i> of another type,
called the key type. Both key and value types must be complete. called the key type.
(§Types).
(TODO: is completeness necessary here?)
A map value may be <code>nil</code>. A map value may be <code>nil</code>.
</p> </p>
<pre class="ebnf"> <pre class="ebnf">
MapType = "map" "[" KeyType "]" ValueType . MapType = "map" "[" KeyType "]" ValueType .
KeyType = CompleteType . KeyType = Type .
ValueType = CompleteType . ValueType = Type .
</pre> </pre>
<p> <p>
...@@ -1001,8 +988,7 @@ stored in them. ...@@ -1001,8 +988,7 @@ stored in them.
<p> <p>
A channel provides a mechanism for two concurrently executing functions A channel provides a mechanism for two concurrently executing functions
to synchronize execution and communicate by passing a value of a to synchronize execution and communicate by passing a value of a
specified element type. The element type must be complete (§Types). specified element type.
(TODO: is completeness necessary here?)
A value of channel type may be <code>nil</code>. A value of channel type may be <code>nil</code>.
</p> </p>
...@@ -1358,16 +1344,14 @@ right. ...@@ -1358,16 +1344,14 @@ right.
<pre class="ebnf"> <pre class="ebnf">
ConstDecl = "const" ( ConstSpec | "(" [ ConstSpecList ] ")" ) . ConstDecl = "const" ( ConstSpec | "(" [ ConstSpecList ] ")" ) .
ConstSpecList = ConstSpec { ";" ConstSpec } [ ";" ] . ConstSpecList = ConstSpec { ";" ConstSpec } [ ";" ] .
ConstSpec = IdentifierList [ [ CompleteType ] "=" ExpressionList ] . ConstSpec = IdentifierList [ [ Type ] "=" ExpressionList ] .
IdentifierList = identifier { "," identifier } . IdentifierList = identifier { "," identifier } .
ExpressionList = Expression { "," Expression } . ExpressionList = Expression { "," Expression } .
CompleteType = Type .
</pre> </pre>
<p> <p>
If the type (CompleteType) is omitted, the constants take the If the type is omitted, the constants take the
individual types of the corresponding expressions, which may be individual types of the corresponding expressions, which may be
<i>ideal integer</i> or <i>ideal float</i> (§Ideal number). If the type <i>ideal integer</i> or <i>ideal float</i> (§Ideal number). If the type
is present, all constants take the type specified, and the types is present, all constants take the type specified, and the types
...@@ -1502,12 +1486,11 @@ type Comparable interface { ...@@ -1502,12 +1486,11 @@ type Comparable interface {
<p> <p>
A variable declaration creates a variable, binds an identifier to it and A variable declaration creates a variable, binds an identifier to it and
gives it a type and optionally an initial value. gives it a type and optionally an initial value.
The type must be complete (§Types).
</p> </p>
<pre class="ebnf"> <pre class="ebnf">
VarDecl = "var" ( VarSpec | "(" [ VarSpecList ] ")" ) . VarDecl = "var" ( VarSpec | "(" [ VarSpecList ] ")" ) .
VarSpecList = VarSpec { ";" VarSpec } [ ";" ] . VarSpecList = VarSpec { ";" VarSpec } [ ";" ] .
VarSpec = IdentifierList ( CompleteType [ "=" ExpressionList ] | "=" ExpressionList ) . VarSpec = IdentifierList ( Type [ "=" ExpressionList ] | "=" ExpressionList ) .
</pre> </pre>
<pre> <pre>
...@@ -1613,6 +1596,11 @@ A function declaration binds an identifier to a function (§Function types). ...@@ -1613,6 +1596,11 @@ A function declaration binds an identifier to a function (§Function types).
FunctionDecl = "func" identifier Signature [ Block ] . FunctionDecl = "func" identifier Signature [ Block ] .
</pre> </pre>
<p>
A function declaration may omit the body. Such a declaration provides the
signature for a function implemented outside Go, such as an assembly routine.
</p>
<pre> <pre>
func min(x int, y int) int { func min(x int, y int) int {
if x &lt; y { if x &lt; y {
...@@ -1620,10 +1608,11 @@ func min(x int, y int) int { ...@@ -1620,10 +1608,11 @@ func min(x int, y int) int {
} }
return y; return y;
} }
func flushICache(begin, end uintptr) // implemented externally
</pre> </pre>
<p> <p>
A function must be declared or forward-declared before it can be invoked (§Forward declarations).
Implementation restriction: Functions can only be declared at the package level. Implementation restriction: Functions can only be declared at the package level.
</p> </p>
...@@ -1676,9 +1665,6 @@ general to parameters of functions and methods. ...@@ -1676,9 +1665,6 @@ general to parameters of functions and methods.
</p> </p>
<p> <p>
Methods can be declared
only after their base type is declared or forward-declared, and invoked
only after their own declaration or forward-declaration (§Forward declarations).
Implementation restriction: They can only be declared at package level. Implementation restriction: They can only be declared at package level.
</p> </p>
...@@ -1695,46 +1681,6 @@ argument. For instance, the method <code>Scale</code> has type ...@@ -1695,46 +1681,6 @@ argument. For instance, the method <code>Scale</code> has type
However, a function declared this way is not a method. However, a function declared this way is not a method.
</p> </p>
<h3>Forward declarations</h3>
<p>
Mutually-recursive types require that one be
<i>forward declared</i> so that it may be named in the other.
A forward declaration of a type omits the block containing the fields
or methods of the type.
</p>
<pre>
type List struct // forward declaration of List
type Item struct {
value int;
next *List;
}
type List struct {
head, tail *Item
}
</pre>
<p>
A forward-declared type is incomplete (§Types)
until it is fully declared. The full declaration must follow
before the end of the block containing the forward declaration;
it cannot be contained in an inner block.
</p>
<p>
Functions and methods may similarly be forward-declared by omitting their body.
</p>
<pre>
func F(a int) int // forward declaration of F
func G(a, b int) int {
return F(a) + F(b)
}
func F(a int) int {
if a <= 0 { return 0 }
return G(a-1, b+1)
}
</pre>
<hr/>
<h2>Expressions</h2> <h2>Expressions</h2>
...@@ -4303,7 +4249,7 @@ When <code>main.main()</code> returns, the program exits. ...@@ -4303,7 +4249,7 @@ When <code>main.main()</code> returns, the program exits.
</p> </p>
<p> <p>
Implementation restriction: The compiler assumes package <code>main</code> Implementation restriction: The compiler assumes package <code>main</code>
is created by a single source file and that it is not imported by any other package. is not imported by any other package.
</p> </p>
<hr/> <hr/>
...@@ -4339,7 +4285,7 @@ a <code>Pointer</code> and vice versa. ...@@ -4339,7 +4285,7 @@ a <code>Pointer</code> and vice versa.
</p> </p>
<p> <p>
The function <code>Sizeof</code> takes an expression denoting a The function <code>Sizeof</code> takes an expression denoting a
variable of any (complete) type and returns the size of the variable in bytes. variable of any type and returns the size of the variable in bytes.
</p> </p>
<p> <p>
The function <code>Offsetof</code> takes a selector (§Selectors) denoting a struct The function <code>Offsetof</code> takes a selector (§Selectors) denoting a struct
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment