• Robert Griesemer's avatar
    spec: specify variable initialization order explicitly · 259f0ffa
    Robert Griesemer authored
    The existing spec rules on package initialization were
    contradictory: They specified that 1) dependent variables
    are initialized in dependency order, and 2) independent
    variables are initialized in declaration order. This 2nd
    rule cannot be satisfied in general. For instance, for
    
    var (
            c = b + 2
            a = 0
            b = 1
    )
    
    because of its dependency on b, c must be initialized after b,
    leading to the partial order b, c. Because a is independent of
    b but is declared before b, we end up with the order: a, b, c.
    But a is also independent of c and is declared after c, so the
    order b, c, a should also be valid in contradiction to a, b, c.
    
    The new rules are given in form of an algorithm which outlines
    initialization order explicitly.
    
    gccgo and go/types already follow these rules.
    
    Fixes #8485.
    
    LGTM=iant, r, rsc
    R=r, rsc, iant, ken, gordon.klaus, adonovan
    CC=golang-codereviews
    https://golang.org/cl/142880043
    259f0ffa
Name
Last commit
Last update
..
articles Loading commit data...
codewalk Loading commit data...
devel Loading commit data...
gopher Loading commit data...
play Loading commit data...
progs Loading commit data...
asm.html Loading commit data...
cmd.html Loading commit data...
code.html Loading commit data...
contrib.html Loading commit data...
contribute.html Loading commit data...
debugging_with_gdb.html Loading commit data...
docs.html Loading commit data...
effective_go.html Loading commit data...
gccgo_contribute.html Loading commit data...
gccgo_install.html Loading commit data...
go-logo-black.png Loading commit data...
go-logo-blue.png Loading commit data...
go-logo-white.png Loading commit data...
go1.1.html Loading commit data...
go1.2.html Loading commit data...
go1.3.html Loading commit data...
go1.4.txt Loading commit data...
go1.html Loading commit data...
go1compat.html Loading commit data...
go_faq.html Loading commit data...
go_mem.html Loading commit data...
go_spec.html Loading commit data...
help.html Loading commit data...
ie.css Loading commit data...
install-source.html Loading commit data...
install.html Loading commit data...
logo-153x55.png Loading commit data...
root.html Loading commit data...
share.png Loading commit data...
sieve.gif Loading commit data...
tos.html Loading commit data...