|
10 | 10 |
|
11 | 11 | use borrow_check::location::{LocationIndex, LocationTable};
|
12 | 12 | use dataflow::indexes::BorrowIndex;
|
| 13 | +use polonius_engine::AllFacts as PoloniusAllFacts; |
| 14 | +use polonius_engine::Atom; |
13 | 15 | use rustc::ty::RegionVid;
|
| 16 | +use rustc_data_structures::indexed_vec::Idx; |
14 | 17 | use std::error::Error;
|
15 | 18 | use std::fmt::Debug;
|
16 | 19 | use std::fs::{self, File};
|
17 | 20 | use std::io::Write;
|
18 | 21 | use std::path::Path;
|
19 | 22 |
|
20 |
| -/// The "facts" which are the basis of the NLL borrow analysis. |
21 |
| -#[derive(Default)] |
22 |
| -crate struct AllFacts { |
23 |
| - // `borrow_region(R, B, P)` -- the region R may refer to data from borrow B |
24 |
| - // starting at the point P (this is usually the point *after* a borrow rvalue) |
25 |
| - crate borrow_region: Vec<(RegionVid, BorrowIndex, LocationIndex)>, |
| 23 | +crate type AllFacts = PoloniusAllFacts<RegionVid, BorrowIndex, LocationIndex>; |
26 | 24 |
|
27 |
| - // universal_region(R) -- this is a "free region" within fn body |
28 |
| - crate universal_region: Vec<RegionVid>, |
29 |
| - |
30 |
| - // `cfg_edge(P,Q)` for each edge P -> Q in the control flow |
31 |
| - crate cfg_edge: Vec<(LocationIndex, LocationIndex)>, |
32 |
| - |
33 |
| - // `killed(B,P)` when some prefix of the path borrowed at B is assigned at point P |
34 |
| - crate killed: Vec<(BorrowIndex, LocationIndex)>, |
35 |
| - |
36 |
| - // `outlives(R1, R2, P)` when we require `R1@P: R2@P` |
37 |
| - crate outlives: Vec<(RegionVid, RegionVid, LocationIndex)>, |
38 |
| - |
39 |
| - // `region_live_at(R, P)` when the region R appears in a live variable at P |
40 |
| - crate region_live_at: Vec<(RegionVid, LocationIndex)>, |
41 |
| - |
42 |
| - // `invalidates(P, B)` when the borrow B is invalidated at point P |
43 |
| - crate invalidates: Vec<(LocationIndex, BorrowIndex)>, |
| 25 | +crate trait AllFactsExt { |
| 26 | + fn write_to_dir( |
| 27 | + &self, |
| 28 | + dir: impl AsRef<Path>, |
| 29 | + location_table: &LocationTable, |
| 30 | + ) -> Result<(), Box<dyn Error>>; |
44 | 31 | }
|
45 | 32 |
|
46 |
| -impl AllFacts { |
47 |
| - crate fn write_to_dir( |
| 33 | +impl AllFactsExt for AllFacts { |
| 34 | + fn write_to_dir( |
48 | 35 | &self,
|
49 | 36 | dir: impl AsRef<Path>,
|
50 | 37 | location_table: &LocationTable,
|
@@ -79,6 +66,42 @@ impl AllFacts {
|
79 | 66 | }
|
80 | 67 | }
|
81 | 68 |
|
| 69 | +impl Atom for BorrowIndex { |
| 70 | + fn index(self) -> usize { |
| 71 | + Idx::index(self) |
| 72 | + } |
| 73 | +} |
| 74 | + |
| 75 | +impl From<usize> for BorrowIndex { |
| 76 | + fn from(i: usize) -> BorrowIndex { |
| 77 | + BorrowIndex::new(i) |
| 78 | + } |
| 79 | +} |
| 80 | + |
| 81 | +impl From<BorrowIndex> for usize { |
| 82 | + fn from(vid: BorrowIndex) -> usize { |
| 83 | + Idx::index(vid) |
| 84 | + } |
| 85 | +} |
| 86 | + |
| 87 | +impl Atom for LocationIndex { |
| 88 | + fn index(self) -> usize { |
| 89 | + Idx::index(self) |
| 90 | + } |
| 91 | +} |
| 92 | + |
| 93 | +impl From<usize> for LocationIndex { |
| 94 | + fn from(i: usize) -> LocationIndex { |
| 95 | + LocationIndex::new(i) |
| 96 | + } |
| 97 | +} |
| 98 | + |
| 99 | +impl From<LocationIndex> for usize { |
| 100 | + fn from(vid: LocationIndex) -> usize { |
| 101 | + Idx::index(vid) |
| 102 | + } |
| 103 | +} |
| 104 | + |
82 | 105 | struct FactWriter<'w> {
|
83 | 106 | location_table: &'w LocationTable,
|
84 | 107 | dir: &'w Path,
|
|
0 commit comments