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.
This PR adds a 1st draft of copy elision. It works during callDestructors
and looks for a copy being the last mention of a variable before the
deinitializer is run for that variable. In that event, it elides the copy
and does not deinitialize the variable.
Copy elision is discussed in issues #13704, #9490, #9421,
#14860, #14870, and #14874.
This PR is closest to the proposal in #14860 of any of those,
but it does not quite match that proposal.
In the future, we expect to separate the effort of deciding which copies
are elide-able from the work of doing the actual elision. Since the
elision involves not deinitializing something, it makes sense to continue
to do that in callDestructors. However, the work of deciding which copies
are elide-able will move to some part of the compiler before nil checking
(because nil checking can find certain errors after an elided copy makes
a variable invalid). Additionally we are planning to use a simpler rule
for when a copy can be elided (#14874).
Reviewed by @benharsh - thanks!