Skip to content

Commit c2afca3

Browse files
committed
Auto merge of #53403 - spastorino:move-out-lazily, r=nikomatsakis
Do not used Move data flow analysis, make it lazy instead Close #53394
2 parents 1114ab6 + a6aa5dd commit c2afca3

File tree

7 files changed

+172
-234
lines changed

7 files changed

+172
-234
lines changed

src/librustc/mir/mod.rs

+63-28
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ use hir::def::CtorKind;
1717
use hir::def_id::DefId;
1818
use hir::{self, HirId, InlineAsm};
1919
use middle::region;
20-
use mir::interpret::{EvalErrorKind, Scalar, ScalarMaybeUndef, ConstValue};
20+
use mir::interpret::{ConstValue, EvalErrorKind, Scalar, ScalarMaybeUndef};
2121
use mir::visit::MirVisitable;
2222
use rustc_apfloat::ieee::{Double, Single};
2323
use rustc_apfloat::Float;
2424
use rustc_data_structures::graph::dominators::{dominators, Dominators};
2525
use rustc_data_structures::graph::{self, GraphPredecessors, GraphSuccessors};
2626
use rustc_data_structures::indexed_vec::{Idx, IndexVec};
27-
use smallvec::SmallVec;
2827
use rustc_data_structures::sync::Lrc;
2928
use rustc_data_structures::sync::ReadGuard;
3029
use rustc_serialize as serialize;
30+
use smallvec::SmallVec;
3131
use std::borrow::Cow;
3232
use std::fmt::{self, Debug, Formatter, Write};
3333
use std::ops::{Index, IndexMut};
@@ -203,6 +203,35 @@ impl<'tcx> Mir<'tcx> {
203203
ReadGuard::map(self.predecessors(), |p| &p[bb])
204204
}
205205

206+
#[inline]
207+
pub fn predecessor_locations(&self, loc: Location) -> impl Iterator<Item = Location> + '_ {
208+
let if_zero_locations = if loc.statement_index == 0 {
209+
let predecessor_blocks = self.predecessors_for(loc.block);
210+
let num_predecessor_blocks = predecessor_blocks.len();
211+
Some(
212+
(0..num_predecessor_blocks)
213+
.map(move |i| predecessor_blocks[i])
214+
.map(move |bb| self.terminator_loc(bb)),
215+
)
216+
} else {
217+
None
218+
};
219+
220+
let if_not_zero_locations = if loc.statement_index == 0 {
221+
None
222+
} else {
223+
Some(Location {
224+
block: loc.block,
225+
statement_index: loc.statement_index - 1,
226+
})
227+
};
228+
229+
if_zero_locations
230+
.into_iter()
231+
.flatten()
232+
.chain(if_not_zero_locations)
233+
}
234+
206235
#[inline]
207236
pub fn dominators(&self) -> Dominators<BasicBlock> {
208237
dominators(self)
@@ -555,13 +584,15 @@ impl_stable_hash_for!(struct self::VarBindingForm<'tcx> {
555584
});
556585

557586
mod binding_form_impl {
558-
use rustc_data_structures::stable_hasher::{HashStable, StableHasher, StableHasherResult};
559587
use ich::StableHashingContext;
588+
use rustc_data_structures::stable_hasher::{HashStable, StableHasher, StableHasherResult};
560589

561590
impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for super::BindingForm<'tcx> {
562-
fn hash_stable<W: StableHasherResult>(&self,
563-
hcx: &mut StableHashingContext<'a>,
564-
hasher: &mut StableHasher<W>) {
591+
fn hash_stable<W: StableHasherResult>(
592+
&self,
593+
hcx: &mut StableHashingContext<'a>,
594+
hasher: &mut StableHasher<W>,
595+
) {
565596
use super::BindingForm::*;
566597
::std::mem::discriminant(self).hash_stable(hcx, hasher);
567598

@@ -1478,16 +1509,17 @@ impl<'tcx> TerminatorKind<'tcx> {
14781509
.map(|&u| {
14791510
let mut s = String::new();
14801511
let c = ty::Const {
1481-
val: ConstValue::Scalar(Scalar::Bits {
1512+
val: ConstValue::Scalar(
1513+
Scalar::Bits {
14821514
bits: u,
14831515
size: size.bytes() as u8,
1484-
}.into()),
1516+
}.into(),
1517+
),
14851518
ty: switch_ty,
14861519
};
14871520
fmt_const_val(&mut s, &c).unwrap();
14881521
s.into()
1489-
})
1490-
.chain(iter::once(String::from("otherwise").into()))
1522+
}).chain(iter::once(String::from("otherwise").into()))
14911523
.collect()
14921524
}
14931525
Call {
@@ -2017,7 +2049,13 @@ pub enum AggregateKind<'tcx> {
20172049
/// active field number and is present only for union expressions
20182050
/// -- e.g. for a union expression `SomeUnion { c: .. }`, the
20192051
/// active field index would identity the field `c`
2020-
Adt(&'tcx AdtDef, usize, &'tcx Substs<'tcx>, Option<CanonicalTy<'tcx>>, Option<usize>),
2052+
Adt(
2053+
&'tcx AdtDef,
2054+
usize,
2055+
&'tcx Substs<'tcx>,
2056+
Option<CanonicalTy<'tcx>>,
2057+
Option<usize>,
2058+
),
20212059

20222060
Closure(DefId, ClosureSubsts<'tcx>),
20232061
Generator(DefId, GeneratorSubsts<'tcx>, hir::GeneratorMovability),
@@ -2267,7 +2305,7 @@ pub fn fmt_const_val(f: &mut impl Write, const_val: &ty::Const) -> fmt::Result {
22672305
return write!(f, "{:?}{}", ((bits as i128) << shift) >> shift, i);
22682306
}
22692307
Char => return write!(f, "{:?}", ::std::char::from_u32(bits as u32).unwrap()),
2270-
_ => {},
2308+
_ => {}
22712309
}
22722310
}
22732311
// print function definitons
@@ -2283,14 +2321,12 @@ pub fn fmt_const_val(f: &mut impl Write, const_val: &ty::Const) -> fmt::Result {
22832321
let alloc = tcx.alloc_map.lock().get(ptr.alloc_id);
22842322
if let Some(interpret::AllocType::Memory(alloc)) = alloc {
22852323
assert_eq!(len as usize as u128, len);
2286-
let slice = &alloc
2287-
.bytes
2288-
[(ptr.offset.bytes() as usize)..]
2289-
[..(len as usize)];
2324+
let slice =
2325+
&alloc.bytes[(ptr.offset.bytes() as usize)..][..(len as usize)];
22902326
let s = ::std::str::from_utf8(slice).expect("non utf8 str from miri");
22912327
write!(f, "{:?}", s)
22922328
} else {
2293-
write!(f, "pointer to erroneous constant {:?}, {:?}", ptr, len)
2329+
write!(f, "pointer to erroneous constant {:?}, {:?}", ptr, len)
22942330
}
22952331
});
22962332
}
@@ -2821,15 +2857,13 @@ impl<'tcx> TypeFoldable<'tcx> for Rvalue<'tcx> {
28212857
let kind = box match **kind {
28222858
AggregateKind::Array(ty) => AggregateKind::Array(ty.fold_with(folder)),
28232859
AggregateKind::Tuple => AggregateKind::Tuple,
2824-
AggregateKind::Adt(def, v, substs, user_ty, n) => {
2825-
AggregateKind::Adt(
2826-
def,
2827-
v,
2828-
substs.fold_with(folder),
2829-
user_ty.fold_with(folder),
2830-
n,
2831-
)
2832-
}
2860+
AggregateKind::Adt(def, v, substs, user_ty, n) => AggregateKind::Adt(
2861+
def,
2862+
v,
2863+
substs.fold_with(folder),
2864+
user_ty.fold_with(folder),
2865+
n,
2866+
),
28332867
AggregateKind::Closure(id, substs) => {
28342868
AggregateKind::Closure(id, substs.fold_with(folder))
28352869
}
@@ -2860,8 +2894,9 @@ impl<'tcx> TypeFoldable<'tcx> for Rvalue<'tcx> {
28602894
(match **kind {
28612895
AggregateKind::Array(ty) => ty.visit_with(visitor),
28622896
AggregateKind::Tuple => false,
2863-
AggregateKind::Adt(_, _, substs, user_ty, _) =>
2864-
substs.visit_with(visitor) || user_ty.visit_with(visitor),
2897+
AggregateKind::Adt(_, _, substs, user_ty, _) => {
2898+
substs.visit_with(visitor) || user_ty.visit_with(visitor)
2899+
}
28652900
AggregateKind::Closure(_, substs) => substs.visit_with(visitor),
28662901
AggregateKind::Generator(_, substs, _) => substs.visit_with(visitor),
28672902
}) || fields.visit_with(visitor)

0 commit comments

Comments
 (0)