diff --git a/crates/nyash_kernel/src/lib.rs b/crates/nyash_kernel/src/lib.rs index 98e570d4..32a133fa 100644 --- a/crates/nyash_kernel/src/lib.rs +++ b/crates/nyash_kernel/src/lib.rs @@ -241,16 +241,6 @@ pub extern "C" fn nyash_box_from_i8_string(ptr: *const i8) -> i64 { h } -// box.from_f64(val) -> handle -// Helper: build a FloatBox and return a handle -#[export_name = "nyash.box.from_f64"] -pub extern "C" fn nyash_box_from_f64(val: f64) -> i64 { - use nyash_rust::{box_trait::NyashBox, boxes::FloatBox, runtime::host_handles as handles}; - let arc: std::sync::Arc = std::sync::Arc::new(FloatBox::new(val)); - nyash_rust::runtime::global_hooks::gc_alloc(8); - handles::to_handle_arc(arc) as i64 -} - // box.from_i64(val) -> handle // Helper: build an IntegerBox and return a handle #[export_name = "nyash.box.from_i64"] @@ -968,19 +958,6 @@ pub extern "C" fn nyash_float_unbox_to_f64(float_handle: i64) -> f64 { 0.0 // Not a FloatBox or handle invalid } -// Phase 275 P0: Float box helper for LLVM harness (Int+Float result boxing) -// Creates FloatBox from f64 and returns its handle -#[no_mangle] -#[export_name = "nyash.float.box_from_f64"] -pub extern "C" fn nyash_float_box_from_f64(value: f64) -> i64 { - use nyash_rust::{box_trait::NyashBox, boxes::FloatBox, runtime::host_handles as handles}; - - // Create a new FloatBox with the given value - let float_box = FloatBox::new(value); - let arc: std::sync::Arc = std::sync::Arc::new(float_box); - handles::to_handle_arc(arc) as i64 -} - #[cfg(test)] mod tests { use super::*; diff --git a/docs/development/current/main/10-Now.md b/docs/development/current/main/10-Now.md index aaddb5b3..d7fb984f 100644 --- a/docs/development/current/main/10-Now.md +++ b/docs/development/current/main/10-Now.md @@ -1,6 +1,32 @@ # Self Current Task — Now (main) -## Current: Phase 277(P2)— PHI関連環境変数の統合・整理 ✅ +## 2025-12-22: Phase 277(P0/P1)— Phase 275/276 残タスク完全実装 ✅ + +- 目的: Phase 275/276 で積み残した改善タスクを完全実装(デッドコード削除・SSOT使用推進・Void検出) +- 達成内容: + - ✅ **P0: box_from_f64 削除**(デッドコード) + - `crates/nyash_kernel/src/lib.rs` から2関数削除 + - Phase 275 P0 の Float 型 SSOT 方針により boxing helper 不要 + - ビルド成功・テスト成功確認 + - ✅ **P1: dst_type_to_llvm_type 使用推進** + - `phi_wiring/wiring.py` を type_helper.py SSOT に統一 + - 型変換ロジックが完全に1箇所に集約(拡張性向上) + - ✅ **LLVM A1: Void検出修正(Phase 275 P0 残タスク)** + - `branch.py` に Void/VoidBox 検出ロジック実装済みを確認 + - エラーメッセージ追加(fail-fast 原則) + - テストケース作成(/tmp/test_p275_a1_void.hako) + - VM側で正常にエラー検出確認 + - ✅ **LLVM Smoke Tests 完全実施**: + - Test 1 (simple Int+Float): ✅ PASS (exit=3, VM/LLVM parity) + - Test 2 (two Int+Float ops): ✅ PASS (exit=3, VM/LLVM parity) + - Test 3 (Float + String): ⚠️ exit=0 (String 問題は Phase 275 範囲外) +- 効果: + - Float PHI 完全動作(VM/LLVM parity 達成) + - SSOT 原則完全適用(型変換・環境変数) + - Fail-Fast 原則適用(Void in boolean context) + - デッドコード削減(保守性向上) + +## 2025-12-22: Phase 277(P2)— PHI関連環境変数の統合・整理 ✅ - 目的: PHI関連環境変数を **8個 → 3個** に統合してユーザビリティ向上・保守性向上 - 完了日: 2025-12-22 diff --git a/src/llvm_py/instructions/controlflow/branch.py b/src/llvm_py/instructions/controlflow/branch.py index 88ab42b5..bc722e09 100644 --- a/src/llvm_py/instructions/controlflow/branch.py +++ b/src/llvm_py/instructions/controlflow/branch.py @@ -50,7 +50,24 @@ def lower_branch( # Default to false if missing cond = ir.Constant(ir.IntType(1), 0) - # Convert to i1 if needed + # Phase 275 A1: Check MIR type facts for Void discrimination (fail-fast) + mir_type = None + if resolver is not None and hasattr(resolver, 'value_types') and isinstance(resolver.value_types, dict): + mir_type = resolver.value_types.get(cond_vid) + + # Void → TypeError (trap) - Phase 275 A1: Fail-fast for Void in boolean context + if mir_type == 'Void' or (isinstance(mir_type, dict) and mir_type.get('kind') == 'Void'): + print(f"⚠️ [branch/CRITICAL] Void in boolean context! v{cond_vid}", file=sys.stderr) + builder.unreachable() + return + + # VoidBox → TypeError (trap) + if isinstance(mir_type, dict) and mir_type.get('box_type') == 'VoidBox': + print(f"⚠️ [branch/CRITICAL] VoidBox in boolean context! v{cond_vid}", file=sys.stderr) + builder.unreachable() + return + + # Convert to i1 if needed (existing logic for non-Void types) if hasattr(cond, 'type'): # If we already have an i1 (canonical compare result), use it directly. if isinstance(cond.type, ir.IntType) and cond.type.width == 1: diff --git a/src/llvm_py/phi_wiring/wiring.py b/src/llvm_py/phi_wiring/wiring.py index da7e93a7..9b3a2021 100644 --- a/src/llvm_py/phi_wiring/wiring.py +++ b/src/llvm_py/phi_wiring/wiring.py @@ -111,12 +111,9 @@ def ensure_phi(builder, block_id: int, dst_vid: int, bb: ir.Block, dst_type=None except Exception: pass - # Phase 275 P0: Determine PHI type from dst_type (from MIR JSON) - # Float PHIs use double, others use i64 - if dst_type == 'f64' or dst_type == 'double': - phi_type = ir.DoubleType() - else: - phi_type = builder.i64 + # Phase 277 P1: Use type_helper SSOT for PHI type determination + from .type_helper import dst_type_to_llvm_type + phi_type = dst_type_to_llvm_type(dst_type, builder) import sys if is_phi_debug_enabled():