Prevent unsafe view-copy replacement around mutations - #23279
Open
JacobSzwejbka wants to merge 1 commit into
Open
JacobSzwejbka wants to merge 1 commit into
JacobSzwejbka wants to merge 1 commit into
Conversation
Replace view_copy with a storage alias only when writes to the prospective base and view storage cannot be observed through the other value. Preserve the optimization when the other value is already dead. Authored with Codex.
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/23279
Note: Links to docs will display an error until the docs builds have been completed. ❌ 1 Unclassified FailureAs of commit 8674068 with merge base 21f770c ( UNCLASSIFIED FAILURE - DrCI could not classify the following job because the workflow did not run on the merge base. The failure may be pre-existing on trunk or introduced by this PR:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This PR needs a
|
9 of 11 tasks
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
ReplaceViewCopyWithViewPasscurrently runs after reinplacement. A reinplaced mutation of the copied view can therefore become a mutation of the base afterview_copyis changed tomemory.view, even though the original copy kept the base unchanged. The inverse interaction is possible when the base is mutated while the copied view remains live.Add a reusable
is_copy_to_view_safecheck that follows existing view aliases, schema-declared mutation aliases, and reinplace allocation-sharing annotations. It rejects a substitution only when a write to either prospective storage family precedes a read from the other family. Mutations after the other value's last read remain eligible for view replacement.The helper accepts the set of existing aliasing operators so other copy-to-view passes, including slice-copy lowering, can share the same safety analysis.
Authored with Codex.
Test plan
test_remove_view_copycases and the existingtest_replace_view_copy_with_view_passcase.compileall, andgit diff --checkon the changed Python files.