Skip to content

Commit 774159f

Browse files
committed
Mutability DataflowAnalysis
1 parent 1268fe4 commit 774159f

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

crates/flux-refineck/src/ghost_statements/points_to.rs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! This module implements a points-to analysis for mutable references.
22
//!
33
//! We use the result of the analysis to insert ghost statements at the points where pointers (`ptr(l)`)
4-
//! have to be converted to borrows (`&mut T`). For example, given the function
4+
//! have to be converted to borrows (`&mut T`). For example, consider the function
55
//! ```ignore
66
//! fn foo(mut x: i32, mut y: i32, b: bool) {
77
//! let r;
@@ -12,11 +12,11 @@
1212
//! }
1313
//! }
1414
//! ```
15-
//! In the then branch (resp. else) we know `r` must point to `x` (resp. `y`). During refinement checking,
16-
//! we will give `r` types `ptr(x)` and `ptr(y)` in each branch respectively. However, at the join point
17-
//! `r` could pointn to either `x` or `y`. Thus, we use the result of the analysis to insert a ghost
18-
//! statement at the end of each branch to convert the pointers to a borrow `&mut T` for a type `T` that
19-
//! needs to be inferred.
15+
//! In the then branch (resp. else) we know `r` must point to `x` (resp. `y`). Thus, during refinement
16+
//! type checking, we give `r` types `ptr(x)` and `ptr(y)` in each branch respectively. However, at the
17+
//! join point, `r` could point to either `x` or `y` so we must find a type that joins the two pointers.
18+
//! We use the result of the analysis to insert a ghost statement at the end of each branch to convert
19+
//! the pointer to a borrow `&mut i32{v: ...}` and use it as the join.
2020
use std::{collections::VecDeque, fmt, iter, ops::Range};
2121

2222
use flux_common::tracked_span_bug;
@@ -51,11 +51,9 @@ pub(crate) fn add_ghost_statements<'tcx>(
5151
) -> QueryResult {
5252
let map = Map::new(body);
5353
let points_to = PointsToAnalysis::new(&map, fn_sig);
54-
let fixpoint = points_to.iterate_to_fixpoint(genv.tcx(), body, None);
55-
let mut analysis = fixpoint.analysis;
56-
let results = fixpoint.results;
57-
let mut visitor = CollectPointerToBorrows::new(&map, stmts, &results);
58-
visit_reachable_results(body, &mut analysis, &results, &mut visitor);
54+
let results = points_to.iterate_to_fixpoint(genv.tcx(), body, None);
55+
let mut visitor = CollectPointerToBorrows::new(&map, stmts, &results.entry_states);
56+
visit_reachable_results(body, &results, &mut visitor);
5957

6058
Ok(())
6159
}
@@ -213,7 +211,7 @@ impl<'tcx> rustc_mir_dataflow::Analysis<'tcx> for PointsToAnalysis<'_> {
213211
}
214212

215213
fn apply_primary_statement_effect(
216-
&mut self,
214+
&self,
217215
state: &mut Self::Domain,
218216
statement: &mir::Statement<'tcx>,
219217
_location: mir::Location,
@@ -222,7 +220,7 @@ impl<'tcx> rustc_mir_dataflow::Analysis<'tcx> for PointsToAnalysis<'_> {
222220
}
223221

224222
fn apply_primary_terminator_effect<'mir>(
225-
&mut self,
223+
&self,
226224
state: &mut Self::Domain,
227225
terminator: &'mir mir::Terminator<'tcx>,
228226
_location: mir::Location,
@@ -231,7 +229,7 @@ impl<'tcx> rustc_mir_dataflow::Analysis<'tcx> for PointsToAnalysis<'_> {
231229
}
232230

233231
fn apply_call_return_effect(
234-
&mut self,
232+
&self,
235233
state: &mut Self::Domain,
236234
_block: BasicBlock,
237235
return_places: mir::CallReturnPlaces<'_, 'tcx>,
@@ -278,7 +276,7 @@ impl<'a, 'tcx> ResultsVisitor<'tcx, PointsToAnalysis<'a>> for CollectPointerToBo
278276

279277
fn visit_after_primary_statement_effect(
280278
&mut self,
281-
_analysis: &mut PointsToAnalysis<'a>,
279+
_analysis: &PointsToAnalysis<'a>,
282280
state: &State,
283281
_statement: &mir::Statement<'tcx>,
284282
location: mir::Location,
@@ -300,7 +298,7 @@ impl<'a, 'tcx> ResultsVisitor<'tcx, PointsToAnalysis<'a>> for CollectPointerToBo
300298

301299
fn visit_after_primary_terminator_effect(
302300
&mut self,
303-
_analysis: &mut PointsToAnalysis<'a>,
301+
_analysis: &PointsToAnalysis<'a>,
304302
_state: &State,
305303
terminator: &mir::Terminator<'tcx>,
306304
location: mir::Location,

0 commit comments

Comments
 (0)