From: Rob Pike Date: Wed, 20 Mar 2013 22:05:28 +0000 (-0700) Subject: spec: fix description of initialization X-Git-Tag: go1.1rc2~418 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=b636f192e2f2c9e7114379ed27a43654b86b1b3b;p=gostls13.git spec: fix description of initialization The analysis does not depend on the values of the items. Fixes #4648. R=golang-dev, gri, rsc CC=golang-dev https://golang.org/cl/7593050 --- diff --git a/doc/go_spec.html b/doc/go_spec.html index 4c0718f4a9..ebef65916e 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -3542,7 +3542,7 @@ using an addressable value will automatically take the address of that value: @@ -5715,19 +5715,23 @@ in unspecified order.

Within a package, package-level variables are initialized, -and constant values are determined, in -data-dependent order: if the initializer of A -depends on the value of B, A +and constant values are determined, according to +order of reference: if the initializer of A +depends on B, A will be set after B. -It is an error if such dependencies form a cycle. -Dependency analysis is done lexically: A +Dependency analysis does not depend on the actual values +of the items being initialized, only on their appearance +in the source. +A depends on B if the value of A contains a mention of B, contains a value whose initializer mentions B, or mentions a function that mentions B, recursively. +It is an error if such dependencies form a cycle. If two items are not interdependent, they will be initialized -in the order they appear in the source. +in the order they appear in the source, possibly in multiple files, +as presented to the compiler. Since the dependency analysis is done per package, it can produce unspecified results if A's initializer calls a function defined in another package that refers to B.