Skip to content

Commit

Permalink
Update const prop
Browse files Browse the repository at this point in the history
  • Loading branch information
jonas-schievink committed Apr 20, 2020
1 parent 0fda0fd commit c5bfbb6
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/librustc_mir/transform/const_prop.rs
Expand Up @@ -331,7 +331,6 @@ struct ConstPropagator<'mir, 'tcx> {
// by accessing them through `ecx` instead.
source_scopes: IndexVec<SourceScope, SourceScopeData>,
local_decls: IndexVec<Local, LocalDecl<'tcx>>,
ret: Option<OpTy<'tcx, ()>>,
// Because we have `MutVisitor` we can't obtain the `SourceInfo` from a `Location`. So we store
// the last known `SourceInfo` here and just keep revisiting it.
source_info: Option<SourceInfo>,
Expand Down Expand Up @@ -403,22 +402,23 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
source_scopes: body.source_scopes.clone(),
//FIXME(wesleywiser) we can't steal this because `Visitor::super_visit_body()` needs it
local_decls: body.local_decls.clone(),
ret: ret.map(Into::into),
source_info: None,
}
}

fn get_const(&self, local: Local) -> Option<OpTy<'tcx>> {
let op = self.ecx.access_local(self.ecx.frame(), local, None).ok();

if local == RETURN_PLACE {
// Try to read the return place 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.
return match self.ret.map(|ret| self.ecx.try_read_immediate(ret)) {
return match op.map(|ret| self.ecx.try_read_immediate(ret)) {
Some(Ok(Ok(imm))) => Some(imm.into()),
_ => self.ret,
_ => op,
};
}

self.ecx.access_local(self.ecx.frame(), local, None).ok()
op
}

fn remove_const(&mut self, local: Local) {
Expand Down

0 comments on commit c5bfbb6

Please sign in to comment.