Phase 33 NORM canon test: enforce normalized dev route for P1/P2/JP mini

This commit is contained in:
nyash-codex
2025-12-11 20:54:33 +09:00
parent 59a985b7fa
commit af6f95cd4b
170 changed files with 4423 additions and 1897 deletions

View File

@ -124,10 +124,7 @@ pub fn extract_all_variables(node: &ASTNode) -> HashSet<String> {
/// Future versions may include:
/// - Dominance tree analysis
/// - More sophisticated scope inference
pub(crate) fn is_outer_scope_variable(
var_name: &str,
scope: Option<&LoopScopeShape>,
) -> bool {
pub(crate) fn is_outer_scope_variable(var_name: &str, scope: Option<&LoopScopeShape>) -> bool {
match scope {
// No scope information: be conservative but *not* overstrict.
// We treat unknown as body-local only when we have a LoopScopeShape
@ -162,7 +159,10 @@ pub(crate) fn is_outer_scope_variable(
// ...
// i = i + 1 (latch)
// }
if def_blocks.iter().all(|b| *b == scope.header || *b == scope.latch) {
if def_blocks
.iter()
.all(|b| *b == scope.header || *b == scope.latch)
{
return true;
}
@ -423,7 +423,10 @@ mod tests {
let vars = extract_all_variables(&literal_node);
assert!(vars.is_empty(), "Literal-only condition should extract no variables");
assert!(
vars.is_empty(),
"Literal-only condition should extract no variables"
);
}
#[test]
@ -453,14 +456,16 @@ mod tests {
};
// Phase 170-ultrathink: header+latch ONLY → OuterLocal (carrier variable)
assert!(is_outer_scope_variable("i", Some(&scope)),
"Carrier variable (header+latch only) should be classified as OuterLocal");
assert!(
is_outer_scope_variable("i", Some(&scope)),
"Carrier variable (header+latch only) should be classified as OuterLocal"
);
}
#[test]
fn test_scope_priority_in_add_var() {
// Test Phase 170-ultrathink scope priority system
use super::super::loop_condition_scope::{LoopConditionScope, CondVarScope};
use super::super::loop_condition_scope::{CondVarScope, LoopConditionScope};
let mut scope = LoopConditionScope::new();
@ -472,19 +477,28 @@ mod tests {
// Add same variable as OuterLocal (more restrictive)
scope.add_var("x".to_string(), CondVarScope::OuterLocal);
assert_eq!(scope.vars.len(), 1, "Should not duplicate variable");
assert_eq!(scope.vars[0].scope, CondVarScope::OuterLocal,
"Should upgrade to more restrictive OuterLocal");
assert_eq!(
scope.vars[0].scope,
CondVarScope::OuterLocal,
"Should upgrade to more restrictive OuterLocal"
);
// Try to downgrade to LoopBodyLocal (should be rejected)
scope.add_var("x".to_string(), CondVarScope::LoopBodyLocal);
assert_eq!(scope.vars.len(), 1);
assert_eq!(scope.vars[0].scope, CondVarScope::OuterLocal,
"Should NOT downgrade from OuterLocal to LoopBodyLocal");
assert_eq!(
scope.vars[0].scope,
CondVarScope::OuterLocal,
"Should NOT downgrade from OuterLocal to LoopBodyLocal"
);
// Add same variable as LoopParam (most restrictive)
scope.add_var("x".to_string(), CondVarScope::LoopParam);
assert_eq!(scope.vars.len(), 1);
assert_eq!(scope.vars[0].scope, CondVarScope::LoopParam,
"Should upgrade to most restrictive LoopParam");
assert_eq!(
scope.vars[0].scope,
CondVarScope::LoopParam,
"Should upgrade to most restrictive LoopParam"
);
}
}