You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
eager vals may be represented by JVM final fields. Scala 2's isn't able to do this because final fields assignments must appear lexically in the class constructor.
Binary fragility
Traits have a number of well-known binary fragilities. Most notably, when a field is added to a trait and a subclass is not recompiled, a LinkageError will happen when the trait constructor calls the trait setter.
The new encoding introduces new binary fragilities, one of which has a soft failure mode (execution order incorrect). This is because the subclass has the order of the fields "baked in" to its constructor which calls the intiaial$... methods sequentially.
Following are some failure modes when certain changes are made to the trait without recompiling the subclass.
Edit
New Behaviour
Old Behaviour
Fields or side effects reordered
The subclass constructor will execute the old sequence of initialiation/effects. This could be benign but is dangerous in general
No need to recompile subclass, semantics okay
Field deleted
LinkageError
wasted field in the subclass, but semantically okay
Modified, fail-fast encoding
@smarter Has suggested that we could encode the index of the initializer into the initial$... method names.
Edit
New Behaviour
Fields or side effects reordered
LinkageError
Field deleted
LinkageError
The text was updated successfully, but these errors were encountered:
Dotty has implemented a new encoding for trait constructors. Scala 2.14 and 3.0 should align on this implementation detail.
The alignment could come from:
Sample
Scala 2.13
Scala 3.x
Advantages of new encoding
final
fields. Scala 2's isn't able to do this because final fields assignments must appear lexically in the class constructor.Binary fragility
Traits have a number of well-known binary fragilities. Most notably, when a field is added to a trait and a subclass is not recompiled, a
LinkageError
will happen when the trait constructor calls the trait setter.The new encoding introduces new binary fragilities, one of which has a soft failure mode (execution order incorrect). This is because the subclass has the order of the fields "baked in" to its constructor which calls the
intiaial$...
methods sequentially.Following are some failure modes when certain changes are made to the trait without recompiling the subclass.
LinkageError
Modified, fail-fast encoding
@smarter Has suggested that we could encode the index of the initializer into the
initial$...
method names.LinkageError
LinkageError
The text was updated successfully, but these errors were encountered: