Skip to content

Commit e598f63

Browse files
committed
Move only usage of take_static_root_alloc to its definition and inline it
1 parent a50e459 commit e598f63

File tree

4 files changed

+19
-24
lines changed

4 files changed

+19
-24
lines changed

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ use crate::errors;
1818
use crate::errors::ConstEvalError;
1919
use crate::interpret::eval_nullary_intrinsic;
2020
use crate::interpret::{
21-
create_static_alloc, intern_const_alloc_recursive, take_static_root_alloc, CtfeValidationMode,
22-
GlobalId, Immediate, InternKind, InterpCx, InterpError, InterpResult, MPlaceTy, MemoryKind,
23-
OpTy, RefTracking, StackPopCleanup,
21+
create_static_alloc, intern_const_alloc_recursive, CtfeValidationMode, GlobalId, Immediate,
22+
InternKind, InterpCx, InterpError, InterpResult, MPlaceTy, MemoryKind, OpTy, RefTracking,
23+
StackPopCleanup,
2424
};
2525

2626
// Returns a pointer to where the result lives
@@ -293,23 +293,13 @@ pub fn eval_static_initializer_provider<'tcx>(
293293
eval_in_interpreter(&mut ecx, cid, true)
294294
}
295295

296-
trait InterpretationResult<'tcx> {
296+
pub trait InterpretationResult<'tcx> {
297297
fn make_result<'mir>(
298298
mplace: MPlaceTy<'tcx>,
299299
ecx: &mut InterpCx<'mir, 'tcx, CompileTimeInterpreter<'mir, 'tcx>>,
300300
) -> Self;
301301
}
302302

303-
impl<'tcx> InterpretationResult<'tcx> for mir::interpret::ConstAllocation<'tcx> {
304-
fn make_result<'mir>(
305-
mplace: MPlaceTy<'tcx>,
306-
ecx: &mut InterpCx<'mir, 'tcx, CompileTimeInterpreter<'mir, 'tcx>>,
307-
) -> Self {
308-
let alloc = take_static_root_alloc(ecx, mplace.ptr().provenance.unwrap().alloc_id());
309-
ecx.tcx.mk_const_alloc(alloc)
310-
}
311-
}
312-
313303
impl<'tcx> InterpretationResult<'tcx> for ConstAlloc<'tcx> {
314304
fn make_result<'mir>(
315305
mplace: MPlaceTy<'tcx>,

compiler/rustc_const_eval/src/interpret/intern.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ pub fn intern_const_alloc_recursive<
175175
// This gives us the initial set of nested allocations, which will then all be processed
176176
// recursively in the loop below.
177177
let mut todo: Vec<_> = if is_static {
178-
// Do not steal the root allocation, we need it later for `take_static_root_alloc`
178+
// Do not steal the root allocation, we need it later to create the return value of `eval_static_initializer`.
179179
// But still change its mutability to match the requested one.
180180
let alloc = ecx.memory.alloc_map.get_mut(&base_alloc_id).unwrap();
181181
alloc.1.mutability = base_mutability;

compiler/rustc_const_eval/src/interpret/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,5 @@ use self::{
3939
};
4040

4141
pub(crate) use self::intrinsics::eval_nullary_intrinsic;
42-
pub(crate) use self::util::{create_static_alloc, take_static_root_alloc};
42+
pub(crate) use self::util::create_static_alloc;
4343
use eval_context::{from_known_layout, mir_assign_valid_types};

compiler/rustc_const_eval/src/interpret/util.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
use crate::const_eval::CompileTimeEvalContext;
1+
use crate::const_eval::{CompileTimeEvalContext, CompileTimeInterpreter, InterpretationResult};
22
use crate::interpret::{MemPlaceMeta, MemoryKind};
33
use rustc_hir::def_id::LocalDefId;
4-
use rustc_middle::mir::interpret::{AllocId, Allocation, InterpResult, Pointer};
4+
use rustc_middle::mir;
5+
use rustc_middle::mir::interpret::{Allocation, InterpResult, Pointer};
56
use rustc_middle::ty::layout::TyAndLayout;
67
use rustc_middle::ty::{
78
self, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor,
89
};
910
use std::ops::ControlFlow;
1011

11-
use super::MPlaceTy;
12+
use super::{InterpCx, MPlaceTy};
1213

1314
/// Checks whether a type contains generic parameters which must be instantiated.
1415
///
@@ -80,11 +81,15 @@ where
8081
}
8182
}
8283

83-
pub(crate) fn take_static_root_alloc<'mir, 'tcx: 'mir>(
84-
ecx: &mut CompileTimeEvalContext<'mir, 'tcx>,
85-
alloc_id: AllocId,
86-
) -> Allocation {
87-
ecx.memory.alloc_map.swap_remove(&alloc_id).unwrap().1
84+
impl<'tcx> InterpretationResult<'tcx> for mir::interpret::ConstAllocation<'tcx> {
85+
fn make_result<'mir>(
86+
mplace: MPlaceTy<'tcx>,
87+
ecx: &mut InterpCx<'mir, 'tcx, CompileTimeInterpreter<'mir, 'tcx>>,
88+
) -> Self {
89+
let alloc_id = mplace.ptr().provenance.unwrap().alloc_id();
90+
let alloc = ecx.memory.alloc_map.swap_remove(&alloc_id).unwrap().1;
91+
ecx.tcx.mk_const_alloc(alloc)
92+
}
8893
}
8994

9095
pub(crate) fn create_static_alloc<'mir, 'tcx: 'mir>(

0 commit comments

Comments
 (0)