Skip to content

Commit eda3fa9

Browse files
committed
Move eval_body_using_ecx to the only module it is used in
1 parent 9a82458 commit eda3fa9

File tree

2 files changed

+53
-50
lines changed

2 files changed

+53
-50
lines changed

src/librustc_mir/const_eval.rs

Lines changed: 3 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,16 @@ use std::fmt;
66
use std::hash::Hash;
77

88
use rustc::mir;
9-
use rustc::mir::interpret::ScalarMaybeUndef;
10-
use rustc::ty::layout::{self, LayoutOf, VariantIdx};
11-
use rustc::ty::{self, subst::Subst, TyCtxt};
9+
use rustc::ty::layout::{self, VariantIdx};
10+
use rustc::ty::{self, TyCtxt};
1211

1312
use syntax::{
1413
source_map::{Span, DUMMY_SP},
1514
symbol::Symbol,
1615
};
1716

1817
use crate::interpret::{
19-
intern_const_alloc_recursive, Allocation, ConstValue, GlobalId, ImmTy, Immediate, InterpCx,
20-
InterpResult, MPlaceTy, MemoryKind, OpTy, Scalar, StackPopCleanup,
18+
intern_const_alloc_recursive, Allocation, ConstValue, ImmTy, Immediate, InterpCx, OpTy, Scalar,
2119
};
2220

2321
mod error;
@@ -121,49 +119,6 @@ fn op_to_const<'tcx>(
121119
ecx.tcx.mk_const(ty::Const { val: ty::ConstKind::Value(val), ty: op.layout.ty })
122120
}
123121

124-
// Returns a pointer to where the result lives
125-
fn eval_body_using_ecx<'mir, 'tcx>(
126-
ecx: &mut CompileTimeEvalContext<'mir, 'tcx>,
127-
cid: GlobalId<'tcx>,
128-
body: &'mir mir::Body<'tcx>,
129-
) -> InterpResult<'tcx, MPlaceTy<'tcx>> {
130-
debug!("eval_body_using_ecx: {:?}, {:?}", cid, ecx.param_env);
131-
let tcx = ecx.tcx.tcx;
132-
let layout = ecx.layout_of(body.return_ty().subst(tcx, cid.instance.substs))?;
133-
assert!(!layout.is_unsized());
134-
let ret = ecx.allocate(layout, MemoryKind::Stack);
135-
136-
let name = ty::tls::with(|tcx| tcx.def_path_str(cid.instance.def_id()));
137-
let prom = cid.promoted.map_or(String::new(), |p| format!("::promoted[{:?}]", p));
138-
trace!("eval_body_using_ecx: pushing stack frame for global: {}{}", name, prom);
139-
140-
// Assert all args (if any) are zero-sized types; `eval_body_using_ecx` doesn't
141-
// make sense if the body is expecting nontrivial arguments.
142-
// (The alternative would be to use `eval_fn_call` with an args slice.)
143-
for arg in body.args_iter() {
144-
let decl = body.local_decls.get(arg).expect("arg missing from local_decls");
145-
let layout = ecx.layout_of(decl.ty.subst(tcx, cid.instance.substs))?;
146-
assert!(layout.is_zst())
147-
}
148-
149-
ecx.push_stack_frame(
150-
cid.instance,
151-
body.span,
152-
body,
153-
Some(ret.into()),
154-
StackPopCleanup::None { cleanup: false },
155-
)?;
156-
157-
// The main interpreter loop.
158-
ecx.run()?;
159-
160-
// Intern the result
161-
intern_const_alloc_recursive(ecx, tcx.static_mutability(cid.instance.def_id()), ret)?;
162-
163-
debug!("eval_body_using_ecx done: {:?}", *ret);
164-
Ok(ret)
165-
}
166-
167122
/// Extracts a field of a (variant of a) const.
168123
// this function uses `unwrap` copiously, because an already validated constant must have valid
169124
// fields and can thus never fail outside of compiler bugs

src/librustc_mir/const_eval/query.rs

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
use crate::interpret::eval_nullary_intrinsic;
22
use rustc::hir::def::DefKind;
3+
use rustc::mir;
34
use rustc::mir::interpret::{ConstEvalErr, ErrorHandled};
45
use rustc::traits::Reveal;
6+
use rustc::ty::{self, layout::LayoutOf, subst::Subst, TyCtxt};
57
use rustc::ty::{self, TyCtxt};
68

7-
use crate::interpret::{ConstValue, GlobalId, InterpCx, RawConst, RefTracking};
9+
use crate::interpret::{
10+
intern_const_alloc_recursive, ConstValue, GlobalId, InterpCx, InterpResult, MPlaceTy,
11+
MemoryKind, RawConst, RefTracking, StackPopCleanup,
12+
};
813

914
use super::{
10-
error_to_const_error, eval_body_using_ecx, mk_eval_cx, op_to_const, CompileTimeInterpreter,
15+
error_to_const_error, mk_eval_cx, op_to_const, CompileTimeEvalContext, CompileTimeInterpreter,
1116
};
1217

1318
pub fn note_on_undefined_behavior_error() -> &'static str {
@@ -214,3 +219,46 @@ pub fn const_eval_raw_provider<'tcx>(
214219
}
215220
})
216221
}
222+
223+
// Returns a pointer to where the result lives
224+
fn eval_body_using_ecx<'mir, 'tcx>(
225+
ecx: &mut CompileTimeEvalContext<'mir, 'tcx>,
226+
cid: GlobalId<'tcx>,
227+
body: &'mir mir::Body<'tcx>,
228+
) -> InterpResult<'tcx, MPlaceTy<'tcx>> {
229+
debug!("eval_body_using_ecx: {:?}, {:?}", cid, ecx.param_env);
230+
let tcx = ecx.tcx.tcx;
231+
let layout = ecx.layout_of(body.return_ty().subst(tcx, cid.instance.substs))?;
232+
assert!(!layout.is_unsized());
233+
let ret = ecx.allocate(layout, MemoryKind::Stack);
234+
235+
let name = ty::tls::with(|tcx| tcx.def_path_str(cid.instance.def_id()));
236+
let prom = cid.promoted.map_or(String::new(), |p| format!("::promoted[{:?}]", p));
237+
trace!("eval_body_using_ecx: pushing stack frame for global: {}{}", name, prom);
238+
239+
// Assert all args (if any) are zero-sized types; `eval_body_using_ecx` doesn't
240+
// make sense if the body is expecting nontrivial arguments.
241+
// (The alternative would be to use `eval_fn_call` with an args slice.)
242+
for arg in body.args_iter() {
243+
let decl = body.local_decls.get(arg).expect("arg missing from local_decls");
244+
let layout = ecx.layout_of(decl.ty.subst(tcx, cid.instance.substs))?;
245+
assert!(layout.is_zst())
246+
}
247+
248+
ecx.push_stack_frame(
249+
cid.instance,
250+
body.span,
251+
body,
252+
Some(ret.into()),
253+
StackPopCleanup::None { cleanup: false },
254+
)?;
255+
256+
// The main interpreter loop.
257+
ecx.run()?;
258+
259+
// Intern the result
260+
intern_const_alloc_recursive(ecx, tcx.static_mutability(cid.instance.def_id()), ret)?;
261+
262+
debug!("eval_body_using_ecx done: {:?}", *ret);
263+
Ok(ret)
264+
}

0 commit comments

Comments
 (0)