feat(joinir): Phase 40-4.1 delete collect_assigned_vars (35 lines)
Breaking: collect_assigned_vars function removed from if_phi.rs Changes: - Delete collect_assigned_vars() function (35 lines) - Make JoinIR route the default in loop_builder.rs - Rewrite collect_assigned_vars_via_joinir() with ast_to_json support - Now detects both Local declarations and Assignment nodes - Add extract_vars_from_json_stmts/stmt helpers - Update tests to use new implementation - phase40_joinir_detects_local_declarations - phase40_joinir_nested_if_local Test results: 407 passed, 11 failed (same as before, no regression) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -122,118 +122,92 @@ fn phase40_mir_conversion_with_meta() {
|
||||
// Phase 40-3.5: A/B Test (Route Switching)
|
||||
// ========================================
|
||||
|
||||
/// Test 4: A/B route switching produces identical results
|
||||
/// Test 4: JoinIR経由の代入変数収集(Local宣言)
|
||||
///
|
||||
/// ## Verification Points
|
||||
/// 1. collect_assigned_vars と collect_assigned_vars_via_joinir が同じ結果を返す
|
||||
/// 2. env flag で経路が正しく切り替わる
|
||||
///
|
||||
/// Note: collect_assigned_vars detects Assignment nodes, not Local declarations.
|
||||
/// JoinIR version detects Local declarations (which is the correct behavior for PHI).
|
||||
/// 1. collect_assigned_vars_via_joinir が Local 宣言を正しく検出
|
||||
/// 2. Phase 40-4.1 削除後もメイン経路として動作
|
||||
#[test]
|
||||
fn phase40_ab_route_switching() {
|
||||
fn phase40_joinir_detects_local_declarations() {
|
||||
use crate::ast::{ASTNode, LiteralValue, Span};
|
||||
use std::collections::BTreeSet;
|
||||
|
||||
// Create simple if body with Assignment: x = 1; y = 2;
|
||||
// Note: Assignment requires target to be a Variable node
|
||||
// Create simple if body with Local declarations: local x = 1; local y = 2;
|
||||
let then_body = vec![
|
||||
ASTNode::Assignment {
|
||||
target: Box::new(ASTNode::Variable {
|
||||
name: "x".to_string(),
|
||||
span: Span::unknown(),
|
||||
}),
|
||||
value: Box::new(ASTNode::Literal {
|
||||
ASTNode::Local {
|
||||
variables: vec!["x".to_string()],
|
||||
initial_values: vec![Some(Box::new(ASTNode::Literal {
|
||||
value: LiteralValue::Integer(1),
|
||||
span: Span::unknown(),
|
||||
}),
|
||||
}))],
|
||||
span: Span::unknown(),
|
||||
},
|
||||
ASTNode::Assignment {
|
||||
target: Box::new(ASTNode::Variable {
|
||||
name: "y".to_string(),
|
||||
span: Span::unknown(),
|
||||
}),
|
||||
value: Box::new(ASTNode::Literal {
|
||||
ASTNode::Local {
|
||||
variables: vec!["y".to_string()],
|
||||
initial_values: vec![Some(Box::new(ASTNode::Literal {
|
||||
value: LiteralValue::Integer(2),
|
||||
span: Span::unknown(),
|
||||
}),
|
||||
}))],
|
||||
span: Span::unknown(),
|
||||
},
|
||||
];
|
||||
|
||||
// Route A: Legacy collect_assigned_vars (detects Assignment)
|
||||
let mut route_a_vars: BTreeSet<String> = BTreeSet::new();
|
||||
let then_prog = ASTNode::Program {
|
||||
statements: then_body.clone(),
|
||||
span: Span::unknown(),
|
||||
};
|
||||
crate::mir::phi_core::if_phi::collect_assigned_vars(&then_prog, &mut route_a_vars);
|
||||
// JoinIR経由(メイン経路)
|
||||
let vars =
|
||||
crate::mir::phi_core::if_phi::collect_assigned_vars_via_joinir(&then_body, None);
|
||||
|
||||
// Verify Route A detects assignments
|
||||
assert!(route_a_vars.contains("x"), "Route A should detect x assignment");
|
||||
assert!(route_a_vars.contains("y"), "Route A should detect y assignment");
|
||||
assert_eq!(route_a_vars.len(), 2, "Route A should have exactly 2 variables");
|
||||
// Verify JoinIR detects Local declarations
|
||||
assert!(vars.contains("x"), "JoinIR should detect x declaration");
|
||||
assert!(vars.contains("y"), "JoinIR should detect y declaration");
|
||||
assert_eq!(vars.len(), 2, "Should have exactly 2 variables");
|
||||
}
|
||||
|
||||
/// Test 5: A/B route switching with nested if (Assignment nodes)
|
||||
/// Test 5: JoinIR経由のネストif内Local検出
|
||||
///
|
||||
/// ## Verification Points
|
||||
/// 1. Nested if内の代入(Assignment)も正しく検出
|
||||
/// 2. collect_assigned_varsのAssignment検出を検証
|
||||
/// 1. Nested if内のLocal宣言も正しく検出
|
||||
/// 2. Phase 40-4.1 削除後の動作確認
|
||||
#[test]
|
||||
fn phase40_ab_nested_if() {
|
||||
fn phase40_joinir_nested_if_local() {
|
||||
use crate::ast::{ASTNode, LiteralValue, Span};
|
||||
use std::collections::BTreeSet;
|
||||
|
||||
// Create nested if body with Assignment:
|
||||
// if (true) { inner = 1 }
|
||||
// outer = 2
|
||||
// Create nested if body with Local:
|
||||
// if (true) { local inner = 1 }
|
||||
// local outer = 2
|
||||
let then_body = vec![
|
||||
ASTNode::If {
|
||||
condition: Box::new(ASTNode::Literal {
|
||||
value: LiteralValue::Bool(true),
|
||||
span: Span::unknown(),
|
||||
}),
|
||||
then_body: vec![ASTNode::Assignment {
|
||||
target: Box::new(ASTNode::Variable {
|
||||
name: "inner".to_string(),
|
||||
span: Span::unknown(),
|
||||
}),
|
||||
value: Box::new(ASTNode::Literal {
|
||||
then_body: vec![ASTNode::Local {
|
||||
variables: vec!["inner".to_string()],
|
||||
initial_values: vec![Some(Box::new(ASTNode::Literal {
|
||||
value: LiteralValue::Integer(1),
|
||||
span: Span::unknown(),
|
||||
}),
|
||||
}))],
|
||||
span: Span::unknown(),
|
||||
}],
|
||||
else_body: None,
|
||||
span: Span::unknown(),
|
||||
},
|
||||
ASTNode::Assignment {
|
||||
target: Box::new(ASTNode::Variable {
|
||||
name: "outer".to_string(),
|
||||
span: Span::unknown(),
|
||||
}),
|
||||
value: Box::new(ASTNode::Literal {
|
||||
ASTNode::Local {
|
||||
variables: vec!["outer".to_string()],
|
||||
initial_values: vec![Some(Box::new(ASTNode::Literal {
|
||||
value: LiteralValue::Integer(2),
|
||||
span: Span::unknown(),
|
||||
}),
|
||||
}))],
|
||||
span: Span::unknown(),
|
||||
},
|
||||
];
|
||||
|
||||
// Route A: collect_assigned_vars
|
||||
let mut route_a_vars: BTreeSet<String> = BTreeSet::new();
|
||||
let then_prog = ASTNode::Program {
|
||||
statements: then_body.clone(),
|
||||
span: Span::unknown(),
|
||||
};
|
||||
crate::mir::phi_core::if_phi::collect_assigned_vars(&then_prog, &mut route_a_vars);
|
||||
// JoinIR経由
|
||||
let vars =
|
||||
crate::mir::phi_core::if_phi::collect_assigned_vars_via_joinir(&then_body, None);
|
||||
|
||||
// Verify: inner (nested in if) and outer (top-level) detected
|
||||
assert!(route_a_vars.contains("inner"), "Route A: should detect inner assignment in nested if");
|
||||
assert!(route_a_vars.contains("outer"), "Route A: should detect outer assignment");
|
||||
assert_eq!(route_a_vars.len(), 2, "Should detect exactly 2 assignments");
|
||||
assert!(vars.contains("inner"), "JoinIR: should detect inner in nested if");
|
||||
assert!(vars.contains("outer"), "JoinIR: should detect outer");
|
||||
assert_eq!(vars.len(), 2, "Should detect exactly 2 declarations");
|
||||
}
|
||||
|
||||
// ========================================
|
||||
|
||||
Reference in New Issue
Block a user