Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
zgrannan committed Feb 12, 2025
1 parent 5c1d6d2 commit bf896be
Show file tree
Hide file tree
Showing 8 changed files with 942 additions and 1,514 deletions.
1,553 changes: 47 additions & 1,506 deletions Cargo.lock

Large diffs are not rendered by default.

17 changes: 9 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ edition = "2021"
build = "build.rs"

[dependencies]
rustc_ast = {path = "/Users/zgrannan/.rustup/toolchains/nightly-2024-09-15-aarch64-apple-darwin/lib/rustlib/rustc-src/rust/compiler/rustc_ast", optional = true}
rustc_borrowck = {path = "/Users/zgrannan/.rustup/toolchains/nightly-2024-09-15-aarch64-apple-darwin/lib/rustlib/rustc-src/rust/compiler/rustc_borrowck", optional = true}
rustc_mir_dataflow = {path = "/Users/zgrannan/.rustup/toolchains/nightly-2024-09-15-aarch64-apple-darwin/lib/rustlib/rustc-src/rust/compiler/rustc_mir_dataflow", optional = true}
rustc_data_structures = {path = "/Users/zgrannan/.rustup/toolchains/nightly-2024-09-15-aarch64-apple-darwin/lib/rustlib/rustc-src/rust/compiler/rustc_data_structures", optional = true}
rustc_hir = {path = "/Users/zgrannan/.rustup/toolchains/nightly-2024-09-15-aarch64-apple-darwin/lib/rustlib/rustc-src/rust/compiler/rustc_hir", optional = true}
rustc_index = {path = "/Users/zgrannan/.rustup/toolchains/nightly-2024-09-15-aarch64-apple-darwin/lib/rustlib/rustc-src/rust/compiler/rustc_index", optional = true}
rustc_middle = {path = "/Users/zgrannan/.rustup/toolchains/nightly-2024-09-15-aarch64-apple-darwin/lib/rustlib/rustc-src/rust/compiler/rustc_middle", optional = true}
rustc_target = {path = "/Users/zgrannan/.rustup/toolchains/nightly-2024-09-15-aarch64-apple-darwin/lib/rustlib/rustc-src/rust/compiler/rustc_target", optional = true}
# For RustRover
# rustc_ast = {path = "~/.rustup/toolchains/nightly-2024-09-15-aarch64-apple-darwin/lib/rustlib/rustc-src/rust/compiler/rustc_ast", optional = true}
# rustc_borrowck = {path = "~/.rustup/toolchains/nightly-2024-09-15-aarch64-apple-darwin/lib/rustlib/rustc-src/rust/compiler/rustc_borrowck", optional = true}
# rustc_mir_dataflow = {path = "~/.rustup/toolchains/nightly-2024-09-15-aarch64-apple-darwin/lib/rustlib/rustc-src/rust/compiler/rustc_mir_dataflow", optional = true}
# rustc_data_structures = {path = "~/.rustup/toolchains/nightly-2024-09-15-aarch64-apple-darwin/lib/rustlib/rustc-src/rust/compiler/rustc_data_structures", optional = true}
# rustc_hir = {path = "~/.rustup/toolchains/nightly-2024-09-15-aarch64-apple-darwin/lib/rustlib/rustc-src/rust/compiler/rustc_hir", optional = true}
# rustc_index = {path = "~/.rustup/toolchains/nightly-2024-09-15-aarch64-apple-darwin/lib/rustlib/rustc-src/rust/compiler/rustc_index", optional = true}
# rustc_middle = {path = "~/.rustup/toolchains/nightly-2024-09-15-aarch64-apple-darwin/lib/rustlib/rustc-src/rust/compiler/rustc_middle", optional = true}
# rustc_target = {path = "~/.rustup/toolchains/nightly-2024-09-15-aarch64-apple-darwin/lib/rustlib/rustc-src/rust/compiler/rustc_target", optional = true}
shell-escape = "0.1.5"
rustversion = "1.0"
itertools = "0.12.0"
Expand Down
57 changes: 57 additions & 0 deletions src/utils/domain_data.rs
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;
}
}
}
108 changes: 108 additions & 0 deletions src/utils/eval_stmt_data.rs
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)
}
}
Loading

0 comments on commit bf896be

Please sign in to comment.