1
Fork 0

Rollup merge of #139961 - nnethercote:two-rustc_const_eval-cleanups, r=oli-obk

Two `rustc_const_eval` cleanups

r? ``@lcnr``
This commit is contained in:
Matthias Krüger 2025-04-17 17:40:31 +02:00 committed by GitHub
commit 8281a54a1b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 19 additions and 15 deletions

View file

@ -34,7 +34,7 @@ use crate::check_consts::is_fn_or_trait_safe_to_expose_on_stable;
use crate::errors; use crate::errors;
type QualifResults<'mir, 'tcx, Q> = type QualifResults<'mir, 'tcx, Q> =
rustc_mir_dataflow::ResultsCursor<'mir, 'tcx, FlowSensitiveAnalysis<'mir, 'mir, 'tcx, Q>>; rustc_mir_dataflow::ResultsCursor<'mir, 'tcx, FlowSensitiveAnalysis<'mir, 'tcx, Q>>;
#[derive(Copy, Clone, PartialEq, Eq, Debug)] #[derive(Copy, Clone, PartialEq, Eq, Debug)]
enum ConstConditionsHold { enum ConstConditionsHold {

View file

@ -22,17 +22,17 @@ use super::{ConstCx, Qualif, qualifs};
/// qualified immediately after it is borrowed or its address escapes. The borrow must allow for /// qualified immediately after it is borrowed or its address escapes. The borrow must allow for
/// mutation, which includes shared borrows of places with interior mutability. The type of /// mutation, which includes shared borrows of places with interior mutability. The type of
/// borrowed place must contain the qualif. /// borrowed place must contain the qualif.
struct TransferFunction<'a, 'mir, 'tcx, Q> { struct TransferFunction<'mir, 'tcx, Q> {
ccx: &'a ConstCx<'mir, 'tcx>, ccx: &'mir ConstCx<'mir, 'tcx>,
state: &'a mut State, state: &'mir mut State,
_qualif: PhantomData<Q>, _qualif: PhantomData<Q>,
} }
impl<'a, 'mir, 'tcx, Q> TransferFunction<'a, 'mir, 'tcx, Q> impl<'mir, 'tcx, Q> TransferFunction<'mir, 'tcx, Q>
where where
Q: Qualif, Q: Qualif,
{ {
fn new(ccx: &'a ConstCx<'mir, 'tcx>, state: &'a mut State) -> Self { fn new(ccx: &'mir ConstCx<'mir, 'tcx>, state: &'mir mut State) -> Self {
TransferFunction { ccx, state, _qualif: PhantomData } TransferFunction { ccx, state, _qualif: PhantomData }
} }
@ -124,7 +124,7 @@ where
} }
} }
impl<'tcx, Q> Visitor<'tcx> for TransferFunction<'_, '_, 'tcx, Q> impl<'tcx, Q> Visitor<'tcx> for TransferFunction<'_, 'tcx, Q>
where where
Q: Qualif, Q: Qualif,
{ {
@ -228,20 +228,20 @@ where
} }
/// The dataflow analysis used to propagate qualifs on arbitrary CFGs. /// The dataflow analysis used to propagate qualifs on arbitrary CFGs.
pub(super) struct FlowSensitiveAnalysis<'a, 'mir, 'tcx, Q> { pub(super) struct FlowSensitiveAnalysis<'mir, 'tcx, Q> {
ccx: &'a ConstCx<'mir, 'tcx>, ccx: &'mir ConstCx<'mir, 'tcx>,
_qualif: PhantomData<Q>, _qualif: PhantomData<Q>,
} }
impl<'a, 'mir, 'tcx, Q> FlowSensitiveAnalysis<'a, 'mir, 'tcx, Q> impl<'mir, 'tcx, Q> FlowSensitiveAnalysis<'mir, 'tcx, Q>
where where
Q: Qualif, Q: Qualif,
{ {
pub(super) fn new(_: Q, ccx: &'a ConstCx<'mir, 'tcx>) -> Self { pub(super) fn new(_: Q, ccx: &'mir ConstCx<'mir, 'tcx>) -> Self {
FlowSensitiveAnalysis { ccx, _qualif: PhantomData } FlowSensitiveAnalysis { ccx, _qualif: PhantomData }
} }
fn transfer_function(&self, state: &'a mut State) -> TransferFunction<'a, 'mir, 'tcx, Q> { fn transfer_function(&self, state: &'mir mut State) -> TransferFunction<'mir, 'tcx, Q> {
TransferFunction::<Q>::new(self.ccx, state) TransferFunction::<Q>::new(self.ccx, state)
} }
} }
@ -313,7 +313,7 @@ impl JoinSemiLattice for State {
} }
} }
impl<'tcx, Q> Analysis<'tcx> for FlowSensitiveAnalysis<'_, '_, 'tcx, Q> impl<'tcx, Q> Analysis<'tcx> for FlowSensitiveAnalysis<'_, 'tcx, Q>
where where
Q: Qualif, Q: Qualif,
{ {

View file

@ -30,6 +30,7 @@ use super::{
AllocId, Allocation, InterpCx, MPlaceTy, Machine, MemoryKind, PlaceTy, err_ub, interp_ok, AllocId, Allocation, InterpCx, MPlaceTy, Machine, MemoryKind, PlaceTy, err_ub, interp_ok,
}; };
use crate::const_eval; use crate::const_eval;
use crate::const_eval::DummyMachine;
use crate::errors::NestedStaticInThreadLocal; use crate::errors::NestedStaticInThreadLocal;
pub trait CompileTimeMachine<'tcx, T> = Machine< pub trait CompileTimeMachine<'tcx, T> = Machine<
@ -323,14 +324,17 @@ pub fn intern_const_alloc_for_constprop<'tcx, T, M: CompileTimeMachine<'tcx, T>>
interp_ok(()) interp_ok(())
} }
impl<'tcx, M: super::intern::CompileTimeMachine<'tcx, !>> InterpCx<'tcx, M> { impl<'tcx> InterpCx<'tcx, DummyMachine> {
/// A helper function that allocates memory for the layout given and gives you access to mutate /// A helper function that allocates memory for the layout given and gives you access to mutate
/// it. Once your own mutation code is done, the backing `Allocation` is removed from the /// it. Once your own mutation code is done, the backing `Allocation` is removed from the
/// current `Memory` and interned as read-only into the global memory. /// current `Memory` and interned as read-only into the global memory.
pub fn intern_with_temp_alloc( pub fn intern_with_temp_alloc(
&mut self, &mut self,
layout: TyAndLayout<'tcx>, layout: TyAndLayout<'tcx>,
f: impl FnOnce(&mut InterpCx<'tcx, M>, &PlaceTy<'tcx, M::Provenance>) -> InterpResult<'tcx, ()>, f: impl FnOnce(
&mut InterpCx<'tcx, DummyMachine>,
&PlaceTy<'tcx, CtfeProvenance>,
) -> InterpResult<'tcx, ()>,
) -> InterpResult<'tcx, AllocId> { ) -> InterpResult<'tcx, AllocId> {
// `allocate` picks a fresh AllocId that we will associate with its data below. // `allocate` picks a fresh AllocId that we will associate with its data below.
let dest = self.allocate(layout, MemoryKind::Stack)?; let dest = self.allocate(layout, MemoryKind::Stack)?;