diff options
| author | Manish Goregaokar <manishsmail@gmail.com> | 2020-06-26 13:57:43 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-06-26 13:57:43 -0700 |
| commit | 83f6d0a93f8159fe18b4a9ccfaf395a0fbabf07c (patch) | |
| tree | 2397c79b928cf316df830bf377fdedd524a7115f | |
| parent | bc10bb02f5a763ffeea906c48f90114e4bfab625 (diff) | |
| parent | 1a355a21ebbe70ebfa2856dee2becc18d9ab3b13 (diff) | |
| download | rust-83f6d0a93f8159fe18b4a9ccfaf395a0fbabf07c.tar.gz rust-83f6d0a93f8159fe18b4a9ccfaf395a0fbabf07c.zip | |
Rollup merge of #73728 - oli-obk:const_prop_cleanup, r=wesleywiser
Document some invariants correctly/more r? @wesleywiser
| -rw-r--r-- | src/librustc_mir/transform/const_prop.rs | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index 19337c520f9..e1c5a4f5b18 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -350,14 +350,20 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { } fn get_const(&self, place: Place<'tcx>) -> Option<OpTy<'tcx>> { - let op = self.ecx.eval_place_to_op(place, None).ok(); + let op = match self.ecx.eval_place_to_op(place, None) { + Ok(op) => op, + Err(e) => { + trace!("get_const failed: {}", e); + return None; + } + }; // Try to read the local as an immediate so that if it is representable as a scalar, we can // handle it as such, but otherwise, just return the value as is. - match op.map(|ret| self.ecx.try_read_immediate(ret)) { - Some(Ok(Ok(imm))) => Some(imm.into()), + Some(match self.ecx.try_read_immediate(op) { + Ok(Ok(imm)) => imm.into(), _ => op, - } + }) } /// Remove `local` from the pool of `Locals`. Allows writing to them, @@ -872,8 +878,9 @@ impl<'mir, 'tcx> MutVisitor<'tcx> for ConstPropagator<'mir, 'tcx> { if let Ok(place_layout) = self.tcx.layout_of(self.param_env.and(place_ty)) { let can_const_prop = self.can_const_prop[place.local]; if let Some(()) = self.const_prop(rval, place_layout, source_info, place) { - // This will return None for variables that are from other blocks, - // so it should be okay to propagate from here on down. + // This will return None if the above `const_prop` invocation only "wrote" a + // type whose creation requires no write. E.g. a generator whose initial state + // consists solely of uninitialized memory (so it doesn't capture any locals). if let Some(value) = self.get_const(place) { if self.should_const_prop(value) { trace!("replacing {:?} with {:?}", rval, value); |
