Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
8cb9184d
Commit
8cb9184d
authored
Sep 15, 2009
by
Rob Pike
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
an attempt to define initialization order within a package.
DELTA=23 (19 added, 1 deleted, 3 changed) OCL=34646 CL=34649
parent
678625d8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
4 deletions
+22
-4
doc/go_spec.html
doc/go_spec.html
+22
-4
No files found.
doc/go_spec.html
View file @
8cb9184d
...
...
@@ -764,7 +764,7 @@ a type named <code>T</code>:
A field declaration may be followed by an optional string literal
<i>
tag
</i>
,
which becomes an attribute for all the identifiers in the corresponding
field declaration. The tags are made
visible through a
reflection library
<font
color=
red
>
TODO: reference?
</font
>
visible through a
<a
href=
"#Package_unsafe"
>
reflection interface
</a
>
but are otherwise ignored.
</p>
...
...
@@ -2384,7 +2384,7 @@ its dynamic type is a structure whose sequential fields are the
trailing arguments of the call. That is, the actual arguments
provided for a
<code>
...
</code>
parameter are wrapped into a struct
that is passed to the function instead of the actual arguments.
Using the
reflection library (TODO: reference)
,
<code>
f
</code>
may
Using the
<a
href=
"#Package_unsafe"
>
reflection
</a>
interface
,
<code>
f
</code>
may
unpack the elements of the dynamic type to recover the actual
arguments.
</p>
...
...
@@ -4281,8 +4281,7 @@ var t T
<h3
id=
"Program_execution"
>
Program execution
</h3>
<p>
A package with no imports is initialized by assigning initial values to
all its package-level variables in data-dependency order
(
<font
color=
red
>
TODO: clarify
</font>
)
all its package-level variables
and then calling any
package-level function with the name and signature of
</p>
...
...
@@ -4296,6 +4295,25 @@ than one source file, there may be more than one
only one per source file.
</p>
<p>
Within a package, package-level variables are initialized,
and constant values are determined, in
data-dependent order: if the initializer of
<code>
A
</code>
depends on the value of
<code>
B
</code>
,
<code>
A
</code>
will be set after
<code>
B
</code>
.
It is an error if such dependencies form a cycle.
Dependency analysis is done lexically:
<code>
A
</code>
depends on
<code>
B
</code>
if the value of
<code>
A
</code>
contains a mention of
<code>
B
</code>
, contains a value
whose initializer
mentions
<code>
B
</code>
, or mentions a function that
mentions
<code>
B
</code>
, recursively.
If two items are not interdependent, they will be initialized
in the order they appear in the source.
Since the dependency analysis is done per package, it can be
defeated if
<code>
A
</code>
's initializer calls a function defined
in another package that refers to
<code>
B
</code>
.
</p>
<p>
Initialization code may contain "go" statements, but the functions
they invoke do not begin execution until initialization of the entire
program is complete. Therefore, all initialization code is run in a single
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment