Generalize initial "not const" assignments
This commit is contained in:
parent
b8e9da7c08
commit
6b01844408
2 changed files with 23 additions and 23 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue