Skip to content

Commit 1c219bb

Browse files
committed
[const-prop] Replace NullaryOp handling with use of InterpCx
1 parent ecc4cc2 commit 1c219bb

File tree

1 file changed

+7
-21
lines changed

1 file changed

+7
-21
lines changed

src/librustc_mir/transform/const_prop.rs

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,15 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
304304
) -> Option<Const<'tcx>> {
305305
let span = source_info.span;
306306
match *rvalue {
307+
Rvalue::Repeat(..) |
308+
Rvalue::Aggregate(..) |
309+
Rvalue::NullaryOp(NullOp::Box, _) |
310+
Rvalue::Discriminant(..) => None,
311+
307312
Rvalue::Use(_) |
308313
Rvalue::Len(_) |
309-
Rvalue::Cast(..) => {
314+
Rvalue::Cast(..) |
315+
Rvalue::NullaryOp(..) => {
310316
self.use_ecx(source_info, |this| {
311317
this.ecx.eval_rvalue_into_place(rvalue, place)?;
312318
this.ecx.eval_place_to_op(place, Some(place_layout))
@@ -317,19 +323,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
317323
let mplace = src.try_as_mplace().ok()?;
318324
Some(ImmTy::from_scalar(mplace.ptr.into(), place_layout).into())
319325
},
320-
Rvalue::Repeat(..) |
321-
Rvalue::Aggregate(..) |
322-
Rvalue::NullaryOp(NullOp::Box, _) |
323-
Rvalue::Discriminant(..) => None,
324326

325-
Rvalue::NullaryOp(NullOp::SizeOf, ty) => {
326-
type_size_of(self.tcx, self.param_env, ty).and_then(|n| Some(
327-
ImmTy::from_uint(
328-
n,
329-
self.tcx.layout_of(self.param_env.and(self.tcx.types.usize)).ok()?,
330-
).into()
331-
))
332-
}
333327
Rvalue::UnaryOp(op, ref arg) => {
334328
let def_id = if self.tcx.is_closure(self.source.def_id()) {
335329
self.tcx.closure_base_def_id(self.source.def_id())
@@ -515,14 +509,6 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
515509
}
516510
}
517511

518-
fn type_size_of<'tcx>(
519-
tcx: TyCtxt<'tcx>,
520-
param_env: ty::ParamEnv<'tcx>,
521-
ty: Ty<'tcx>,
522-
) -> Option<u64> {
523-
tcx.layout_of(param_env.and(ty)).ok().map(|layout| layout.size.bytes())
524-
}
525-
526512
struct CanConstProp {
527513
can_const_prop: IndexVec<Local, bool>,
528514
// false at the beginning, once set, there are not allowed to be any more assignments

0 commit comments

Comments
 (0)