"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/librustc_mir/transform/const_prop.rs" between
rustc-1.45.0-src.tar.xz and rustc-1.45.2-src.tar.xz

About: Rust is a systems programming language that runs "blazingly fast, prevents nearly all segfaults, and guarantees thread safety" (developed by Mozilla).

const_prop.rs  (rustc-1.45.0-src.tar.xz):const_prop.rs  (rustc-1.45.2-src.tar.xz)
skipping to change at line 583 skipping to change at line 583
trace!( trace!(
"checking CheckedBinaryOp(op = {:?}, left = {:?}, right = {: ?})", "checking CheckedBinaryOp(op = {:?}, left = {:?}, right = {: ?})",
op, op,
left, left,
right right
); );
self.check_binary_op(*op, left, right, source_info)?; self.check_binary_op(*op, left, right, source_info)?;
} }
// Do not try creating references (#67862) // Do not try creating references (#67862)
Rvalue::Ref(_, _, place_ref) => { Rvalue::AddressOf(_, place) | Rvalue::Ref(_, _, place) => {
trace!("skipping Ref({:?})", place_ref); trace!("skipping AddressOf | Ref for {:?}", place);
// This may be creating mutable references or immutable referenc
es to cells.
// If that happens, the pointed to value could be mutated via th
at reference.
// Since we aren't tracking references, the const propagator los
es track of what
// value the local has right now.
// Thus, all locals that have their reference taken
// must not take part in propagation.
Self::remove_const(&mut self.ecx, place.local);
return None; return None;
} }
_ => {} _ => {}
} }
// FIXME we need to revisit this for #67176 // FIXME we need to revisit this for #67176
if rvalue.needs_subst() { if rvalue.needs_subst() {
return None; return None;
skipping to change at line 729 skipping to change at line 737
/// The mode that `ConstProp` is allowed to run in for a given `Local`. /// The mode that `ConstProp` is allowed to run in for a given `Local`.
#[derive(Clone, Copy, Debug, PartialEq)] #[derive(Clone, Copy, Debug, PartialEq)]
enum ConstPropMode { enum ConstPropMode {
/// The `Local` can be propagated into and reads of this `Local` can also be propagated. /// The `Local` can be propagated into and reads of this `Local` can also be propagated.
FullConstProp, FullConstProp,
/// The `Local` can only be propagated into and from its own block. /// The `Local` can only be propagated into and from its own block.
OnlyInsideOwnBlock, OnlyInsideOwnBlock,
/// The `Local` can be propagated into but reads cannot be propagated. /// The `Local` can be propagated into but reads cannot be propagated.
OnlyPropagateInto, OnlyPropagateInto,
/// No propagation is allowed at all. /// The `Local` cannot be part of propagation at all. Any statement
/// referencing it either for reading or writing will not get propagated.
NoPropagation, NoPropagation,
} }
struct CanConstProp { struct CanConstProp {
can_const_prop: IndexVec<Local, ConstPropMode>, can_const_prop: IndexVec<Local, ConstPropMode>,
// False at the beginning. Once set, no more assignments are allowed to that local. // False at the beginning. Once set, no more assignments are allowed to that local.
found_assignment: BitSet<Local>, found_assignment: BitSet<Local>,
// Cache of locals' information // Cache of locals' information
local_kinds: IndexVec<Local, LocalKind>, local_kinds: IndexVec<Local, LocalKind>,
} }
skipping to change at line 796 skipping to change at line 805
| MutatingUse(MutatingUseContext::Call) | MutatingUse(MutatingUseContext::Call)
// Actual store that can possibly even propagate a value // Actual store that can possibly even propagate a value
| MutatingUse(MutatingUseContext::Store) => { | MutatingUse(MutatingUseContext::Store) => {
if !self.found_assignment.insert(local) { if !self.found_assignment.insert(local) {
match &mut self.can_const_prop[local] { match &mut self.can_const_prop[local] {
// If the local can only get propagated in its own block , then we don't have // If the local can only get propagated in its own block , then we don't have
// to worry about multiple assignments, as we'll nuke th e const state at the // to worry about multiple assignments, as we'll nuke th e const state at the
// end of the block anyway, and inside the block we over write previous // end of the block anyway, and inside the block we over write previous
// states as applicable. // states as applicable.
ConstPropMode::OnlyInsideOwnBlock => {} ConstPropMode::OnlyInsideOwnBlock => {}
other => { ConstPropMode::NoPropagation => {}
ConstPropMode::OnlyPropagateInto => {}
other @ ConstPropMode::FullConstProp => {
trace!( trace!(
"local {:?} can't be propagated because of multi ple assignments", "local {:?} can't be propagated because of multi ple assignments",
local, local,
); );
*other = ConstPropMode::NoPropagation; *other = ConstPropMode::NoPropagation;
} }
} }
} }
} }
// Reading constants is allowed an arbitrary number of times // Reading constants is allowed an arbitrary number of times
skipping to change at line 883 skipping to change at line 894
} }
if can_const_prop == ConstPropMode::OnlyInsideOwnBlo ck { if can_const_prop == ConstPropMode::OnlyInsideOwnBlo ck {
trace!( trace!(
"found local restricted to its block. Will r emove it from const-prop after block is finished. Local: {:?}", "found local restricted to its block. Will r emove it from const-prop after block is finished. Local: {:?}",
place.local place.local
); );
self.locals_of_current_block.insert(place.local) ; self.locals_of_current_block.insert(place.local) ;
} }
} }
} }
if can_const_prop == ConstPropMode::OnlyPropagateInto match can_const_prop {
|| can_const_prop == ConstPropMode::NoPropagation ConstPropMode::OnlyInsideOwnBlock => {
{ trace!(
trace!("can't propagate into {:?}", place); "found local restricted to its block. \
if place.local != RETURN_PLACE { Will remove it from const-prop after block is fi
Self::remove_const(&mut self.ecx, place.local); nished. Local: {:?}",
place.local
);
self.locals_of_current_block.insert(place.local);
} }
ConstPropMode::OnlyPropagateInto | ConstPropMode::NoProp
agation => {
trace!("can't propagate into {:?}", place);
if place.local != RETURN_PLACE {
Self::remove_const(&mut self.ecx, place.local);
}
}
ConstPropMode::FullConstProp => {}
} }
} else { } else {
// Const prop failed, so erase the destination, ensuring tha t whatever happens // Const prop failed, so erase the destination, ensuring tha t whatever happens
// from here on, does not know about the previous value. // from here on, does not know about the previous value.
// This is important in case we have // This is important in case we have
// ```rust // ```rust
// let mut x = 42; // let mut x = 42;
// x = SOME_MUTABLE_STATIC; // x = SOME_MUTABLE_STATIC;
// // x must now be undefined // // x must now be undefined
// ``` // ```
// FIXME: we overzealously erase the entire local, because t hat's easier to // FIXME: we overzealously erase the entire local, because t hat's easier to
// implement. // implement.
trace!( trace!(
"propagation into {:?} failed. "propagation into {:?} failed.
Nuking the entire site from orbit, it's the only way to be sure", Nuking the entire site from orbit, it's the only way to be sure",
place, place,
); );
Self::remove_const(&mut self.ecx, place.local); Self::remove_const(&mut self.ecx, place.local);
} }
} else {
trace!(
"cannot propagate into {:?}, because the type of the local i
s generic.",
place,
);
Self::remove_const(&mut self.ecx, place.local);
} }
} else { } else {
match statement.kind { match statement.kind {
StatementKind::StorageLive(local) | StatementKind::StorageDead(l ocal) => { StatementKind::StorageLive(local) | StatementKind::StorageDead(l ocal) => {
let frame = self.ecx.frame_mut(); let frame = self.ecx.frame_mut();
frame.locals[local].value = frame.locals[local].value =
if let StatementKind::StorageLive(_) = statement.kind { if let StatementKind::StorageLive(_) = statement.kind {
LocalValue::Uninitialized LocalValue::Uninitialized
} else { } else {
LocalValue::Dead LocalValue::Dead
 End of changes. 6 change blocks. 
10 lines changed or deleted 42 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)