Skip to content

Commit b8f8fe9

Browse files
committed
move const_eval out of rustc_mir::interpret
to make sure that it does not access private implementation details
1 parent 63b32e1 commit b8f8fe9

File tree

6 files changed

+22
-19
lines changed

6 files changed

+22
-19
lines changed

src/librustc_mir/interpret/const_eval.rs renamed to src/librustc_mir/const_eval.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// Not in interpret to make sure we do not use private implementation details
12+
1113
use std::fmt;
1214
use std::error::Error;
1315

@@ -26,7 +28,7 @@ use rustc::mir::interpret::{
2628
EvalResult, EvalError, EvalErrorKind, GlobalId,
2729
Scalar, AllocId, Allocation, ConstValue, AllocType,
2830
};
29-
use super::{
31+
use interpret::{self,
3032
Place, PlaceExtra, PlaceTy, MemPlace, OpTy, Operand, Value,
3133
EvalContext, StackPopCleanup, MemoryKind, Memory,
3234
};
@@ -41,7 +43,7 @@ pub fn mk_borrowck_eval_cx<'a, 'mir, 'tcx>(
4143
let param_env = tcx.param_env(instance.def_id());
4244
let mut ecx = EvalContext::new(tcx.at(span), param_env, CompileTimeEvaluator, ());
4345
// insert a stack frame so any queries have the correct substs
44-
ecx.stack.push(super::eval_context::Frame {
46+
ecx.stack.push(interpret::Frame {
4547
block: mir::START_BLOCK,
4648
locals: IndexVec::new(),
4749
instance,
@@ -228,14 +230,14 @@ impl Error for ConstEvalError {
228230
}
229231
}
230232

231-
impl super::IsStatic for ! {
233+
impl interpret::IsStatic for ! {
232234
fn is_static(self) -> bool {
233235
// unreachable
234236
self
235237
}
236238
}
237239

238-
impl<'mir, 'tcx> super::Machine<'mir, 'tcx> for CompileTimeEvaluator {
240+
impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeEvaluator {
239241
type MemoryData = ();
240242
type MemoryKinds = !;
241243

src/librustc_mir/interpret/cast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
3232
}
3333
}
3434

35-
crate fn cast(
35+
pub fn cast(
3636
&mut self,
3737
src: OpTy<'tcx>,
3838
kind: CastKind,

src/librustc_mir/interpret/eval_context.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,15 @@ pub struct EvalContext<'a, 'mir, 'tcx: 'a + 'mir, M: Machine<'mir, 'tcx>> {
5656
pub(crate) stack: Vec<Frame<'mir, 'tcx>>,
5757

5858
/// The maximum number of stack frames allowed
59-
pub(crate) stack_limit: usize,
59+
pub(super) stack_limit: usize,
6060

6161
/// When this value is negative, it indicates the number of interpreter
6262
/// steps *until* the loop detector is enabled. When it is positive, it is
6363
/// the number of steps after the detector has been enabled modulo the loop
6464
/// detector period.
65-
pub(crate) steps_since_detector_enabled: isize,
65+
pub(super) steps_since_detector_enabled: isize,
6666

67-
pub(crate) loop_detector: InfiniteLoopDetector<'a, 'mir, 'tcx, M>,
67+
pub(super) loop_detector: InfiniteLoopDetector<'a, 'mir, 'tcx, M>,
6868
}
6969

7070
/// A stack frame.
@@ -201,7 +201,7 @@ impl<'tcx> LocalValue {
201201
type EvalSnapshot<'a, 'mir, 'tcx, M>
202202
= (M, Vec<Frame<'mir, 'tcx>>, Memory<'a, 'mir, 'tcx, M>);
203203

204-
pub(crate) struct InfiniteLoopDetector<'a, 'mir, 'tcx: 'a + 'mir, M: Machine<'mir, 'tcx>> {
204+
pub(super) struct InfiniteLoopDetector<'a, 'mir, 'tcx: 'a + 'mir, M: Machine<'mir, 'tcx>> {
205205
/// The set of all `EvalSnapshot` *hashes* observed by this detector.
206206
///
207207
/// When a collision occurs in this table, we store the full snapshot in
@@ -652,7 +652,7 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
652652
Ok(())
653653
}
654654

655-
crate fn deallocate_local(&mut self, local: LocalValue) -> EvalResult<'tcx> {
655+
pub(super) fn deallocate_local(&mut self, local: LocalValue) -> EvalResult<'tcx> {
656656
// FIXME: should we tell the user that there was a local which was never written to?
657657
if let LocalValue::Live(Operand::Indirect(MemPlace { ptr, .. })) = local {
658658
trace!("deallocating local");

src/librustc_mir/interpret/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ mod operator;
2020
mod step;
2121
mod terminator;
2222
mod traits;
23-
mod const_eval;
2423
mod validity;
2524
mod intrinsics;
2625

@@ -32,7 +31,12 @@ pub use self::place::{Place, PlaceExtra, PlaceTy, MemPlace, MPlaceTy};
3231

3332
pub use self::memory::{Memory, MemoryKind};
3433

35-
pub use self::const_eval::{
34+
pub use self::machine::{Machine, IsStatic};
35+
36+
pub use self::operand::{Value, ValTy, Operand, OpTy};
37+
38+
// reexports for compatibility
39+
pub use const_eval::{
3640
eval_promoted,
3741
mk_borrowck_eval_cx,
3842
mk_eval_cx,
@@ -43,7 +47,3 @@ pub use self::const_eval::{
4347
const_variant_index,
4448
op_to_const,
4549
};
46-
47-
pub use self::machine::{Machine, IsStatic};
48-
49-
pub use self::operand::{Value, ValTy, Operand, OpTy};

src/librustc_mir/interpret/operand.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
281281
/// Note that for a given layout, this operation will either always fail or always
282282
/// succeed! Whether it succeeds depends on whether the layout can be represented
283283
/// in a `Value`, not on which data is stored there currently.
284-
pub(super) fn try_read_value(
284+
pub(crate) fn try_read_value(
285285
&self,
286286
src: OpTy<'tcx>,
287287
) -> EvalResult<'tcx, Result<Value, MemPlace>> {
@@ -391,7 +391,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
391391
Ok(OpTy { op: Operand::Immediate(value), layout: field_layout })
392392
}
393393

394-
pub(super) fn operand_downcast(
394+
pub fn operand_downcast(
395395
&self,
396396
op: OpTy<'tcx>,
397397
variant: usize,
@@ -497,7 +497,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
497497
}
498498

499499
/// Evaluate a bunch of operands at once
500-
pub(crate) fn eval_operands(
500+
pub(super) fn eval_operands(
501501
&self,
502502
ops: &[mir::Operand<'tcx>],
503503
) -> EvalResult<'tcx, Vec<OpTy<'tcx>>> {

src/librustc_mir/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ pub mod transform;
8282
pub mod util;
8383
pub mod interpret;
8484
pub mod monomorphize;
85+
pub mod const_eval;
8586

8687
pub use hair::pattern::check_crate as matchck_crate;
8788
use rustc::ty::query::Providers;

0 commit comments

Comments
 (0)