Move only usage of take_static_root_alloc
to its definition and inline it
This commit is contained in:
parent
d6c999754c
commit
93888cd0a4
4 changed files with 19 additions and 24 deletions
|
@ -18,9 +18,9 @@ use crate::errors;
|
|||
use crate::errors::ConstEvalError;
|
||||
use crate::interpret::eval_nullary_intrinsic;
|
||||
use crate::interpret::{
|
||||
create_static_alloc, intern_const_alloc_recursive, take_static_root_alloc, CtfeValidationMode,
|
||||
GlobalId, Immediate, InternKind, InterpCx, InterpError, InterpResult, MPlaceTy, MemoryKind,
|
||||
OpTy, RefTracking, StackPopCleanup,
|
||||
create_static_alloc, intern_const_alloc_recursive, CtfeValidationMode, GlobalId, Immediate,
|
||||
InternKind, InterpCx, InterpError, InterpResult, MPlaceTy, MemoryKind, OpTy, RefTracking,
|
||||
StackPopCleanup,
|
||||
};
|
||||
|
||||
// Returns a pointer to where the result lives
|
||||
|
@ -293,7 +293,7 @@ pub fn eval_static_initializer_provider<'tcx>(
|
|||
eval_in_interpreter(&mut ecx, cid, true)
|
||||
}
|
||||
|
||||
trait InterpretationResult<'tcx> {
|
||||
pub trait InterpretationResult<'tcx> {
|
||||
/// This function takes the place where the result of the evaluation is stored
|
||||
/// and prepares it for returning it in the appropriate format needed by the specific
|
||||
/// evaluation query.
|
||||
|
@ -303,16 +303,6 @@ trait InterpretationResult<'tcx> {
|
|||
) -> Self;
|
||||
}
|
||||
|
||||
impl<'tcx> InterpretationResult<'tcx> for mir::interpret::ConstAllocation<'tcx> {
|
||||
fn make_result<'mir>(
|
||||
mplace: MPlaceTy<'tcx>,
|
||||
ecx: &mut InterpCx<'mir, 'tcx, CompileTimeInterpreter<'mir, 'tcx>>,
|
||||
) -> Self {
|
||||
let alloc = take_static_root_alloc(ecx, mplace.ptr().provenance.unwrap().alloc_id());
|
||||
ecx.tcx.mk_const_alloc(alloc)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> InterpretationResult<'tcx> for ConstAlloc<'tcx> {
|
||||
fn make_result<'mir>(
|
||||
mplace: MPlaceTy<'tcx>,
|
||||
|
|
|
@ -176,7 +176,7 @@ pub fn intern_const_alloc_recursive<
|
|||
// This gives us the initial set of nested allocations, which will then all be processed
|
||||
// recursively in the loop below.
|
||||
let mut todo: Vec<_> = if is_static {
|
||||
// Do not steal the root allocation, we need it later for `take_static_root_alloc`
|
||||
// Do not steal the root allocation, we need it later to create the return value of `eval_static_initializer`.
|
||||
// But still change its mutability to match the requested one.
|
||||
let alloc = ecx.memory.alloc_map.get_mut(&base_alloc_id).unwrap();
|
||||
alloc.1.mutability = base_mutability;
|
||||
|
|
|
@ -39,5 +39,5 @@ use self::{
|
|||
};
|
||||
|
||||
pub(crate) use self::intrinsics::eval_nullary_intrinsic;
|
||||
pub(crate) use self::util::{create_static_alloc, take_static_root_alloc};
|
||||
pub(crate) use self::util::create_static_alloc;
|
||||
use eval_context::{from_known_layout, mir_assign_valid_types};
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
use crate::const_eval::CompileTimeEvalContext;
|
||||
use crate::const_eval::{CompileTimeEvalContext, CompileTimeInterpreter, InterpretationResult};
|
||||
use crate::interpret::{MemPlaceMeta, MemoryKind};
|
||||
use rustc_hir::def_id::LocalDefId;
|
||||
use rustc_middle::mir::interpret::{AllocId, Allocation, InterpResult, Pointer};
|
||||
use rustc_middle::mir;
|
||||
use rustc_middle::mir::interpret::{Allocation, InterpResult, Pointer};
|
||||
use rustc_middle::ty::layout::TyAndLayout;
|
||||
use rustc_middle::ty::{
|
||||
self, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor,
|
||||
};
|
||||
use std::ops::ControlFlow;
|
||||
|
||||
use super::MPlaceTy;
|
||||
use super::{InterpCx, MPlaceTy};
|
||||
|
||||
/// Checks whether a type contains generic parameters which must be instantiated.
|
||||
///
|
||||
|
@ -80,11 +81,15 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) fn take_static_root_alloc<'mir, 'tcx: 'mir>(
|
||||
ecx: &mut CompileTimeEvalContext<'mir, 'tcx>,
|
||||
alloc_id: AllocId,
|
||||
) -> Allocation {
|
||||
ecx.memory.alloc_map.swap_remove(&alloc_id).unwrap().1
|
||||
impl<'tcx> InterpretationResult<'tcx> for mir::interpret::ConstAllocation<'tcx> {
|
||||
fn make_result<'mir>(
|
||||
mplace: MPlaceTy<'tcx>,
|
||||
ecx: &mut InterpCx<'mir, 'tcx, CompileTimeInterpreter<'mir, 'tcx>>,
|
||||
) -> Self {
|
||||
let alloc_id = mplace.ptr().provenance.unwrap().alloc_id();
|
||||
let alloc = ecx.memory.alloc_map.swap_remove(&alloc_id).unwrap().1;
|
||||
ecx.tcx.mk_const_alloc(alloc)
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn create_static_alloc<'mir, 'tcx: 'mir>(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue