Avoid inserting end_cow_mutation_addr in some common cases #85482
+55
−1
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.
We introduce
end_cow_mutation_addrat the scope ends of a lifetime dependent value's parent in cases where the lifetime dependent value maybe a MutableSpan and the parent has a modify scope.This is necessary to avoid miscompiles on the mutableSpan property of Array/ArraySlice/ContiguousArray to indicate the end of mutation.
The analysis used to insert
end_cow_mutation_addris conservative and may introduce unnecessaryend_cow_mutation_addrinstructions when generic types are involved which can indirectly block bounds check optimizations.Improve this analysis by avoiding insertion of
end_cow_mutation_addrwhen the parent maybe trivial, ~Copyable or builtin type. Also avoid insertingend_cow_mutation_addrby adding an early exit inmayHaveMutableSpanfor Escapable and Copyable types.This avoids an unnecessary
end_cow_mutation_addron themark_dependencebase of the MutableSpan's unsafe addressor based subscript result.