-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
942 additions
and
1,514 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
use crate::borrows::engine::DataflowPhase; | ||
use crate::rustc_interface::middle::mir::Location; | ||
|
||
use super::eval_stmt_data::EvalStmtData; | ||
|
||
#[derive(Debug, Clone, PartialEq, Eq)] | ||
pub(crate) struct DomainData<T> { | ||
pub(crate) entry_state: T, | ||
pub(crate) states: EvalStmtData<T>, | ||
phase: DataflowPhase, | ||
} | ||
|
||
impl<T: Default> Default for DomainData<T> { | ||
fn default() -> Self { | ||
Self { | ||
entry_state: T::default(), | ||
states: EvalStmtData::default(), | ||
phase: DataflowPhase::Init, | ||
} | ||
} | ||
} | ||
|
||
impl<T: Clone + Default> DomainData<T> { | ||
pub(crate) fn new(entry_state: T) -> Self { | ||
Self { | ||
entry_state, | ||
states: EvalStmtData::default(), | ||
phase: DataflowPhase::Init, | ||
} | ||
} | ||
pub(crate) fn pre_operands_complete(&mut self) { | ||
assert!(self.phase == DataflowPhase::Transfer); | ||
self.states.pre_operands = self.states.post_main.clone(); | ||
} | ||
pub(crate) fn post_operands_complete(&mut self) { | ||
assert!(self.phase == DataflowPhase::Transfer); | ||
self.states.post_operands = self.states.post_main.clone(); | ||
} | ||
|
||
pub(crate) fn pre_main_complete(&mut self) { | ||
assert!(self.phase == DataflowPhase::Transfer); | ||
self.states.pre_main = self.states.post_main.clone(); | ||
} | ||
pub(crate) fn enter_location(&mut self, _location: Location) { | ||
if self.phase != DataflowPhase::Transfer { | ||
// The entry state may have taken into account previous joins | ||
self.states.post_main = self.entry_state.clone(); | ||
self.phase = DataflowPhase::Transfer; | ||
} | ||
} | ||
pub(crate) fn enter_join(&mut self) { | ||
if self.phase == DataflowPhase::Transfer { | ||
self.entry_state = self.states.post_main.clone(); | ||
self.phase = DataflowPhase::Join; | ||
} | ||
} | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,108 @@ | ||
use serde_json::json; | ||
use crate::utils::json::ToJsonWithRepacker; | ||
use crate::borrows::engine::BorrowsStates; | ||
use crate::combined_pcs::EvalStmtPhase; | ||
use crate::utils::PlaceRepacker; | ||
use crate::utils::validity::HasValidityCheck; | ||
|
||
#[derive(Clone, PartialEq, Eq, Debug)] | ||
pub struct EvalStmtData<T> { | ||
pub(crate) pre_operands: T, | ||
pub(crate) post_operands: T, | ||
pub(crate) pre_main: T, | ||
pub(crate) post_main: T, | ||
} | ||
|
||
impl<'tcx, T: ToJsonWithRepacker<'tcx>> ToJsonWithRepacker<'tcx> for EvalStmtData<T> { | ||
fn to_json(&self, repacker: PlaceRepacker<'_, 'tcx>) -> serde_json::Value { | ||
json!({ | ||
"pre_operands": self.pre_operands.to_json(repacker), | ||
"post_operands": self.post_operands.to_json(repacker), | ||
"pre_main": self.pre_main.to_json(repacker), | ||
"post_main": self.post_main.to_json(repacker), | ||
}) | ||
} | ||
} | ||
|
||
impl<T: Default> Default for EvalStmtData<T> { | ||
fn default() -> Self { | ||
Self { | ||
pre_operands: T::default(), | ||
post_operands: T::default(), | ||
pre_main: T::default(), | ||
post_main: T::default(), | ||
} | ||
} | ||
} | ||
|
||
impl<T> EvalStmtData<T> { | ||
pub fn map<U>(self, f: impl Fn(T) -> U) -> EvalStmtData<U> { | ||
EvalStmtData { | ||
pre_operands: f(self.pre_operands), | ||
post_operands: f(self.post_operands), | ||
pre_main: f(self.pre_main), | ||
post_main: f(self.post_main), | ||
} | ||
} | ||
|
||
pub fn iter(&self) -> impl Iterator<Item = (EvalStmtPhase, &T)> { | ||
[ | ||
(EvalStmtPhase::PreOperands, &self.pre_operands), | ||
(EvalStmtPhase::PostOperands, &self.post_operands), | ||
(EvalStmtPhase::PreMain, &self.pre_main), | ||
(EvalStmtPhase::PostMain, &self.post_main), | ||
] | ||
.into_iter() | ||
} | ||
|
||
#[allow(unused)] | ||
pub(crate) fn iter_mut(&mut self) -> impl Iterator<Item = (EvalStmtPhase, &mut T)> { | ||
[ | ||
(EvalStmtPhase::PreOperands, &mut self.pre_operands), | ||
(EvalStmtPhase::PostOperands, &mut self.post_operands), | ||
(EvalStmtPhase::PreMain, &mut self.pre_main), | ||
(EvalStmtPhase::PostMain, &mut self.post_main), | ||
] | ||
.into_iter() | ||
} | ||
|
||
pub(crate) fn get(&self, phase: EvalStmtPhase) -> &T { | ||
match phase { | ||
EvalStmtPhase::PreOperands => &self.pre_operands, | ||
EvalStmtPhase::PostOperands => &self.post_operands, | ||
EvalStmtPhase::PreMain => &self.pre_main, | ||
EvalStmtPhase::PostMain => &self.post_main, | ||
} | ||
} | ||
pub fn post_main(&self) -> &T { | ||
&self.post_main | ||
} | ||
} | ||
|
||
impl<T> std::ops::Index<EvalStmtPhase> for EvalStmtData<T> { | ||
type Output = T; | ||
|
||
fn index(&self, phase: EvalStmtPhase) -> &Self::Output { | ||
self.get(phase) | ||
} | ||
} | ||
|
||
impl<T> std::ops::IndexMut<EvalStmtPhase> for EvalStmtData<T> { | ||
fn index_mut(&mut self, phase: EvalStmtPhase) -> &mut Self::Output { | ||
match phase { | ||
EvalStmtPhase::PreOperands => &mut self.pre_operands, | ||
EvalStmtPhase::PostOperands => &mut self.post_operands, | ||
EvalStmtPhase::PreMain => &mut self.pre_main, | ||
EvalStmtPhase::PostMain => &mut self.post_main, | ||
} | ||
} | ||
} | ||
|
||
impl<'tcx> HasValidityCheck<'tcx> for BorrowsStates<'tcx> { | ||
fn check_validity(&self, repacker: PlaceRepacker<'_, 'tcx>) -> Result<(), String> { | ||
self.pre_operands.check_validity(repacker)?; | ||
self.post_operands.check_validity(repacker)?; | ||
self.pre_main.check_validity(repacker)?; | ||
self.post_main.check_validity(repacker) | ||
} | ||
} |
Oops, something went wrong.