compiler: speed up variable initializer sorting

The compiler used to do variable initializer sorting by looping
through all the initialized variables and, for each one, looping
through all the initialized variables and checking for a dependency.
For very large packages with thousands of initialized global
variables, this quadratic loop could take quite a long time.

Change the approach to first loop through all the initialized
variables and fetch all the references to other variables from the
initialization code.  Then, loop through them again and this time add
a dependency for each referenced, initialized, variable, while
checking for initialization loops.  We still have a nested loop, but
this time the inner loop should normally be short--just the list of
referenced variables, not the list of all variables.

Change-Id: I4939a8a63991241eb71f26b9dfe94c1bb956bbcc
Reviewed-on: https://go-review.googlesource.com/116816
Reviewed-by: Than McIntosh <thanm@google.com>
1 file changed