Skip to content

Commit

Permalink
Merge pull request #100 from willcrichton/dev
Browse files Browse the repository at this point in the history
Update to nightly-2024-12-01
  • Loading branch information
willcrichton authored Dec 3, 2024
2 parents 74df653 + aefec8c commit bddaaae
Show file tree
Hide file tree
Showing 23 changed files with 205 additions and 202 deletions.
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ exclude = ["ide/src/tests/mock_project"]
resolver = "2"

[workspace.dependencies]
rustc_plugin = "=0.8.0-nightly-2024-01-06"
rustc_utils = {version = "=0.8.0-nightly-2024-01-06", features = ["indexical"]}
rustc_plugin = "=0.11.0-nightly-2024-12-01"
rustc_utils = {version = "=0.11.0-nightly-2024-12-01", features = ["indexical"]}
indexical = {version = "0.3.1", default-features = false, features = ["rustc"]}

[profile.bench]
Expand Down
47 changes: 23 additions & 24 deletions crates/flowistry/benches/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,36 +79,35 @@ impl rustc_driver::Callbacks for Callbacks {
config.override_queries = Some(borrowck_facts::override_queries);
}

fn after_crate_root_parsing<'tcx>(
fn after_analysis<'tcx>(
&mut self,
_compiler: &rustc_interface::interface::Compiler,
queries: &'tcx rustc_interface::Queries<'tcx>,
tcx: TyCtxt<'tcx>,
) -> rustc_driver::Compilation {
queries.global_ctxt().unwrap().enter(|tcx| {
let hir = tcx.hir();
let body_id = hir
.items()
.filter_map(|id| match hir.item(id).kind {
ItemKind::Fn(_, _, body) => Some(body),
_ => None,
})
.next()
.unwrap();
let hir = tcx.hir();
let body_id = hir
.items()
.filter_map(|id| match hir.item(id).kind {
ItemKind::Fn(_, _, body) => Some(body),
_ => None,
})
.next()
.unwrap();

let def_id = hir.body_owner_def_id(body_id);
let body_with_facts = borrowck_facts::get_body_with_borrowck_facts(tcx, def_id);
let def_id = hir.body_owner_def_id(body_id);
let body_with_facts = borrowck_facts::get_body_with_borrowck_facts(tcx, def_id);

for analysis_ty in [AnalysisType::FlowOnly, AnalysisType::FlowAndDeps] {
let bench_id = match analysis_ty {
AnalysisType::FlowOnly => "Flow",
AnalysisType::FlowAndDeps => "Flow + Deps",
};
for analysis_ty in [AnalysisType::FlowOnly, AnalysisType::FlowAndDeps] {
let bench_id = match analysis_ty {
AnalysisType::FlowOnly => "Flow",
AnalysisType::FlowAndDeps => "Flow + Deps",
};

self.group.0.bench_function(bench_id, |b| {
b.iter(|| analysis(tcx, body_id, body_with_facts, analysis_ty))
});
}

self.group.0.bench_function(bench_id, |b| {
b.iter(|| analysis(tcx, body_id, body_with_facts, analysis_ty))
});
}
});
rustc_driver::Compilation::Stop
}
}
Expand Down
39 changes: 19 additions & 20 deletions crates/flowistry/examples/example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,29 +96,28 @@ impl rustc_driver::Callbacks for Callbacks {
config.override_queries = Some(borrowck_facts::override_queries);
}

fn after_crate_root_parsing<'tcx>(
fn after_analysis<'tcx>(
&mut self,
_compiler: &rustc_interface::interface::Compiler,
queries: &'tcx rustc_interface::Queries<'tcx>,
tcx: TyCtxt<'tcx>,
) -> rustc_driver::Compilation {
queries.global_ctxt().unwrap().enter(|tcx| {
let hir = tcx.hir();

// Get the first body we can find
let body_id = hir
.items()
.filter_map(|id| match hir.item(id).kind {
ItemKind::Fn(_, _, body) => Some(body),
_ => None,
})
.next()
.unwrap();

let def_id = hir.body_owner_def_id(body_id);
let body_with_facts = borrowck_facts::get_body_with_borrowck_facts(tcx, def_id);

compute_dependencies(tcx, body_id, body_with_facts)
});
let hir = tcx.hir();

// Get the first body we can find
let body_id = hir
.items()
.filter_map(|id| match hir.item(id).kind {
ItemKind::Fn(_, _, body) => Some(body),
_ => None,
})
.next()
.unwrap();

let def_id = hir.body_owner_def_id(body_id);
let body_with_facts = borrowck_facts::get_body_with_borrowck_facts(tcx, def_id);

compute_dependencies(tcx, body_id, body_with_facts);

rustc_driver::Compilation::Stop
}
}
Expand Down
21 changes: 11 additions & 10 deletions crates/flowistry/src/infoflow/analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use rustc_middle::{
mir::{visit::Visitor, *},
ty::TyCtxt,
};
use rustc_mir_dataflow::{Analysis, AnalysisDomain};
use rustc_mir_dataflow::Analysis;
use rustc_utils::{
mir::{
control_dependencies::ControlDependencies,
Expand Down Expand Up @@ -107,12 +107,15 @@ impl<'a, 'tcx> FlowAnalysis<'a, 'tcx> {
.aliases(place)
.iter()
.flat_map(|alias| self.place_info.conflicts(*alias));
let provenance = place.refs_in_projection().flat_map(|(place_ref, _)| {
self
.place_info
.aliases(Place::from_ref(place_ref, self.tcx))
.iter()
});
let provenance =
place
.refs_in_projection(self.body, self.tcx)
.flat_map(|(place_ref, _)| {
self
.place_info
.aliases(Place::from_ref(place_ref, self.tcx))
.iter()
});
conflicts.chain(provenance).copied().collect()
}

Expand Down Expand Up @@ -231,7 +234,7 @@ impl<'a, 'tcx> FlowAnalysis<'a, 'tcx> {
}
}

impl<'a, 'tcx> AnalysisDomain<'tcx> for FlowAnalysis<'a, 'tcx> {
impl<'a, 'tcx> Analysis<'tcx> for FlowAnalysis<'a, 'tcx> {
type Domain = FlowDomain<'tcx>;

const NAME: &'static str = "FlowAnalysis";
Expand All @@ -251,9 +254,7 @@ impl<'a, 'tcx> AnalysisDomain<'tcx> for FlowAnalysis<'a, 'tcx> {
}
}
}
}

impl<'a, 'tcx> Analysis<'tcx> for FlowAnalysis<'a, 'tcx> {
fn apply_statement_effect(
&mut self,
state: &mut Self::Domain,
Expand Down
2 changes: 1 addition & 1 deletion crates/flowistry/src/infoflow/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub type FlowResults<'a, 'tcx> = engine::AnalysisResults<'tcx, FlowAnalysis<'a,

thread_local! {
pub(super) static BODY_STACK: RefCell<Vec<BodyId>> =
RefCell::new(Vec::new());
const { RefCell::new(Vec::new()) };
}

/// Computes information flow for a MIR body.
Expand Down
13 changes: 6 additions & 7 deletions crates/flowistry/src/infoflow/recursive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,12 @@ impl<'tcx> FlowAnalysis<'_, 'tcx> {
}
};

let unsafety = tcx.mir_unsafety_check_result(def_id.expect_local());
if !unsafety.used_unsafe_blocks.is_empty() {
debug!(" Func contains unsafe blocks");
return false;
}
// TODO(wcrichto, 2024-12-02): mir_unsafety_check_result got removed, need to find a replacement
// let unsafety = tcx.mir_unsafety_check_result(def_id.expect_local());
// if !unsafety.used_unsafe_blocks.is_empty() {
// debug!(" Func contains unsafe blocks");
// return false;
// }

let parent_arg_places = utils::arg_places(parent_args);
let any_closure_inputs = parent_arg_places.iter().any(|(_, place)| {
Expand Down Expand Up @@ -168,7 +169,6 @@ impl<'tcx> FlowAnalysis<'_, 'tcx> {

let mut projection = parent_toplevel_arg.projection.to_vec();
let mut ty = parent_toplevel_arg.ty(self.body.local_decls(), tcx);
let parent_param_env = tcx.param_env(self.def_id);
log::debug!("Adding child {child:?} to parent {parent_toplevel_arg:?}");
for elem in child.projection.iter() {
// Don't continue if we reach a private field
Expand All @@ -183,7 +183,6 @@ impl<'tcx> FlowAnalysis<'_, 'tcx> {

ty = ty.projection_ty_core(
tcx,
parent_param_env,
&elem,
|_, field, _| ty.field_ty(tcx, field),
|_, ty| ty,
Expand Down
52 changes: 30 additions & 22 deletions crates/flowistry/src/mir/aliases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ use rustc_data_structures::{
};
use rustc_hir::def_id::DefId;
use rustc_index::{
bit_set::{HybridBitSet, SparseBitMatrix},
bit_set::{ChunkedBitSet, SparseBitMatrix},
IndexVec,
};
use rustc_middle::{
mir::{visit::Visitor, *},
ty::{Region, RegionKind, RegionVid, Ty, TyCtxt, TyKind, TypeAndMut},
ty::{Region, RegionKind, RegionVid, Ty, TyCtxt, TyKind},
};
use rustc_utils::{mir::place::UNKNOWN_REGION, timer::elapsed, PlaceExt};

Expand Down Expand Up @@ -109,13 +109,12 @@ impl<'a, 'tcx> Aliases<'a, 'tcx> {
let start = Instant::now();
let body = &body_with_facts.body;
let static_region = RegionVid::from_usize(0);
let subset_base = &body_with_facts
.input_facts
.as_ref()
.unwrap()
let input_facts = &body_with_facts.input_facts.as_ref().unwrap();
let subset_base = input_facts
.subset_base
.iter()
.cloned()
.map(|(r1, r2, i)| (RegionVid::from(r1), RegionVid::from(r2), i))
.filter(|(r1, r2, i)| constraint_selector(*r1, *r2, *i))
.collect::<Vec<_>>();

Expand Down Expand Up @@ -143,10 +142,10 @@ impl<'a, 'tcx> Aliases<'a, 'tcx> {

// subset('a, 'b) :- subset_base('a, 'b, _).
for (a, b, _) in subset_base {
if ignore_regions.contains(a) || ignore_regions.contains(b) {
if ignore_regions.contains(&a) || ignore_regions.contains(&b) {
continue;
}
subset.insert(*a, *b);
subset.insert(a, b);
}

// subset('static, 'a).
Expand Down Expand Up @@ -186,19 +185,19 @@ impl<'a, 'tcx> Aliases<'a, 'tcx> {
// If p = p^[* p2]: definite('a, ty(p2), p2^[])
// Else: definite('a, ty(p), p^[]).
let mut gather_borrows = GatherBorrows::default();
gather_borrows.visit_body(&body_with_facts.body);
gather_borrows.visit_body(body);
for (region, kind, place) in gather_borrows.borrows {
if place.is_direct(body) {
if place.is_direct(body, tcx) {
contains
.entry(region)
.or_default()
.insert((place, kind.to_mutbl_lossy()));
}

let def = match place.refs_in_projection().next() {
let def = match place.refs_in_projection(body, tcx).next() {
Some((ptr, proj)) => {
let ptr_ty = ptr.ty(body.local_decls(), tcx).ty;
(ptr_ty.builtin_deref(true).unwrap().ty, proj.to_vec())
(ptr_ty.builtin_deref(true).unwrap(), proj.to_vec())
}
None => (
body.local_decls()[place.local].ty,
Expand Down Expand Up @@ -251,10 +250,12 @@ impl<'a, 'tcx> Aliases<'a, 'tcx> {
.rows()
.flat_map(|r1| subset.iter(r1).map(move |r2| (r1, r2)))
.collect::<Vec<_>>();
let subset_graph = VecGraph::new(num_regions, edge_pairs);
let subset_graph = VecGraph::<_, false>::new(num_regions, edge_pairs);
let subset_sccs = Sccs::<RegionVid, RegionSccIndex>::new(&subset_graph);
let mut scc_to_regions =
IndexVec::from_elem_n(HybridBitSet::new_empty(num_regions), subset_sccs.num_sccs());
let mut scc_to_regions = IndexVec::from_elem_n(
ChunkedBitSet::new_empty(num_regions),
subset_sccs.num_sccs(),
);
for r in all_regions.clone() {
let scc = subset_sccs.scc(r);
scc_to_regions[scc].insert(r);
Expand Down Expand Up @@ -344,6 +345,9 @@ impl<'a, 'tcx> Aliases<'a, 'tcx> {
"Final places in loan set: {}",
contains.values().map(|set| set.len()).sum::<usize>()
);

log::trace!("contains: {contains:#?}");

contains
}

Expand All @@ -368,24 +372,28 @@ impl<'a, 'tcx> Aliases<'a, 'tcx> {
aliases.insert(place);

// Places with no derefs, or derefs from arguments, have no aliases
if place.is_direct(self.body) {
if place.is_direct(self.body, self.tcx) {
return aliases;
}

// place = after[*ptr]
let (ptr, after) = place.refs_in_projection().last().unwrap();
let (ptr, after) = place
.refs_in_projection(self.body, self.tcx)
.last()
.unwrap();

// ptr : &'region orig_ty
let ptr_ty = ptr.ty(self.body.local_decls(), self.tcx).ty;
let (region, orig_ty) = match ptr_ty.kind() {
_ if ptr_ty.is_box() => (UNKNOWN_REGION, ptr_ty.boxed_ty()),
TyKind::RawPtr(TypeAndMut { ty, .. }) => (UNKNOWN_REGION, *ty),
_ if ptr_ty.is_box() => (
UNKNOWN_REGION,
ptr_ty.boxed_ty().expect("Could not unbox boxed type??"),
),
TyKind::RawPtr(ty, _) => (UNKNOWN_REGION, *ty),
TyKind::Ref(Region(Interned(RegionKind::ReVar(region), _)), ty, _) => {
(*region, *ty)
}
_ => {
return aliases;
}
_ => return aliases,
};

// For each p ∈ loans('region),
Expand Down
Loading

0 comments on commit bddaaae

Please sign in to comment.