phase29an(p11): populate exitmap presence from exit usage
This commit is contained in:
@ -44,9 +44,24 @@ pub(in crate::mir::builder) fn try_extract_loop_feature_facts(
|
||||
for stmt in body {
|
||||
update_exit_usage_from_stmt(stmt, &mut exit_usage);
|
||||
}
|
||||
let mut kinds_present = BTreeSet::new();
|
||||
if exit_usage.has_return {
|
||||
kinds_present.insert(ExitKindFacts::Return);
|
||||
}
|
||||
if exit_usage.has_break {
|
||||
kinds_present.insert(ExitKindFacts::Break);
|
||||
}
|
||||
if exit_usage.has_continue {
|
||||
kinds_present.insert(ExitKindFacts::Continue);
|
||||
}
|
||||
let exit_map = if kinds_present.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(ExitMapFacts { kinds_present })
|
||||
};
|
||||
Ok(LoopFeatureFacts {
|
||||
exit_usage,
|
||||
exit_map: None,
|
||||
exit_map,
|
||||
value_join: None,
|
||||
cleanup: None,
|
||||
})
|
||||
@ -80,7 +95,7 @@ fn update_exit_usage_from_stmt(stmt: &ASTNode, usage: &mut ExitUsageFacts) {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{try_extract_loop_feature_facts, ExitUsageFacts};
|
||||
use super::{try_extract_loop_feature_facts, ExitKindFacts, ExitUsageFacts};
|
||||
use crate::ast::{ASTNode, LiteralValue, Span};
|
||||
|
||||
fn lit_bool(value: bool) -> ASTNode {
|
||||
@ -117,7 +132,11 @@ mod tests {
|
||||
has_return: true,
|
||||
}
|
||||
);
|
||||
assert!(facts.exit_map.is_none());
|
||||
let exit_map = facts.exit_map.expect("exit_map");
|
||||
assert_eq!(exit_map.kinds_present.len(), 3);
|
||||
assert!(exit_map.kinds_present.contains(&ExitKindFacts::Return));
|
||||
assert!(exit_map.kinds_present.contains(&ExitKindFacts::Break));
|
||||
assert!(exit_map.kinds_present.contains(&ExitKindFacts::Continue));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user