Files
hakorune/src/mir/join_ir_vm_bridge_dispatch/targets.rs
nyash-codex 78e8eca971 feat(phase182): Upgrade 3 JOINIR_TARGETS functions from LowerOnly to Exec
Phase 182 implementation: JOINIR_TARGETS expansion for representative paths

## Changes
- Stage1UsingResolverBox.resolve_for_source/5: LowerOnly → Exec (default_enabled: true)
- StageBBodyExtractorBox.build_body_src/2: LowerOnly → Exec (default_enabled: true)
- StageBFuncScannerBox.scan_all_boxes/1: LowerOnly → Exec (default_enabled: true)

## Critical Finding: JOINIR_TARGETS is Loop-Only
Discovered that JOINIR_TARGETS is specifically for LOOP lowering only.
Adding if-lowering functions (like IfSelectTest.test/1) would be counterproductive
because is_loop_lowered_function() exclusion would disable if-lowering entirely.

## Test Results
- 4/5 selfhost loop tests: PASS with NYASH_JOINIR_CORE=1 NYASH_JOINIR_STRICT=1
- 1/5 if-select test: FAIL (requires Phase 183 architectural fix - Option A)
- No regressions in existing functionality

## Phase 183 Recommendation
Implement Option A: Create JOINIR_IF_TARGETS as separate table for if-lowering
functions, avoiding the mutual exclusion problem between loop and if lowering.

See: docs/private/roadmap2/phases/phase-182/FINDINGS.md for full analysis

🤖 Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-04 21:03:44 +09:00

92 lines
4.0 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

use crate::mir::MirModule;
/// JoinIR ブリッジの実行範囲を表す enum
///
/// - `Exec`: JoinIR→VM 実行まで対応。意味論を A/B 実証済みのものに限定。
/// - `LowerOnly`: JoinIR lowering / Bridge 構造検証専用。実行は VM Route A にフォールバック。
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum JoinIrBridgeKind {
/// JoinIR→VM 実行まで対応skip/trim など、意味論を A/B 実証済み)
Exec,
/// JoinIR lowering / Bridge 構造検証専用Stage-1/Stage-B など)
LowerOnly,
}
/// JoinIR ブリッジ対象の記述子
///
/// 関数名と実行範囲Exec/LowerOnlyをペアで管理する。
#[derive(Debug, Clone, Copy)]
pub struct JoinIrTargetDesc {
/// 対象関数名MirModule.functions のキー)
pub func_name: &'static str,
/// 実行範囲
pub kind: JoinIrBridgeKind,
/// デフォルト有効化env フラグなしでも JoinIR 経路に入る)
pub default_enabled: bool,
}
/// JoinIR ブリッジ対象テーブルSSOT
///
/// Phase 32 L-4: 全対象関数を一覧化し、Exec/LowerOnly の区分を明示する。
/// Phase 82: このテーブルが唯一の SSOT。is_loop_lowered_function() はここから参照。
/// Phase 182: representative paths 対応3 upgrades - LOOP ONLY
///
/// **重要**: このテーブルは LOOP lowering 専用です。
/// If lowering の関数を追加すると、is_loop_lowered_function() で除外され、
/// if-lowering が機能しなくなります。If 関数は is_joinir_if_toplevel_target() で管理。
///
/// | 関数 | Kind | デフォルト有効 | 備考 |
/// |-----|------|---------------|------|
/// | Main.skip/1 | Exec | No | PHI canary のため env 必須 |
/// | FuncScannerBox.trim/1 | Exec | Yes | A/B 実証済み、事実上本線 |
/// | FuncScannerBox.append_defs/2 | Exec | No | Phase 82 SSOT統一で追加 |
/// | Stage1UsingResolverBox.resolve_for_source/5 | Exec | Yes | Phase 182: LowerOnly→Exec 昇格 |
/// | StageBBodyExtractorBox.build_body_src/2 | Exec | Yes | Phase 182: LowerOnly→Exec 昇格 |
/// | StageBFuncScannerBox.scan_all_boxes/1 | Exec | Yes | Phase 182: LowerOnly→Exec 昇格 |
///
/// Phase 181/182 設計ドキュメント:
/// - docs/private/roadmap2/phases/phase-181/joinir-targets-mapping.md
/// - docs/private/roadmap2/phases/phase-181/representative-paths-finalized.md
/// - docs/private/roadmap2/phases/phase-182/FINDINGS.md (Phase 182 実装時発見事項)
pub const JOINIR_TARGETS: &[JoinIrTargetDesc] = &[
// Loop Exec実行対応
JoinIrTargetDesc {
func_name: "Main.skip/1",
kind: JoinIrBridgeKind::Exec,
default_enabled: false, // PHI canary のため env 必須
},
JoinIrTargetDesc {
func_name: "FuncScannerBox.trim/1",
kind: JoinIrBridgeKind::Exec,
default_enabled: true, // A/B 実証済み、事実上本線
},
JoinIrTargetDesc {
func_name: "FuncScannerBox.append_defs/2",
kind: JoinIrBridgeKind::Exec,
default_enabled: false,
},
// Phase 182 昇格: Stage-1/Stage-B infrastructure (LowerOnly → Exec)
JoinIrTargetDesc {
func_name: "Stage1UsingResolverBox.resolve_for_source/5",
kind: JoinIrBridgeKind::Exec, // Phase 182: LowerOnly から昇格
default_enabled: true,
},
JoinIrTargetDesc {
func_name: "StageBBodyExtractorBox.build_body_src/2",
kind: JoinIrBridgeKind::Exec, // Phase 182: LowerOnly から昇格
default_enabled: true,
},
JoinIrTargetDesc {
func_name: "StageBFuncScannerBox.scan_all_boxes/1",
kind: JoinIrBridgeKind::Exec, // Phase 182: LowerOnly から昇格
default_enabled: true,
},
];
/// Phase 32 L-4: テーブルから対象関数を探す
pub(crate) fn find_joinir_target(module: &MirModule) -> Option<&'static JoinIrTargetDesc> {
JOINIR_TARGETS
.iter()
.find(|target| module.functions.contains_key(target.func_name))
}