-
Notifications
You must be signed in to change notification settings - Fork 413
TreeBorrows: split Tree::perform_protector_release_access from Tree::perform_access
#4741
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
royAmmerschuber
wants to merge
1
commit into
rust-lang:master
Choose a base branch
from
royAmmerschuber:feature/refactor-protector-release
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -828,7 +828,9 @@ impl<'tcx> Tree { | |||||||
| ) -> InterpResult<'tcx> { | ||||||||
| self.perform_access( | ||||||||
| prov, | ||||||||
| Some((access_range, AccessKind::Write, diagnostics::AccessCause::Dealloc)), | ||||||||
| access_range, | ||||||||
| AccessKind::Write, | ||||||||
| diagnostics::AccessCause::Dealloc, | ||||||||
| global, | ||||||||
| alloc_id, | ||||||||
| span, | ||||||||
|
|
@@ -903,14 +905,6 @@ impl<'tcx> Tree { | |||||||
| /// to each location of the first component of `access_range_and_kind`, | ||||||||
| /// on every tag of the allocation. | ||||||||
| /// | ||||||||
| /// If `access_range_and_kind` is `None`, this is interpreted as the special | ||||||||
| /// access that is applied on protector release: | ||||||||
| /// - the access will be applied only to accessed locations of the allocation, | ||||||||
| /// - it will not be visible to children, | ||||||||
| /// - it will be recorded as a `FnExit` diagnostic access | ||||||||
| /// - and it will be a read except if the location is `Unique`, i.e. has been written to, | ||||||||
| /// in which case it will be a write. | ||||||||
| /// | ||||||||
| /// `LocationState::perform_access` will take care of raising transition | ||||||||
| /// errors and updating the `accessed` status of each location, | ||||||||
| /// this traversal adds to that: | ||||||||
|
|
@@ -920,7 +914,9 @@ impl<'tcx> Tree { | |||||||
| pub fn perform_access( | ||||||||
| &mut self, | ||||||||
| prov: ProvenanceExtra, | ||||||||
| access_range_and_kind: Option<(AllocRange, AccessKind, diagnostics::AccessCause)>, | ||||||||
| access_range: AllocRange, | ||||||||
| access_kind: AccessKind, | ||||||||
| access_cause: AccessCause, | ||||||||
| global: &GlobalState, | ||||||||
| alloc_id: AllocId, // diagnostics | ||||||||
| span: Span, // diagnostics | ||||||||
|
|
@@ -934,61 +930,75 @@ impl<'tcx> Tree { | |||||||
| ProvenanceExtra::Concrete(tag) => Some(self.tag_mapping.get(&tag).unwrap()), | ||||||||
| ProvenanceExtra::Wildcard => None, | ||||||||
| }; | ||||||||
| if let Some((access_range, access_kind, access_cause)) = access_range_and_kind { | ||||||||
| // Default branch: this is a "normal" access through a known range. | ||||||||
| // We iterate over affected locations and traverse the tree for each of them. | ||||||||
| for (loc_range, loc) in self.locations.iter_mut(access_range.start, access_range.size) { | ||||||||
| // We iterate over affected locations and traverse the tree for each of them. | ||||||||
| for (loc_range, loc) in self.locations.iter_mut(access_range.start, access_range.size) { | ||||||||
| loc.perform_access( | ||||||||
| self.roots.iter().copied(), | ||||||||
| &mut self.nodes, | ||||||||
| source_idx, | ||||||||
| loc_range, | ||||||||
| Some(access_range), | ||||||||
| access_kind, | ||||||||
| access_cause, | ||||||||
| global, | ||||||||
| alloc_id, | ||||||||
| span, | ||||||||
| ChildrenVisitMode::VisitChildrenOfAccessed, | ||||||||
| )?; | ||||||||
| } | ||||||||
| interp_ok(()) | ||||||||
| } | ||||||||
| /// this is the special access that is applied on protector release: | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| /// - the access will be applied only to accessed locations of the allocation, | ||||||||
| /// - it will not be visible to children, | ||||||||
| /// - it will be recorded as a `FnExit` diagnostic access | ||||||||
| /// - and it will be a read except if the location is `Unique`, i.e. has been written to, | ||||||||
| /// in which case it will be a write. | ||||||||
| /// - otherwise identical to `Tree::perform_access` | ||||||||
| pub fn perform_protector_release_access( | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we more typically call this "protector end access", so
Suggested change
|
||||||||
| &mut self, | ||||||||
| tag: BorTag, | ||||||||
| global: &GlobalState, | ||||||||
| alloc_id: AllocId, // diagnostics | ||||||||
| span: Span, // diagnostics | ||||||||
| ) -> InterpResult<'tcx> { | ||||||||
| #[cfg(feature = "expensive-consistency-checks")] | ||||||||
| if self.roots.len() > 1 { | ||||||||
| self.verify_wildcard_consistency(global); | ||||||||
| } | ||||||||
|
|
||||||||
| let source_idx = self.tag_mapping.get(&tag).unwrap(); | ||||||||
|
|
||||||||
| // This is a special access through the entire allocation. | ||||||||
| // It actually only affects `accessed` locations, so we need | ||||||||
| // to filter on those before initiating the traversal. | ||||||||
| // | ||||||||
| // In addition this implicit access should not be visible to children, | ||||||||
| // thus the use of `traverse_nonchildren`. | ||||||||
| // See the test case `returned_mut_is_usable` from | ||||||||
| // `tests/pass/tree_borrows/tree-borrows.rs` for an example of | ||||||||
| // why this is important. | ||||||||
| for (loc_range, loc) in self.locations.iter_mut_all() { | ||||||||
| // Only visit accessed permissions | ||||||||
| if let Some(p) = loc.perms.get(source_idx) | ||||||||
| && let Some(access_kind) = p.permission.protector_end_access() | ||||||||
| && p.accessed | ||||||||
| { | ||||||||
| let access_cause = diagnostics::AccessCause::FnExit(access_kind); | ||||||||
| loc.perform_access( | ||||||||
| self.roots.iter().copied(), | ||||||||
| &mut self.nodes, | ||||||||
| source_idx, | ||||||||
| Some(source_idx), | ||||||||
| loc_range, | ||||||||
| Some(access_range), | ||||||||
| None, | ||||||||
| access_kind, | ||||||||
| access_cause, | ||||||||
| global, | ||||||||
| alloc_id, | ||||||||
| span, | ||||||||
| ChildrenVisitMode::VisitChildrenOfAccessed, | ||||||||
| ChildrenVisitMode::SkipChildrenOfAccessed, | ||||||||
| )?; | ||||||||
| } | ||||||||
| } else { | ||||||||
| // This is a special access through the entire allocation. | ||||||||
| // It actually only affects `accessed` locations, so we need | ||||||||
| // to filter on those before initiating the traversal. | ||||||||
| // | ||||||||
| // In addition this implicit access should not be visible to children, | ||||||||
| // thus the use of `traverse_nonchildren`. | ||||||||
| // See the test case `returned_mut_is_usable` from | ||||||||
| // `tests/pass/tree_borrows/tree-borrows.rs` for an example of | ||||||||
| // why this is important. | ||||||||
|
|
||||||||
| // Wildcard references are never protected. So this can never be | ||||||||
| // called with a wildcard reference. | ||||||||
| let source_idx = source_idx.unwrap(); | ||||||||
|
|
||||||||
| for (loc_range, loc) in self.locations.iter_mut_all() { | ||||||||
| // Only visit accessed permissions | ||||||||
| if let Some(p) = loc.perms.get(source_idx) | ||||||||
| && let Some(access_kind) = p.permission.protector_end_access() | ||||||||
| && p.accessed | ||||||||
| { | ||||||||
| let access_cause = diagnostics::AccessCause::FnExit(access_kind); | ||||||||
| loc.perform_access( | ||||||||
| self.roots.iter().copied(), | ||||||||
| &mut self.nodes, | ||||||||
| Some(source_idx), | ||||||||
| loc_range, | ||||||||
| None, | ||||||||
| access_kind, | ||||||||
| access_cause, | ||||||||
| global, | ||||||||
| alloc_id, | ||||||||
| span, | ||||||||
| ChildrenVisitMode::SkipChildrenOfAccessed, | ||||||||
| )?; | ||||||||
| } | ||||||||
| } | ||||||||
| } | ||||||||
| interp_ok(()) | ||||||||
| } | ||||||||
|
|
||||||||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
access_causeis also just used for diagnostics I assume?