mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
Move only usage of take_static_root_alloc
to its definition and inline it
This commit is contained in:
parent
d6c999754c
commit
93888cd0a4
@ -18,9 +18,9 @@ use crate::errors;
|
|||||||
use crate::errors::ConstEvalError;
|
use crate::errors::ConstEvalError;
|
||||||
use crate::interpret::eval_nullary_intrinsic;
|
use crate::interpret::eval_nullary_intrinsic;
|
||||||
use crate::interpret::{
|
use crate::interpret::{
|
||||||
create_static_alloc, intern_const_alloc_recursive, take_static_root_alloc, CtfeValidationMode,
|
create_static_alloc, intern_const_alloc_recursive, CtfeValidationMode, GlobalId, Immediate,
|
||||||
GlobalId, Immediate, InternKind, InterpCx, InterpError, InterpResult, MPlaceTy, MemoryKind,
|
InternKind, InterpCx, InterpError, InterpResult, MPlaceTy, MemoryKind, OpTy, RefTracking,
|
||||||
OpTy, RefTracking, StackPopCleanup,
|
StackPopCleanup,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Returns a pointer to where the result lives
|
// 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)
|
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
|
/// 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
|
/// and prepares it for returning it in the appropriate format needed by the specific
|
||||||
/// evaluation query.
|
/// evaluation query.
|
||||||
@ -303,16 +303,6 @@ trait InterpretationResult<'tcx> {
|
|||||||
) -> Self;
|
) -> 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> {
|
impl<'tcx> InterpretationResult<'tcx> for ConstAlloc<'tcx> {
|
||||||
fn make_result<'mir>(
|
fn make_result<'mir>(
|
||||||
mplace: MPlaceTy<'tcx>,
|
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
|
// This gives us the initial set of nested allocations, which will then all be processed
|
||||||
// recursively in the loop below.
|
// recursively in the loop below.
|
||||||
let mut todo: Vec<_> = if is_static {
|
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.
|
// But still change its mutability to match the requested one.
|
||||||
let alloc = ecx.memory.alloc_map.get_mut(&base_alloc_id).unwrap();
|
let alloc = ecx.memory.alloc_map.get_mut(&base_alloc_id).unwrap();
|
||||||
alloc.1.mutability = base_mutability;
|
alloc.1.mutability = base_mutability;
|
||||||
|
@ -39,5 +39,5 @@ use self::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
pub(crate) use self::intrinsics::eval_nullary_intrinsic;
|
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};
|
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 crate::interpret::{MemPlaceMeta, MemoryKind};
|
||||||
use rustc_hir::def_id::LocalDefId;
|
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::layout::TyAndLayout;
|
||||||
use rustc_middle::ty::{
|
use rustc_middle::ty::{
|
||||||
self, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor,
|
self, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor,
|
||||||
};
|
};
|
||||||
use std::ops::ControlFlow;
|
use std::ops::ControlFlow;
|
||||||
|
|
||||||
use super::MPlaceTy;
|
use super::{InterpCx, MPlaceTy};
|
||||||
|
|
||||||
/// Checks whether a type contains generic parameters which must be instantiated.
|
/// 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>(
|
impl<'tcx> InterpretationResult<'tcx> for mir::interpret::ConstAllocation<'tcx> {
|
||||||
ecx: &mut CompileTimeEvalContext<'mir, 'tcx>,
|
fn make_result<'mir>(
|
||||||
alloc_id: AllocId,
|
mplace: MPlaceTy<'tcx>,
|
||||||
) -> Allocation {
|
ecx: &mut InterpCx<'mir, 'tcx, CompileTimeInterpreter<'mir, 'tcx>>,
|
||||||
ecx.memory.alloc_map.swap_remove(&alloc_id).unwrap().1
|
) -> 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>(
|
pub(crate) fn create_static_alloc<'mir, 'tcx: 'mir>(
|
||||||
|
Loading…
Reference in New Issue
Block a user