Skip to content

Commit 835ce0a

Browse files
committed
New formatting
1 parent d24b93f commit 835ce0a

27 files changed

+476
-263
lines changed

.rustfmt.toml

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
tab_spaces = 2
2-
imports_granularity = "Crate"
2+
imports_granularity = "Crate"
3+
overflow_delimited_expr = true
4+
group_imports = "StdExternalCrate"
5+
spaces_around_ranges = true
6+
use_field_init_shorthand = true
7+
max_width = 90

crates/flowistry/src/extensions.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
use std::cell::RefCell;
2+
13
use fluid_let::fluid_let;
24
use rustc_macros::Encodable;
3-
use std::cell::RefCell;
45

56
#[derive(Debug, PartialEq, Eq, Clone, Copy, Encodable, Hash)]
67
pub enum MutabilityMode {

crates/flowistry/src/indexed/impls.rs

+17-14
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
use super::{DefaultDomain, IndexSet, IndexedDomain, IndexedValue, ToIndex};
2-
use crate::{
3-
mir::utils::{BodyExt, PlaceExt},
4-
to_index_impl,
5-
};
1+
use std::{cell::RefCell, rc::Rc};
2+
63
use rustc_data_structures::fx::{FxHashMap as HashMap, FxHashSet as HashSet};
74
use rustc_index::vec::IndexVec;
85
use rustc_infer::infer::TyCtxtInferExt;
@@ -13,7 +10,12 @@ use rustc_middle::{
1310
};
1411
use rustc_span::def_id::DefId;
1512
use rustc_trait_selection::infer::InferCtxtExt;
16-
use std::{cell::RefCell, rc::Rc};
13+
14+
use super::{DefaultDomain, IndexSet, IndexedDomain, IndexedValue, ToIndex};
15+
use crate::{
16+
mir::utils::{BodyExt, PlaceExt},
17+
to_index_impl,
18+
};
1719

1820
rustc_index::newtype_index! {
1921
pub struct PlaceIndex {
@@ -52,7 +54,11 @@ impl NormalizedPlaces<'tcx> {
5254
let place = tcx.erase_regions(place);
5355
let place = tcx.infer_ctxt().enter(|infcx| {
5456
infcx
55-
.partially_normalize_associated_types_in(ObligationCause::dummy(), param_env, place)
57+
.partially_normalize_associated_types_in(
58+
ObligationCause::dummy(),
59+
param_env,
60+
place,
61+
)
5662
.value
5763
});
5864

@@ -177,13 +183,10 @@ impl LocationDomain {
177183
.filter(|place| place.is_arg(body))
178184
.enumerate()
179185
.map(|(i, place)| {
180-
(
181-
*place,
182-
Location {
183-
block: arg_block,
184-
statement_index: i,
185-
},
186-
)
186+
(*place, Location {
187+
block: arg_block,
188+
statement_index: i,
189+
})
187190
})
188191
.unzip();
189192

crates/flowistry/src/indexed/mod.rs

+50-24
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
1-
use rustc_data_structures::fx::FxHashMap as HashMap;
2-
use rustc_index::{
3-
bit_set::BitSet,
4-
vec::{Idx, IndexVec},
5-
};
6-
use rustc_mir_dataflow::{fmt::DebugWithContext, JoinSemiLattice};
71
use std::{
82
fmt,
93
hash::Hash,
104
ops::{Deref, DerefMut},
115
rc::Rc,
126
};
137

8+
use rustc_data_structures::fx::FxHashMap as HashMap;
9+
use rustc_index::{
10+
bit_set::BitSet,
11+
vec::{Idx, IndexVec},
12+
};
13+
use rustc_mir_dataflow::{fmt::DebugWithContext, JoinSemiLattice};
14+
1415
pub mod impls;
1516

1617
pub trait IndexedValue: Eq + Hash + Clone + Ord + fmt::Debug {
1718
type Index: Idx + ToIndex<Self>;
18-
type Domain: IndexedDomain<Index = Self::Index, Value = Self> = DefaultDomain<Self::Index, Self>;
19+
type Domain: IndexedDomain<Index = Self::Index, Value = Self> =
20+
DefaultDomain<Self::Index, Self>;
1921
}
2022

2123
pub trait ToIndex<T: IndexedValue> {
@@ -39,7 +41,10 @@ impl<T: IndexedValue> ToIndex<T> for &T {
3941
macro_rules! to_index_impl {
4042
($t:ty) => {
4143
impl ToIndex<$t> for <$t as IndexedValue>::Index {
42-
fn to_index(&self, _domain: &<$t as IndexedValue>::Domain) -> <$t as IndexedValue>::Index {
44+
fn to_index(
45+
&self,
46+
_domain: &<$t as IndexedValue>::Domain,
47+
) -> <$t as IndexedValue>::Index {
4348
*self
4449
}
4550
}
@@ -281,7 +286,12 @@ where
281286
write!(f, "{}", Escape(elts))
282287
}
283288

284-
fn fmt_diff_with(&self, old: &Self, ctxt: &C, f: &mut fmt::Formatter<'_>) -> fmt::Result {
289+
fn fmt_diff_with(
290+
&self,
291+
old: &Self,
292+
ctxt: &C,
293+
f: &mut fmt::Formatter<'_>,
294+
) -> fmt::Result {
285295
if self == old {
286296
return Ok(());
287297
}
@@ -355,14 +365,21 @@ impl<R: IndexedValue, C: IndexedValue> IndexMatrix<R, C> {
355365
self.ensure_row(row).insert(col)
356366
}
357367

358-
pub fn union_into_row<S2>(&mut self, into: impl ToIndex<R>, from: &IndexSet<C, S2>) -> bool
368+
pub fn union_into_row<S2>(
369+
&mut self,
370+
into: impl ToIndex<R>,
371+
from: &IndexSet<C, S2>,
372+
) -> bool
359373
where
360374
S2: ToSet<C>,
361375
{
362376
self.ensure_row(into).union(&*from.set)
363377
}
364378

365-
pub fn row<'a>(&'a self, row: impl ToIndex<R> + 'a) -> impl Iterator<Item = &'a C> + 'a {
379+
pub fn row<'a>(
380+
&'a self,
381+
row: impl ToIndex<R> + 'a,
382+
) -> impl Iterator<Item = &'a C> + 'a {
366383
let row = row.to_index(&self.row_domain);
367384
self
368385
.matrix
@@ -372,23 +389,25 @@ impl<R: IndexedValue, C: IndexedValue> IndexMatrix<R, C> {
372389
.flatten()
373390
}
374391

375-
pub fn row_set<'a>(&'a self, row: impl ToIndex<R>) -> Option<IndexSet<C, RefSet<'a, C>>> {
392+
pub fn row_set<'a>(
393+
&'a self,
394+
row: impl ToIndex<R>,
395+
) -> Option<IndexSet<C, RefSet<'a, C>>> {
376396
let row = row.to_index(&self.row_domain);
377397
self.matrix.get(&row).map(|set| IndexSet {
378398
set: RefSet(set),
379399
domain: self.col_domain.clone(),
380400
})
381401
}
382402

383-
pub fn rows<'a>(&'a self) -> impl Iterator<Item = (R::Index, IndexSet<C, RefSet<'a, C>>)> + 'a {
403+
pub fn rows<'a>(
404+
&'a self,
405+
) -> impl Iterator<Item = (R::Index, IndexSet<C, RefSet<'a, C>>)> + 'a {
384406
self.matrix.iter().map(move |(row, col)| {
385-
(
386-
*row,
387-
IndexSet {
388-
set: RefSet(col),
389-
domain: self.col_domain.clone(),
390-
},
391-
)
407+
(*row, IndexSet {
408+
set: RefSet(col),
409+
domain: self.col_domain.clone(),
410+
})
392411
})
393412
}
394413

@@ -446,7 +465,9 @@ impl<R: IndexedValue, C: IndexedValue> Clone for IndexMatrix<R, C> {
446465
}
447466
}
448467

449-
impl<R: IndexedValue + fmt::Debug, C: IndexedValue + fmt::Debug> fmt::Debug for IndexMatrix<R, C> {
468+
impl<R: IndexedValue + fmt::Debug, C: IndexedValue + fmt::Debug> fmt::Debug
469+
for IndexMatrix<R, C>
470+
{
450471
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
451472
write!(f, "{{")?;
452473

@@ -468,8 +489,8 @@ impl<R: IndexedValue + fmt::Debug, C: IndexedValue + fmt::Debug> fmt::Debug for
468489
}
469490
}
470491

471-
impl<R: IndexedValue + fmt::Debug, C: IndexedValue + fmt::Debug, Ctx> DebugWithContext<Ctx>
472-
for IndexMatrix<R, C>
492+
impl<R: IndexedValue + fmt::Debug, C: IndexedValue + fmt::Debug, Ctx>
493+
DebugWithContext<Ctx> for IndexMatrix<R, C>
473494
{
474495
fn fmt_with(&self, ctxt: &Ctx, f: &mut fmt::Formatter<'_>) -> fmt::Result {
475496
write!(f, "{{")?;
@@ -489,7 +510,12 @@ impl<R: IndexedValue + fmt::Debug, C: IndexedValue + fmt::Debug, Ctx> DebugWithC
489510
write!(f, "}}<br align=\"left\" />")
490511
}
491512

492-
fn fmt_diff_with(&self, old: &Self, ctxt: &Ctx, f: &mut fmt::Formatter<'_>) -> fmt::Result {
513+
fn fmt_diff_with(
514+
&self,
515+
old: &Self,
516+
ctxt: &Ctx,
517+
f: &mut fmt::Formatter<'_>,
518+
) -> fmt::Result {
493519
if self == old {
494520
return Ok(());
495521
}

crates/flowistry/src/infoflow/analysis.rs

+40-21
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
use std::{cell::RefCell, iter, rc::Rc};
2+
3+
use log::{debug, info};
4+
use rustc_data_structures::fx::FxHashMap as HashMap;
5+
use rustc_hir::{def_id::DefId, BodyId};
6+
use rustc_middle::{
7+
mir::{visit::Visitor, *},
8+
ty::{subst::GenericArgKind, ClosureKind, TyCtxt, TyKind},
9+
};
10+
use rustc_mir_dataflow::{Analysis, AnalysisDomain, Forward, JoinSemiLattice};
11+
112
use super::{FlowResults, BODY_STACK};
213
use crate::{
314
extensions::{is_extension_active, ContextMode, MutabilityMode, REACHED_LIBRARY},
@@ -12,15 +23,6 @@ use crate::{
1223
utils::{self, OperandExt, PlaceCollector, PlaceExt},
1324
},
1425
};
15-
use log::{debug, info};
16-
use rustc_data_structures::fx::FxHashMap as HashMap;
17-
use rustc_hir::{def_id::DefId, BodyId};
18-
use rustc_middle::{
19-
mir::{visit::Visitor, *},
20-
ty::{subst::GenericArgKind, ClosureKind, TyCtxt, TyKind},
21-
};
22-
use rustc_mir_dataflow::{Analysis, AnalysisDomain, Forward, JoinSemiLattice};
23-
use std::{cell::RefCell, iter, rc::Rc};
2426

2527
pub type FlowDomain<'tcx> = IndexMatrix<Place<'tcx>, Location>;
2628

@@ -103,7 +105,8 @@ impl TransferFunction<'_, '_, 'tcx> {
103105

104106
// Remove any conflicts that aren't actually mutable, e.g. if x : &T ends up
105107
// as an alias of y: &mut T
106-
let ignore_mut = is_extension_active(|mode| mode.mutability_mode == MutabilityMode::IgnoreMut);
108+
let ignore_mut =
109+
is_extension_active(|mode| mode.mutability_mode == MutabilityMode::IgnoreMut);
107110
if !ignore_mut {
108111
let body = self.analysis.body;
109112
let tcx = self.analysis.tcx;
@@ -126,7 +129,11 @@ impl TransferFunction<'_, '_, 'tcx> {
126129
}
127130
}
128131

129-
fn recurse_into_call(&mut self, call: &TerminatorKind<'tcx>, location: Location) -> bool {
132+
fn recurse_into_call(
133+
&mut self,
134+
call: &TerminatorKind<'tcx>,
135+
location: Location,
136+
) -> bool {
130137
let tcx = self.analysis.tcx;
131138
let (func, parent_args, destination) = match call {
132139
TerminatorKind::Call {
@@ -248,7 +255,9 @@ impl TransferFunction<'_, '_, 'tcx> {
248255
let parent_aliases = &self.analysis.aliases;
249256
let child_domain = flow.analysis.place_domain();
250257

251-
let translate_child_to_parent = |child: Place<'tcx>, mutated: bool| -> Option<Place<'tcx>> {
258+
let translate_child_to_parent = |child: Place<'tcx>,
259+
mutated: bool|
260+
-> Option<Place<'tcx>> {
252261
if child.local == RETURN_PLACE && child.projection.len() == 0 {
253262
if child.ty(body.local_decls(), tcx).ty.is_unit() {
254263
return None;
@@ -279,13 +288,16 @@ impl TransferFunction<'_, '_, 'tcx> {
279288
let parent_arg_projected = Place::make(parent_toplevel_arg.local, &projection, tcx);
280289

281290
let parent_arg_accessible = {
282-
let mut sub_places = (0..=parent_arg_projected.projection.len()).rev().map(|i| {
283-
Place::make(
284-
parent_arg_projected.local,
285-
&parent_arg_projected.projection[..i],
286-
tcx,
287-
)
288-
});
291+
let mut sub_places =
292+
(0 ..= parent_arg_projected.projection.len())
293+
.rev()
294+
.map(|i| {
295+
Place::make(
296+
parent_arg_projected.local,
297+
&parent_arg_projected.projection[.. i],
298+
tcx,
299+
)
300+
});
289301

290302
sub_places
291303
.find(|sub_place| {
@@ -314,7 +326,9 @@ impl TransferFunction<'_, '_, 'tcx> {
314326
let parent_deps = return_state
315327
.rows()
316328
.filter(|(_, deps)| child_deps.is_superset(deps))
317-
.filter_map(|(row, _)| translate_child_to_parent(*child_domain.value(row), false))
329+
.filter_map(|(row, _)| {
330+
translate_child_to_parent(*child_domain.value(row), false)
331+
})
318332
.collect::<Vec<_>>();
319333

320334
debug!(
@@ -331,7 +345,12 @@ impl TransferFunction<'_, '_, 'tcx> {
331345
}
332346

333347
impl Visitor<'tcx> for TransferFunction<'a, 'b, 'tcx> {
334-
fn visit_assign(&mut self, place: &Place<'tcx>, rvalue: &Rvalue<'tcx>, location: Location) {
348+
fn visit_assign(
349+
&mut self,
350+
place: &Place<'tcx>,
351+
rvalue: &Rvalue<'tcx>,
352+
location: Location,
353+
) {
335354
debug!("Checking {:?}: {:?} = {:?}", location, place, rvalue);
336355
let mut collector = PlaceCollector::default();
337356
collector.visit_rvalue(rvalue, location);

crates/flowistry/src/infoflow/dependencies.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
use log::{debug, trace};
2+
use rustc_middle::mir::*;
3+
use rustc_mir_dataflow::ResultsVisitor;
4+
use rustc_span::Span;
5+
16
use super::{
27
analysis::{FlowAnalysis, FlowDomain},
38
FlowResults,
@@ -11,10 +16,6 @@ use crate::{
1116
mir::utils::PlaceExt,
1217
source_map::{location_to_spans, HirSpanner},
1318
};
14-
use log::{debug, trace};
15-
use rustc_middle::mir::*;
16-
use rustc_mir_dataflow::ResultsVisitor;
17-
use rustc_span::Span;
1819

1920
#[derive(Clone, Copy, Debug)]
2021
pub enum Direction {
@@ -187,7 +188,8 @@ pub fn compute_dependencies(
187188
.iter()
188189
.map(|_| (new_location_set(), new_place_set()))
189190
.collect::<Vec<_>>();
190-
for ((target_places, _), (_, places)) in expanded_targets.iter().zip(outputs.iter_mut()) {
191+
for ((target_places, _), (_, places)) in expanded_targets.iter().zip(outputs.iter_mut())
192+
{
191193
places.union(target_places);
192194
}
193195

0 commit comments

Comments
 (0)