From b636f192e2f2c9e7114379ed27a43654b86b1b3b Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Wed, 20 Mar 2013 15:05:28 -0700 Subject: [PATCH] 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 --- doc/go_spec.html | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) 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. -- 2.50.0