[const-prop] Replace NullaryOp
handling with use of InterpCx
This commit is contained in:
parent
ecc4cc2fc4
commit
1c219bb34b
@ -304,9 +304,15 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
|
|||||||
) -> Option<Const<'tcx>> {
|
) -> Option<Const<'tcx>> {
|
||||||
let span = source_info.span;
|
let span = source_info.span;
|
||||||
match *rvalue {
|
match *rvalue {
|
||||||
|
Rvalue::Repeat(..) |
|
||||||
|
Rvalue::Aggregate(..) |
|
||||||
|
Rvalue::NullaryOp(NullOp::Box, _) |
|
||||||
|
Rvalue::Discriminant(..) => None,
|
||||||
|
|
||||||
Rvalue::Use(_) |
|
Rvalue::Use(_) |
|
||||||
Rvalue::Len(_) |
|
Rvalue::Len(_) |
|
||||||
Rvalue::Cast(..) => {
|
Rvalue::Cast(..) |
|
||||||
|
Rvalue::NullaryOp(..) => {
|
||||||
self.use_ecx(source_info, |this| {
|
self.use_ecx(source_info, |this| {
|
||||||
this.ecx.eval_rvalue_into_place(rvalue, place)?;
|
this.ecx.eval_rvalue_into_place(rvalue, place)?;
|
||||||
this.ecx.eval_place_to_op(place, Some(place_layout))
|
this.ecx.eval_place_to_op(place, Some(place_layout))
|
||||||
@ -317,19 +323,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
|
|||||||
let mplace = src.try_as_mplace().ok()?;
|
let mplace = src.try_as_mplace().ok()?;
|
||||||
Some(ImmTy::from_scalar(mplace.ptr.into(), place_layout).into())
|
Some(ImmTy::from_scalar(mplace.ptr.into(), place_layout).into())
|
||||||
},
|
},
|
||||||
Rvalue::Repeat(..) |
|
|
||||||
Rvalue::Aggregate(..) |
|
|
||||||
Rvalue::NullaryOp(NullOp::Box, _) |
|
|
||||||
Rvalue::Discriminant(..) => None,
|
|
||||||
|
|
||||||
Rvalue::NullaryOp(NullOp::SizeOf, ty) => {
|
|
||||||
type_size_of(self.tcx, self.param_env, ty).and_then(|n| Some(
|
|
||||||
ImmTy::from_uint(
|
|
||||||
n,
|
|
||||||
self.tcx.layout_of(self.param_env.and(self.tcx.types.usize)).ok()?,
|
|
||||||
).into()
|
|
||||||
))
|
|
||||||
}
|
|
||||||
Rvalue::UnaryOp(op, ref arg) => {
|
Rvalue::UnaryOp(op, ref arg) => {
|
||||||
let def_id = if self.tcx.is_closure(self.source.def_id()) {
|
let def_id = if self.tcx.is_closure(self.source.def_id()) {
|
||||||
self.tcx.closure_base_def_id(self.source.def_id())
|
self.tcx.closure_base_def_id(self.source.def_id())
|
||||||
@ -515,14 +509,6 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn type_size_of<'tcx>(
|
|
||||||
tcx: TyCtxt<'tcx>,
|
|
||||||
param_env: ty::ParamEnv<'tcx>,
|
|
||||||
ty: Ty<'tcx>,
|
|
||||||
) -> Option<u64> {
|
|
||||||
tcx.layout_of(param_env.and(ty)).ok().map(|layout| layout.size.bytes())
|
|
||||||
}
|
|
||||||
|
|
||||||
struct CanConstProp {
|
struct CanConstProp {
|
||||||
can_const_prop: IndexVec<Local, bool>,
|
can_const_prop: IndexVec<Local, bool>,
|
||||||
// false at the beginning, once set, there are not allowed to be any more assignments
|
// false at the beginning, once set, there are not allowed to be any more assignments
|
||||||
|
Loading…
Reference in New Issue
Block a user