Rework implicit allocation in constructors #1255
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As reported in #1225 some weirdness is happening in constructors, caused by late
this
allocations. While investigating, it turned out that this mechanism is connected to quite a few other assumptions made by inlining and reference counting, so I decided to implement a new but more conservative mechanism.With the change, the allocation is injected right at the start of the constructor as soon as any code path requires it (falls-through or accesses
this
). As a side-effect, the following special cases are no longer allowed:this
. Not yet sure if this can become a warning instead of an error.super
calls in this scenario will break due to the resultingthis
mismatch.On the upside, implicit allocations in constructors are now guaranteed to be performed exactly once, reducing code size in scenarios where
this
is first accessed in branches.fixes #1225