We're not really using the ConstPropMachine
anymore
This commit is contained in:
parent
89e6a67310
commit
6ecb2aa580
@ -5,7 +5,6 @@ use rustc_const_eval::interpret::{
|
|||||||
self, compile_time_machine, AllocId, ConstAllocation, FnArg, Frame, ImmTy, InterpCx,
|
self, compile_time_machine, AllocId, ConstAllocation, FnArg, Frame, ImmTy, InterpCx,
|
||||||
InterpResult, OpTy, PlaceTy, Pointer,
|
InterpResult, OpTy, PlaceTy, Pointer,
|
||||||
};
|
};
|
||||||
use rustc_data_structures::fx::FxHashSet;
|
|
||||||
use rustc_index::bit_set::BitSet;
|
use rustc_index::bit_set::BitSet;
|
||||||
use rustc_index::IndexVec;
|
use rustc_index::IndexVec;
|
||||||
use rustc_middle::mir::visit::{MutatingUseContext, NonMutatingUseContext, PlaceContext, Visitor};
|
use rustc_middle::mir::visit::{MutatingUseContext, NonMutatingUseContext, PlaceContext, Visitor};
|
||||||
@ -49,16 +48,7 @@ pub(crate) macro throw_machine_stop_str($($tt:tt)*) {{
|
|||||||
throw_machine_stop!(Zst)
|
throw_machine_stop!(Zst)
|
||||||
}}
|
}}
|
||||||
|
|
||||||
pub(crate) struct ConstPropMachine {
|
pub(crate) struct ConstPropMachine;
|
||||||
pub written_only_inside_own_block_locals: FxHashSet<Local>,
|
|
||||||
pub can_const_prop: IndexVec<Local, ConstPropMode>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ConstPropMachine {
|
|
||||||
pub fn new(can_const_prop: IndexVec<Local, ConstPropMode>) -> Self {
|
|
||||||
Self { written_only_inside_own_block_locals: Default::default(), can_const_prop }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'mir, 'tcx: 'mir> interpret::Machine<'mir, 'tcx> for ConstPropMachine {
|
impl<'mir, 'tcx: 'mir> interpret::Machine<'mir, 'tcx> for ConstPropMachine {
|
||||||
compile_time_machine!(<'mir, 'tcx>);
|
compile_time_machine!(<'mir, 'tcx>);
|
||||||
@ -132,23 +122,11 @@ impl<'mir, 'tcx: 'mir> interpret::Machine<'mir, 'tcx> for ConstPropMachine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn before_access_local_mut<'a>(
|
fn before_access_local_mut<'a>(
|
||||||
ecx: &'a mut InterpCx<'mir, 'tcx, Self>,
|
_ecx: &'a mut InterpCx<'mir, 'tcx, Self>,
|
||||||
frame: usize,
|
_frame: usize,
|
||||||
local: Local,
|
_local: Local,
|
||||||
) -> InterpResult<'tcx> {
|
) -> InterpResult<'tcx> {
|
||||||
assert_eq!(frame, 0);
|
unreachable!()
|
||||||
match ecx.machine.can_const_prop[local] {
|
|
||||||
ConstPropMode::NoPropagation => {
|
|
||||||
throw_machine_stop_str!(
|
|
||||||
"tried to write to a local that is marked as not propagatable"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
ConstPropMode::OnlyInsideOwnBlock => {
|
|
||||||
ecx.machine.written_only_inside_own_block_locals.insert(local);
|
|
||||||
}
|
|
||||||
ConstPropMode::FullConstProp => {}
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn before_access_global(
|
fn before_access_global(
|
||||||
|
@ -5,6 +5,7 @@ use std::fmt::Debug;
|
|||||||
|
|
||||||
use rustc_const_eval::interpret::{ImmTy, Projectable};
|
use rustc_const_eval::interpret::{ImmTy, Projectable};
|
||||||
use rustc_const_eval::interpret::{InterpCx, InterpResult, OpTy, Scalar};
|
use rustc_const_eval::interpret::{InterpCx, InterpResult, OpTy, Scalar};
|
||||||
|
use rustc_data_structures::fx::FxHashSet;
|
||||||
use rustc_hir::def::DefKind;
|
use rustc_hir::def::DefKind;
|
||||||
use rustc_hir::HirId;
|
use rustc_hir::HirId;
|
||||||
use rustc_index::bit_set::BitSet;
|
use rustc_index::bit_set::BitSet;
|
||||||
@ -76,6 +77,8 @@ struct ConstPropagator<'mir, 'tcx> {
|
|||||||
visited_blocks: BitSet<BasicBlock>,
|
visited_blocks: BitSet<BasicBlock>,
|
||||||
locals: IndexVec<Local, Value<'tcx>>,
|
locals: IndexVec<Local, Value<'tcx>>,
|
||||||
body: &'mir Body<'tcx>,
|
body: &'mir Body<'tcx>,
|
||||||
|
written_only_inside_own_block_locals: FxHashSet<Local>,
|
||||||
|
can_const_prop: IndexVec<Local, ConstPropMode>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
@ -181,12 +184,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
|
|||||||
let param_env = tcx.param_env_reveal_all_normalized(def_id);
|
let param_env = tcx.param_env_reveal_all_normalized(def_id);
|
||||||
|
|
||||||
let can_const_prop = CanConstProp::check(tcx, param_env, body);
|
let can_const_prop = CanConstProp::check(tcx, param_env, body);
|
||||||
let ecx = InterpCx::new(
|
let ecx = InterpCx::new(tcx, tcx.def_span(def_id), param_env, ConstPropMachine);
|
||||||
tcx,
|
|
||||||
tcx.def_span(def_id),
|
|
||||||
param_env,
|
|
||||||
ConstPropMachine::new(can_const_prop),
|
|
||||||
);
|
|
||||||
|
|
||||||
ConstPropagator {
|
ConstPropagator {
|
||||||
ecx,
|
ecx,
|
||||||
@ -196,6 +194,8 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
|
|||||||
visited_blocks: BitSet::new_empty(body.basic_blocks.len()),
|
visited_blocks: BitSet::new_empty(body.basic_blocks.len()),
|
||||||
locals: IndexVec::from_elem_n(Value::Uninit, body.local_decls.len()),
|
locals: IndexVec::from_elem_n(Value::Uninit, body.local_decls.len()),
|
||||||
body,
|
body,
|
||||||
|
can_const_prop,
|
||||||
|
written_only_inside_own_block_locals: Default::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -212,14 +212,14 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
|
|||||||
/// but not reading from them anymore.
|
/// but not reading from them anymore.
|
||||||
fn remove_const(&mut self, local: Local) {
|
fn remove_const(&mut self, local: Local) {
|
||||||
self.locals[local] = Value::Uninit;
|
self.locals[local] = Value::Uninit;
|
||||||
self.ecx.machine.written_only_inside_own_block_locals.remove(&local);
|
self.written_only_inside_own_block_locals.remove(&local);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn access_mut(&mut self, place: &Place<'_>) -> Option<&mut Value<'tcx>> {
|
fn access_mut(&mut self, place: &Place<'_>) -> Option<&mut Value<'tcx>> {
|
||||||
match self.ecx.machine.can_const_prop[place.local] {
|
match self.can_const_prop[place.local] {
|
||||||
ConstPropMode::NoPropagation => return None,
|
ConstPropMode::NoPropagation => return None,
|
||||||
ConstPropMode::OnlyInsideOwnBlock => {
|
ConstPropMode::OnlyInsideOwnBlock => {
|
||||||
self.ecx.machine.written_only_inside_own_block_locals.insert(place.local);
|
self.written_only_inside_own_block_locals.insert(place.local);
|
||||||
}
|
}
|
||||||
ConstPropMode::FullConstProp => {}
|
ConstPropMode::FullConstProp => {}
|
||||||
}
|
}
|
||||||
@ -775,7 +775,7 @@ impl<'tcx> Visitor<'tcx> for ConstPropagator<'_, 'tcx> {
|
|||||||
|
|
||||||
let Some(()) = self.check_rvalue(rvalue, location) else { return };
|
let Some(()) = self.check_rvalue(rvalue, location) else { return };
|
||||||
|
|
||||||
match self.ecx.machine.can_const_prop[place.local] {
|
match self.can_const_prop[place.local] {
|
||||||
// Do nothing if the place is indirect.
|
// Do nothing if the place is indirect.
|
||||||
_ if place.is_indirect() => {}
|
_ if place.is_indirect() => {}
|
||||||
ConstPropMode::NoPropagation => self.ensure_not_propagated(place.local),
|
ConstPropMode::NoPropagation => self.ensure_not_propagated(place.local),
|
||||||
@ -811,7 +811,7 @@ impl<'tcx> Visitor<'tcx> for ConstPropagator<'_, 'tcx> {
|
|||||||
|
|
||||||
match statement.kind {
|
match statement.kind {
|
||||||
StatementKind::SetDiscriminant { ref place, variant_index } => {
|
StatementKind::SetDiscriminant { ref place, variant_index } => {
|
||||||
match self.ecx.machine.can_const_prop[place.local] {
|
match self.can_const_prop[place.local] {
|
||||||
// Do nothing if the place is indirect.
|
// Do nothing if the place is indirect.
|
||||||
_ if place.is_indirect() => {}
|
_ if place.is_indirect() => {}
|
||||||
ConstPropMode::NoPropagation => self.ensure_not_propagated(place.local),
|
ConstPropMode::NoPropagation => self.ensure_not_propagated(place.local),
|
||||||
@ -878,7 +878,7 @@ impl<'tcx> Visitor<'tcx> for ConstPropagator<'_, 'tcx> {
|
|||||||
// which were modified in the current block.
|
// which were modified in the current block.
|
||||||
// Take it out of the ecx so we can get a mutable reference to the ecx for `remove_const`.
|
// Take it out of the ecx so we can get a mutable reference to the ecx for `remove_const`.
|
||||||
let mut written_only_inside_own_block_locals =
|
let mut written_only_inside_own_block_locals =
|
||||||
std::mem::take(&mut self.ecx.machine.written_only_inside_own_block_locals);
|
std::mem::take(&mut self.written_only_inside_own_block_locals);
|
||||||
|
|
||||||
// This loop can get very hot for some bodies: it check each local in each bb.
|
// This loop can get very hot for some bodies: it check each local in each bb.
|
||||||
// To avoid this quadratic behaviour, we only clear the locals that were modified inside
|
// To avoid this quadratic behaviour, we only clear the locals that were modified inside
|
||||||
@ -886,17 +886,13 @@ impl<'tcx> Visitor<'tcx> for ConstPropagator<'_, 'tcx> {
|
|||||||
// The order in which we remove consts does not matter.
|
// The order in which we remove consts does not matter.
|
||||||
#[allow(rustc::potential_query_instability)]
|
#[allow(rustc::potential_query_instability)]
|
||||||
for local in written_only_inside_own_block_locals.drain() {
|
for local in written_only_inside_own_block_locals.drain() {
|
||||||
debug_assert_eq!(
|
debug_assert_eq!(self.can_const_prop[local], ConstPropMode::OnlyInsideOwnBlock);
|
||||||
self.ecx.machine.can_const_prop[local],
|
|
||||||
ConstPropMode::OnlyInsideOwnBlock
|
|
||||||
);
|
|
||||||
self.remove_const(local);
|
self.remove_const(local);
|
||||||
}
|
}
|
||||||
self.ecx.machine.written_only_inside_own_block_locals =
|
self.written_only_inside_own_block_locals = written_only_inside_own_block_locals;
|
||||||
written_only_inside_own_block_locals;
|
|
||||||
|
|
||||||
if cfg!(debug_assertions) {
|
if cfg!(debug_assertions) {
|
||||||
for (local, &mode) in self.ecx.machine.can_const_prop.iter_enumerated() {
|
for (local, &mode) in self.can_const_prop.iter_enumerated() {
|
||||||
match mode {
|
match mode {
|
||||||
ConstPropMode::FullConstProp => {}
|
ConstPropMode::FullConstProp => {}
|
||||||
ConstPropMode::NoPropagation | ConstPropMode::OnlyInsideOwnBlock => {
|
ConstPropMode::NoPropagation | ConstPropMode::OnlyInsideOwnBlock => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user