use Result<(),()>
instead of Validity enum
This commit is contained in:
parent
cb7f116c04
commit
b890037af3
1 changed files with 35 additions and 54 deletions
|
@ -77,7 +77,7 @@ pub enum TempState {
|
||||||
/// One direct assignment and any number of direct uses.
|
/// One direct assignment and any number of direct uses.
|
||||||
/// A borrow of this temp is promotable if the assigned
|
/// A borrow of this temp is promotable if the assigned
|
||||||
/// value is qualified as constant.
|
/// value is qualified as constant.
|
||||||
Defined { location: Location, uses: usize, valid: Valid },
|
Defined { location: Location, uses: usize, valid: Result<(), ()> },
|
||||||
/// Any other combination of assignments/uses.
|
/// Any other combination of assignments/uses.
|
||||||
Unpromotable,
|
Unpromotable,
|
||||||
/// This temp was part of an rvalue which got extracted
|
/// This temp was part of an rvalue which got extracted
|
||||||
|
@ -85,13 +85,6 @@ pub enum TempState {
|
||||||
PromotedOut,
|
PromotedOut,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
|
||||||
pub enum Valid {
|
|
||||||
Unknown,
|
|
||||||
InValid,
|
|
||||||
Validated,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TempState {
|
impl TempState {
|
||||||
pub fn is_promotable(&self) -> bool {
|
pub fn is_promotable(&self) -> bool {
|
||||||
debug!("is_promotable: self={:?}", self);
|
debug!("is_promotable: self={:?}", self);
|
||||||
|
@ -140,7 +133,7 @@ impl<'tcx> Visitor<'tcx> for Collector<'_, 'tcx> {
|
||||||
match context {
|
match context {
|
||||||
PlaceContext::MutatingUse(MutatingUseContext::Store)
|
PlaceContext::MutatingUse(MutatingUseContext::Store)
|
||||||
| PlaceContext::MutatingUse(MutatingUseContext::Call) => {
|
| PlaceContext::MutatingUse(MutatingUseContext::Call) => {
|
||||||
*temp = TempState::Defined { location, uses: 0, valid: Valid::Unknown };
|
*temp = TempState::Defined { location, uses: 0, valid: Err(()) };
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_ => { /* mark as unpromotable below */ }
|
_ => { /* mark as unpromotable below */ }
|
||||||
|
@ -281,10 +274,7 @@ impl<'tcx> Validator<'_, 'tcx> {
|
||||||
|
|
||||||
fn validate_local(&mut self, local: Local) -> Result<(), Unpromotable> {
|
fn validate_local(&mut self, local: Local) -> Result<(), Unpromotable> {
|
||||||
if let TempState::Defined { location: loc, uses, valid } = self.temps[local] {
|
if let TempState::Defined { location: loc, uses, valid } = self.temps[local] {
|
||||||
match valid {
|
valid.or_else(|_| {
|
||||||
Valid::InValid => Err(Unpromotable),
|
|
||||||
Valid::Validated => Ok(()),
|
|
||||||
Valid::Unknown => {
|
|
||||||
let ok = {
|
let ok = {
|
||||||
let block = &self.body[loc.block];
|
let block = &self.body[loc.block];
|
||||||
let num_stmts = block.statements.len();
|
let num_stmts = block.statements.len();
|
||||||
|
@ -309,26 +299,17 @@ impl<'tcx> Validator<'_, 'tcx> {
|
||||||
}
|
}
|
||||||
TerminatorKind::Yield { .. } => Err(Unpromotable),
|
TerminatorKind::Yield { .. } => Err(Unpromotable),
|
||||||
kind => {
|
kind => {
|
||||||
span_bug!(
|
span_bug!(terminator.source_info.span, "{:?} not promotable", kind);
|
||||||
terminator.source_info.span,
|
|
||||||
"{:?} not promotable",
|
|
||||||
kind
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
self.temps[local] = TempState::Defined {
|
self.temps[local] = match ok {
|
||||||
location: loc,
|
Ok(()) => TempState::Defined { location: loc, uses, valid: Ok(()) },
|
||||||
uses,
|
Err(_) => TempState::Unpromotable,
|
||||||
valid: match ok {
|
|
||||||
Ok(()) => Valid::Validated,
|
|
||||||
Err(_) => Valid::InValid,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
ok
|
ok
|
||||||
}
|
})
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
Err(Unpromotable)
|
Err(Unpromotable)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue