Skip to content

Conversation

@meg-gupta
Copy link
Contributor

@meg-gupta meg-gupta commented Nov 13, 2025

We introduce end_cow_mutation_addr at 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_addr is conservative and may introduce unnecessary end_cow_mutation_addr instructions when generic types are involved which can indirectly block bounds check optimizations.

Improve this analysis by avoiding insertion of end_cow_mutation_addr when the parent maybe trivial, ~Copyable or builtin type. Also avoid inserting end_cow_mutation_addr by adding an early exit in mayHaveMutableSpan for Escapable and Copyable types.
This avoids an unnecessary end_cow_mutation_addr on the mark_dependence base of the MutableSpan's unsafe addressor based subscript result.

@meg-gupta meg-gupta requested review from atrick and glessard November 13, 2025 10:42
@meg-gupta
Copy link
Contributor Author

Based on #85481

@meg-gupta
Copy link
Contributor Author

@swift-ci test

@meg-gupta meg-gupta marked this pull request as ready for review November 13, 2025 10:44
@meg-gupta meg-gupta requested review from a team and eeckstein as code owners November 13, 2025 10:44
Copy link
Contributor

@eeckstein eeckstein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@meg-gupta meg-gupta force-pushed the reduceendcowmutation branch from 3ad7dbc to 8507c5a Compare November 13, 2025 16:19
@meg-gupta
Copy link
Contributor Author

@swift-ci test

@meg-gupta meg-gupta force-pushed the reduceendcowmutation branch from 8507c5a to 1dc03fe Compare November 13, 2025 18:37
@meg-gupta
Copy link
Contributor Author

@swift-ci test

@meg-gupta meg-gupta enabled auto-merge November 13, 2025 18:47
@meg-gupta meg-gupta merged commit 827c30f into swiftlang:main Nov 14, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants