Skip to content

Commit

Permalink
Generalize initial "not const" assignments
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Apr 8, 2019
1 parent b8e9da7 commit 6b01844
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
15 changes: 10 additions & 5 deletions src/librustc_mir/transform/promote_consts.rs
Expand Up @@ -44,8 +44,8 @@ pub enum TempState {
impl TempState {
pub fn is_promotable(&self) -> bool {
debug!("is_promotable: self={:?}", self);
if let TempState::Defined { uses, .. } = *self {
uses > 0
if let TempState::Defined { .. } = *self {
true
} else {
false
}
Expand Down Expand Up @@ -80,9 +80,14 @@ impl<'tcx> Visitor<'tcx> for TempCollector<'tcx> {
context: PlaceContext<'tcx>,
location: Location) {
debug!("visit_local: index={:?} context={:?} location={:?}", index, context, location);
// We're only interested in temporaries
if self.mir.local_kind(index) != LocalKind::Temp {
return;
// We're only interested in temporaries and the return place
match self.mir.local_kind(index) {
| LocalKind::Temp
| LocalKind::ReturnPointer
=> {},
| LocalKind::Arg
| LocalKind::Var
=> return,
}

// Ignore drops, if the temp gets promoted,
Expand Down
31 changes: 13 additions & 18 deletions src/librustc_mir/transform/qualify_consts.rs
Expand Up @@ -631,26 +631,21 @@ impl<'a, 'tcx> Checker<'a, 'tcx> {
};

for (local, decl) in mir.local_decls.iter_enumerated() {
match mir.local_kind(local) {
LocalKind::Arg => {
let qualifs = cx.qualifs_in_any_value_of_ty(decl.ty);
for (per_local, qualif) in &mut cx.per_local.as_mut().zip(qualifs).0 {
if *qualif {
per_local.insert(local);
}
if let LocalKind::Arg = mir.local_kind(local) {
let qualifs = cx.qualifs_in_any_value_of_ty(decl.ty);
for (per_local, qualif) in &mut cx.per_local.as_mut().zip(qualifs).0 {
if *qualif {
per_local.insert(local);
}
cx.per_local[IsNotConst].insert(local);
}

LocalKind::Var if mode == Mode::Fn => {
cx.per_local[IsNotConst].insert(local);
}

LocalKind::Temp if !temps[local].is_promotable() => {
cx.per_local[IsNotConst].insert(local);
}

_ => {}
}
if !temps[local].is_promotable() {
cx.per_local[IsNotConst].insert(local);
}
if let LocalKind::Var = mir.local_kind(local) {
// Sanity check to prevent implicit and explicit promotion of
// named locals
assert!(cx.per_local[IsNotConst].contains(local));
}
}

Expand Down

0 comments on commit 6b01844

Please sign in to comment.