privat/nit — pull request #857 by privat (2014-10-29 17:40:03+00:00)
Title: Autoinit attributes

Allow `autoinit` on attributes.

This means that the initialization of the attribute is done during the initializer phase.
This will help when the initial value of an attribute depend on the value of another attribute set a the initializer phase.

So that

~~~
class A
var x: String
var y: String = x + " world!"
end
var a = new A("hello") # BOOM! uninitialized x while initializing y
print a.y
~~~

Can become:

~~~
class A
var x: String
var y: String = x + " world!" is autoinit
end
var a = new A("hello")
print a.y # => hello world!
~~~

The inconvenient is that the initialisation markers of attributes become more complex.
Now we have:

* no default value and no special annotation: the setter is collected as an initializer
* no default value and `noinit`: not automatically initializer
* default value and no special annotation: the value is set between the allocation and all initializers
* default value and annotation `lazy`: the value is set at the first access
* *new* default value and annotation `autoinit`: the value is set with all other initializers (other `autoinit`)

For an implementation explanation, the mechanism is a quick hack: `autoinit` means `lazy` + the getter is collector as an initializer. Therefore, when initializers are invoked, the getter will be invoked and the value lazily evaluated.

So the example is equivalent to

~~~
class A
var x: String
var y: String = x + " world!" is lazy
end
var a = ALLOCATE(A)
a.x = "hello" # collected setter for x
a.y # lazy getter for y
a.init
print a.y # => hello world!
~~~