feat(joinir): Phase 40-3.5 route switching implementation
- Add collect_assigned_vars_via_joinir() in if_phi.rs (65 lines) - Wrapper using Phase 40-1 JoinIR infrastructure - Converts ASTNode to JSON and calls JoinIR analysis - Add route switching in loop_builder.rs - Check HAKO_JOINIR_ARRAY_FILTER env flag - Route A: Legacy collect_assigned_vars path - Route B: JoinIR collect_assigned_vars_via_joinir path - Add A/B tests in phase40_array_ext_filter_test.rs - phase40_ab_route_switching: Basic assignment detection - phase40_ab_nested_if: Nested if assignment detection - All 5 Phase 40 tests PASS 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -161,6 +161,71 @@ pub fn collect_assigned_vars(ast: &ASTNode, out: &mut std::collections::BTreeSet
|
||||
}
|
||||
}
|
||||
|
||||
/// Phase 40-3.5: JoinIR経由の代入変数収集
|
||||
///
|
||||
/// `collect_assigned_vars`のJoinIR代替版。
|
||||
/// `HAKO_JOINIR_ARRAY_FILTER=1`で有効化。
|
||||
///
|
||||
/// # Arguments
|
||||
/// - `then_body`: thenブランチのAST
|
||||
/// - `else_body`: elseブランチのAST(オプション)
|
||||
///
|
||||
/// # Returns
|
||||
/// - 代入された変数名のセット
|
||||
///
|
||||
/// # Implementation
|
||||
/// 1. ASTNode → JSON変換
|
||||
/// 2. JoinIR Frontend extract_assigned_vars_from_body()呼び出し
|
||||
/// 3. BTreeSet形式で返却
|
||||
///
|
||||
/// # Note
|
||||
/// この関数はPhase 40-1インフラを使用し、将来的にcollect_assigned_varsを置換する。
|
||||
#[allow(dead_code)]
|
||||
pub fn collect_assigned_vars_via_joinir(
|
||||
then_body: &[crate::ast::ASTNode],
|
||||
else_body: Option<&Vec<crate::ast::ASTNode>>,
|
||||
) -> std::collections::BTreeSet<String> {
|
||||
use crate::mir::join_ir::frontend::AstToJoinIrLowerer;
|
||||
|
||||
let mut result = std::collections::BTreeSet::new();
|
||||
|
||||
// Convert then_body to JSON
|
||||
let then_prog = crate::ast::ASTNode::Program {
|
||||
statements: then_body.to_vec(),
|
||||
span: crate::ast::Span::unknown(),
|
||||
};
|
||||
let then_json = crate::r#macro::ast_json::ast_to_json(&then_prog);
|
||||
|
||||
// Extract assigned vars via JoinIR
|
||||
let mut lowerer = AstToJoinIrLowerer::new();
|
||||
if let Some(body) = then_json.get("statements") {
|
||||
let assigned = lowerer.extract_assigned_vars_from_body(body);
|
||||
result.extend(assigned);
|
||||
}
|
||||
|
||||
// Process else_body if present
|
||||
if let Some(else_statements) = else_body {
|
||||
let else_prog = crate::ast::ASTNode::Program {
|
||||
statements: else_statements.clone(),
|
||||
span: crate::ast::Span::unknown(),
|
||||
};
|
||||
let else_json = crate::r#macro::ast_json::ast_to_json(&else_prog);
|
||||
if let Some(body) = else_json.get("statements") {
|
||||
let assigned = lowerer.extract_assigned_vars_from_body(body);
|
||||
result.extend(assigned);
|
||||
}
|
||||
}
|
||||
|
||||
if crate::config::env::joinir_vm_bridge_debug() {
|
||||
eprintln!(
|
||||
"[Phase 40-3.5] collect_assigned_vars_via_joinir: {:?}",
|
||||
result
|
||||
);
|
||||
}
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
/// 保守的修正名前計算
|
||||
///
|
||||
/// Compute the set of variable names whose values changed in either branch
|
||||
|
||||
Reference in New Issue
Block a user