## Code Changes - Extended function name whitelist in try_lower_if_to_joinir() - Added: JsonShapeParser._read_value_from_pair/1 (Stage-1) - Added: Stage1JsonScannerBox.value_start_after_key_pos/2 (Stage-B) ## Validation - A/B testing: Route A (if_phi) vs Route B (Select) → identical results (RC 0) - Test cases: joinir_if_select_simple.hako, joinir_if_select_local.hako - Build: cargo build --release successful ## Documentation (docs/private submodule) - TASKS.md: Phase 33-4.1 to 33-4.3 marked complete - if_joinir_design.md: Section 9 added (candidate analysis) ## Next Steps - Phase 33-4.4: CI/smoke test updates (pending)
109 lines
3.9 KiB
Rust
109 lines
3.9 KiB
Rust
//! JoinIR Lowering Functions
|
||
//!
|
||
//! Phase 27.9: Modular separation of MIR → JoinIR lowering implementations.
|
||
//!
|
||
//! このモジュールは各種 MIR 関数を JoinIR に変換する lowering 関数を提供します。
|
||
//!
|
||
//! ## 構成:
|
||
//! - `common.rs`: CFG sanity checks と lowering 共通ユーティリティ(Phase 27.10)
|
||
//! - `value_id_ranges.rs`: ValueId 範囲管理(Phase 27.13+)
|
||
//! - `min_loop.rs`: JoinIrMin.main/0 専用の最小ループ lowering
|
||
//! - `skip_ws.rs`: Main.skip/1 の空白スキップ lowering(手書き版+MIR自動解析版)
|
||
//! - `funcscanner_trim.rs`: FuncScannerBox.trim/1 の trim lowering
|
||
//! - `stage1_using_resolver.rs`: Stage1UsingResolverBox.resolve_for_source entries loop lowering(Phase 27.12)
|
||
//! - `funcscanner_append_defs.rs`: FuncScannerBox._append_defs/2 の配列結合 lowering(Phase 27.14)
|
||
//! - `if_select.rs`: Phase 33 If/Else → Select lowering
|
||
|
||
pub mod common;
|
||
pub mod exit_args_resolver;
|
||
pub mod funcscanner_append_defs;
|
||
pub mod funcscanner_trim;
|
||
pub mod generic_case_a;
|
||
pub mod if_select; // Phase 33
|
||
pub mod loop_form_intake;
|
||
pub mod loop_scope_shape;
|
||
pub mod loop_to_join;
|
||
pub mod min_loop;
|
||
pub mod skip_ws;
|
||
pub mod stage1_using_resolver;
|
||
pub mod stageb_body;
|
||
pub mod stageb_funcscanner;
|
||
pub mod value_id_ranges;
|
||
|
||
// Re-export public lowering functions
|
||
pub use funcscanner_append_defs::lower_funcscanner_append_defs_to_joinir;
|
||
pub use funcscanner_trim::lower_funcscanner_trim_to_joinir;
|
||
// Phase 31: LoopToJoinLowerer 統一箱
|
||
pub use loop_to_join::LoopToJoinLowerer;
|
||
// Phase 30 F-3: 旧 lower_case_a_loop_to_joinir_for_minimal_skip_ws は _with_scope に置き換え済みのため削除
|
||
pub use min_loop::lower_min_loop_to_joinir;
|
||
pub use skip_ws::lower_skip_ws_to_joinir;
|
||
pub use stage1_using_resolver::lower_stage1_usingresolver_to_joinir;
|
||
pub use stageb_body::lower_stageb_body_to_joinir;
|
||
pub use stageb_funcscanner::lower_stageb_funcscanner_to_joinir;
|
||
|
||
// Phase 33: If/Else → Select lowering entry point
|
||
use crate::mir::join_ir::JoinInst;
|
||
use crate::mir::{BasicBlockId, MirFunction};
|
||
|
||
/// Phase 33-3: Try to lower if/else to JoinIR Select instruction
|
||
///
|
||
/// Scope:
|
||
/// - Only applies to whitelisted functions:
|
||
/// - IfSelectTest.* (Phase 33-2/33-3)
|
||
/// - JsonShapeParser._read_value_from_pair/1 (Phase 33-4 Stage-1)
|
||
/// - Stage1JsonScannerBox.value_start_after_key_pos/2 (Phase 33-4 Stage-B)
|
||
/// - Requires NYASH_JOINIR_IF_SELECT=1 environment variable
|
||
/// - Falls back to traditional if_phi on pattern mismatch
|
||
///
|
||
/// Returns Some(JoinInst::Select) if pattern matched, None otherwise.
|
||
pub fn try_lower_if_to_joinir(
|
||
func: &MirFunction,
|
||
block_id: BasicBlockId,
|
||
debug: bool,
|
||
) -> Option<JoinInst> {
|
||
// dev トグルチェック
|
||
if !crate::config::env::joinir_if_select_enabled() {
|
||
return None;
|
||
}
|
||
|
||
// Phase 33-4: 関数名ガード拡張(IfSelectTest + Stage-1/Stage-B 候補)
|
||
let is_allowed = func.signature.name.starts_with("IfSelectTest.")
|
||
|| func.signature.name == "JsonShapeParser._read_value_from_pair/1"
|
||
|| func.signature.name == "Stage1JsonScannerBox.value_start_after_key_pos/2";
|
||
|
||
if !is_allowed {
|
||
if debug {
|
||
eprintln!(
|
||
"[try_lower_if_to_joinir] skipping non-allowed function: {}",
|
||
func.signature.name
|
||
);
|
||
}
|
||
return None;
|
||
}
|
||
|
||
// if_select lowering を試行
|
||
let lowerer = if_select::IfSelectLowerer::new(debug);
|
||
|
||
if !lowerer.can_lower_to_select(func, block_id) {
|
||
if debug {
|
||
eprintln!(
|
||
"[try_lower_if_to_joinir] pattern not matched for {}",
|
||
func.signature.name
|
||
);
|
||
}
|
||
return None;
|
||
}
|
||
|
||
let result = lowerer.lower_if_to_select(func, block_id);
|
||
|
||
if result.is_some() && debug {
|
||
eprintln!(
|
||
"[try_lower_if_to_joinir] if_select lowering used for {}",
|
||
func.signature.name
|
||
);
|
||
}
|
||
|
||
result
|
||
}
|