Commit Graph

18 Commits

Author SHA1 Message Date
42f7eaa215 tools: speed up build_llvm NyRT cache + fix Phase 132 smoke counters
Improvements:
1. NyRT build cache in tools/build_llvm.sh
   - Skip [3/4] rebuild when target/release/libnyash_kernel.a exists
   - Add NYASH_LLVM_FORCE_NYRT_BUILD env var to force rebuild
   - Performance: 60-80% faster on incremental builds

2. Fix Phase 132 smoke test arithmetic bug
   - Replace ((PASS_COUNT++)) with PASS_COUNT=$((PASS_COUNT + 1))
   - Issue: ((x++)) returns 0 when x=0, causes set -e to exit
   - Locations: 8 places in phase132_exit_phi_parity.sh

3. Document NYASH_LLVM_FORCE_NYRT_BUILD in environment-variables.md

Acceptance criteria met:
- Behavior unchanged (first build creates .a, subsequent skip rebuild)
- NYASH_LLVM_FORCE_NYRT_BUILD allows forcing rebuild
- Phase 132 smoke test passes (both cases)
- Behavior-preserving optimization

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2025-12-15 11:06:26 +09:00
a955dd6b18 feat(llvm): Phase 131-15 - print/concat segfault 根治修正
## P1-1/P1-2: TypeFacts 優先化
- binop.py: operand facts が dst_type ヒントより優先
- mir_json_emit.rs: Unknown 時に dst_type を出さない
- function_lower.py: value_types を metadata から読み込み

## P2: handle concat 統一(根治)
- print シグネチャ修正: i64(i64) → void(i8*)
- Mixed concat を handle ベースに統一:
  - concat_si/concat_is → concat_hh
  - box.from_i64 で integer を handle 化
  - Everything is Box 哲学に統一
- legacy 関数は互換性のために保持

## 結果
-  print("Result: " + 3) → Result: 3
-  segfault 解消
-  Everything is Box 統一

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-15 01:36:34 +09:00
7dfd6ff1d9 feat(llvm): Phase 131-11-H/12 - ループキャリアPHI型修正 & vmap snapshot SSOT
## Phase 131-11-H: ループキャリアPHI型修正
- PHI生成時に初期値(entry block)の型のみ使用
- backedge の値を型推論に使わない(循環依存回避)
- NYASH_CARRIER_PHI_DEBUG=1 でトレース

## Phase 131-12-P0: def_blocks 登録 & STRICT エラー化
- safe_vmap_write() で PHI 上書き保護
- resolver miss を STRICT でエラー化(フォールバック 0 禁止)
- def_blocks 自動登録

## Phase 131-12-P1: vmap_cur スナップショット実装
- DeferredTerminator 構造体(block, term_ops, vmap_snapshot)
- Pass A で vmap_cur をスナップショット
- Pass C でスナップショット復元(try-finally)
- STRICT モード assert

## 結果
-  MIR PHI型: Integer(正しい)
-  VM: Result: 3
-  vmap snapshot 機構: 動作確認
- ⚠️ LLVM: Result: 0(別のバグ、次Phase で調査)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-14 21:28:41 +09:00
e912ef9134 docs(phase131): SSOT整備 - VM入口/env var/次の入口を1箇所に固定
Phase 131 SSOT 整備完了:

1) VM Box 解決の入口SSOT(phase131-2-box-resolution-map.md)
   - 📍 入口3行を先頭に追記(handle_new_box/UnifiedRegistry/BoxFactoryRegistry)
   - NYASH_VM_FAST を bench/profile-only 特例と明記

2) 環境変数のSSOTを1箇所へ(environment-variables.md)
   - ## LLVM Build Pipeline セクション新設(14変数)
   - phase87 の Environment Variables セクションを参照リンクに置き換え
   - 重複表を削除、SSOTドキュメントへの導線確立

3) 次の開発の入口を明確化(CURRENT_TASK.md)
   - P1(Loop Canonicalizer): 🔶 設計待ち(外部検討中)
   - P2(JoinIR / Selfhost depth-2):  実装可能
   - 次に触るSSOTを1行で指定:
     - Loop系: joinir-architecture-overview.md
     - VM Box系: phase131-2-box-resolution-map.md

Impact:
- 迷子防止: 各領域のSSOTが1行で分かる
- 重複削減: env var 表を environment-variables.md に集約
- 状態明確化: P1/P2 の「設計待ち/実装可能」が一目瞭然

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-14 05:27:39 +09:00
d7805e5974 feat(joinir): Phase 213-2 Step 2-2 & 2-3 Data structure extensions
Extended PatternPipelineContext and CarrierUpdateInfo for Pattern 3 AST-based generalization.

Changes:
1. PatternPipelineContext:
   - Added loop_condition: Option<ASTNode>
   - Added loop_body: Option<Vec<ASTNode>>
   - Added loop_update_summary: Option<LoopUpdateSummary>
   - Updated build_pattern_context() for Pattern 3

2. CarrierUpdateInfo:
   - Added then_expr: Option<ASTNode>
   - Added else_expr: Option<ASTNode>
   - Updated analyze_loop_updates() with None defaults

Status: Phase 213-2 Steps 2-2 & 2-3 complete
Next: Create Pattern3IfAnalyzer to extract if statement and populate update summary
2025-12-10 00:01:53 +09:00
120fbdb523 fix(mir): Receiver used_values for DCE + trace + cleanup
- Fix: Call with Callee::Method now includes receiver in used_values()
  - Prevents DCE from eliminating Copy instructions that define receivers
  - Pattern 3 (loop_if_phi.hako) now works correctly (sum=9)

- Add: NYASH_DCE_TRACE=1 for debugging eliminated instructions
  - Shows which pure instructions DCE removes and from which block

- Cleanup: Consolidate Call used_values to single source of truth
  - Early return in methods.rs handles all Call variants
  - Removed duplicate match arm (now unreachable!())
  - ChatGPT's suggestion for cleaner architecture

- Docs: Phase 166 analysis of inst_meta layer architecture
  - Identified CSE pass callee bug (to be fixed next)
  - Improvement proposals for CallLikeInst

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-05 23:26:55 +09:00
caf38dba19 feat(joinir): Phase 190 - LoopExitBinding boxification
Formalize exit PHI → variable_map reconnection with explicit LoopExitBinding
structure. Eliminates hardcoded variable names and prepares for Pattern 4+
multi-carrier support.

Key changes:

1. **New LoopExitBinding struct**:
   - carrier_name: String (e.g., "sum", "count")
   - join_exit_value: ValueId (JoinIR exit value)
   - host_slot: ValueId (variable_map destination)
   Makes it explicit: WHICH variable, FROM where, TO where.

2. **Updated JoinInlineBoundary**:
   - Replaced implicit host_outputs: Vec<ValueId>
   - With explicit exit_bindings: Vec<LoopExitBinding>
   - Old APIs marked #[deprecated] for backward compatibility

3. **Pattern 3 now uses explicit bindings**:
   Before: boundary.host_outputs = vec![sum_var_id]  // implicit
   After:  boundary.exit_bindings = vec![LoopExitBinding {
       carrier_name: "sum".to_string(),
       join_exit_value: ValueId(18),
       host_slot: sum_var_id,
   }]

4. **merge_joinir_mir_blocks() updated**:
   - Consumes exit_bindings instead of bare ValueIds
   - Enhanced debug output shows carrier names
   - Validates carrier name matches variable_map expectations

Benefits:
- Self-documenting code: bindings explain themselves
- Multi-carrier ready: Pattern 4+ just extend the vec![]
- Type-safe: No implicit semantics
- Debuggable: Explicit carrier name in logs

Test status:
- Build:  SUCCESS (0 errors, 47 warnings)
- Pattern 3:  PASS (no regressions)
- Backward compatibility:  Maintained via #[deprecated]

Prepare for Phase 191: Pattern Router Table and Phase 192: JoinLoopTrace

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: ChatGPT <noreply@openai.com>
Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-05 19:59:40 +09:00
3e3d1b369d refactor(phase124): Delete NYASH_HAKO_CHECK_JOINIR flag completely
- Remove src/config/env/hako_check.rs entirely (file deleted)
- Comment out hako_check module in src/config/env.rs with Phase 124 markers
- Mark NYASH_HAKO_CHECK_JOINIR as deleted in environment-variables.md
- Document reason: JoinIR-only consolidation makes flag unnecessary

Phase 124 Task 2/5 complete
2025-12-04 06:27:54 +09:00
adc10fdf54 Phase 123 proper完了:hako_check JoinIR実装(環境変数選択可能化)
## 実装内容

### 1. 環境変数フラグ追加
- NYASH_HAKO_CHECK_JOINIR でJoinIR/Legacy経路を切り替え可能
- src/config/env/hako_check.rs で hako_check_joinir_enabled() 実装
- デフォルト: false(レガシー経路)で後方互換性確保

### 2. MIR Builder JoinIR スイッチ
- cf_if() メソッドにフラグチェック追加
- try_cf_if_joinir() プレースホルダー実装(Phase 124で完全実装)
- JoinIR → legacy フォールバック機構を構築

### 3. テストケース作成(4個)
- phase123_simple_if.hako
- phase123_nested_if.hako
- phase123_while_loop.hako
- phase123_if_in_loop.hako

### 4. テスト結果
 Legacy path: 4/4 PASS
 JoinIR path: 4/4 PASS
(JoinIR path は現在フォールバック経由で動作)

### 5. ドキュメント更新
- environment-variables.md: NYASH_HAKO_CHECK_JOINIR 記載
- phase121_hako_check_joinir_design.md: Phase 123実装セクション追加
- hako_check_design.md: 2パス実行フロー図を追加
- CURRENT_TASK.md: Phase 123完了を記録

## 数値成果

- 新規ファイル: 2個 (config/env/hako_check.rs, test cases × 4, test script)
- 修正ファイル: 6個
- 総追加行数: 335行
- ビルド: Zero errors

## 設計・実装の特徴

 Environment variable で簡単に経路切り替え可能
 レガシー経路を完全に保持(後方互換性)
 JoinIR基盤を Phase 124 での完全実装に向けて構築
 フォールバック機構でリスク最小化

## 次のステップ

Phase 124: JoinIR 完全実装&デフォルト化
- try_cf_if_joinir() を IfSelectLowerer と統合
- Loop JoinIR 統合追加
- JoinIR をデフォルト経路に変更
- NYASH_LEGACY_PHI=1 で legacy フォールバック可能に

🤖 Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-04 06:17:10 +09:00
a3d5bacc55 Phase 30.1 & 73: Stage-3 features env and JoinIR flag cleanup 2025-11-30 14:30:28 +09:00
35cd93a37a Phase 33-2: JoinInst::Select implementation + minimal If JoinIR lowering
Implementation:
- Add JoinInst::Select variant to JoinIR schema
- Implement Select execution in JoinIR Runner (Bool/Int cond support)
- Add Select handling in JoinIR→MIR Bridge (4-block structure)
- Create test cases (joinir_if_select_simple/local.hako)
- Add dev toggle NYASH_JOINIR_IF_SELECT=1
- Create lowering infrastructure (if_select.rs, stub for Phase 33-3)

Tests:
- 3/3 unit tests pass (test_select_true/false/int_cond)
- Integration tests pass (RC: 0)
- A/B execution verified (existing if_phi vs JoinIR Select)

Files changed:
- New: apps/tests/joinir_if_select_{simple,local}.hako
- New: src/mir/join_ir/lowering/if_select.rs
- Modified: src/mir/join_ir/{mod,json,runner,vm_bridge}.rs
- Modified: src/config/env.rs (joinir_if_select_enabled)
- Modified: docs/reference/environment-variables.md

Phase 33-3 ready: MIR pattern recognition + auto-lowering pending

🤖 Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-27 02:58:38 +09:00
eddc4e6035 docs(joinir): L-2.2 Step-4 - Update JoinIR VM bridge documentation
Phase 32 README:
- Expand VM Bridge table with "JoinIR 利用範囲" column
- Add L-2.2 progress summary table (Step-1~5 status)
- Add developer notes for Stage-B JoinIR observation

environment-variables.md:
- Add detailed descriptions for NYASH_JOINIR_* variables
- Clarify scope and limitations (Stage-B = lowering only)
- Add Stage-B JoinIR observation example

CURRENT_TASK:
- Update L-2.2 status to Step-1~4 complete

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-26 11:55:04 +09:00
51ff558904 feat(phase32): L-2.1 Stage-1 UsingResolver JoinIR integration + cleanup
Phase 32 L-2.1 complete implementation:

1. Stage-1 UsingResolver main line JoinIR connection
   - CFG-based LoopForm construction for resolve_for_source/5
   - LoopToJoinLowerer integration with handwritten fallback
   - JSON snapshot tests 6/6 PASS

2. JoinIR/VM Bridge improvements
   - Simplified join_ir_vm_bridge.rs dispatch logic
   - Enhanced json.rs serialization
   - PHI core boxes cleanup (local_scope_inspector, loop_exit_liveness, loop_var_classifier)

3. Stage-1 CLI enhancements
   - Extended args.rs, groups.rs, mod.rs for new options
   - Improved stage1_bridge module (args, env, mod)
   - Updated stage1_cli.hako

4. MIR builder cleanup
   - Simplified if_form.rs control flow
   - Removed dead code from loop_builder.rs
   - Enhanced phi_merge.rs

5. Runner module updates
   - json_v0_bridge/lowering.rs improvements
   - dispatch.rs, selfhost.rs, modes/vm.rs cleanup

6. Documentation updates
   - CURRENT_TASK.md, AGENTS.md
   - Various docs/ updates

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-26 10:17:37 +09:00
03efa13e76 docs(phase-29): JoinIR/Stage-1 環境変数棚卸し完了
Step 1: ENV_INVENTORY.md 作成 (docs/private submodule)
Step 2: 実装統一確認 - 既にhelper経由で統一済み
Step 3: environment-variables.md に JoinIRセクション追加
Step 4: スモークテスト pass
Step 5: CURRENT_TASK.md に完了記録

発見事項:
- JoinIR: env_flag_is_1() ヘルパー経由で統一済み
- Stage-1: src/config/env/stage1.rs SSOT モジュール経由で統一済み
- NYASH_RUN_JOINIR_MINIMAL は既に削除済み

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-25 09:03:28 +09:00
94b2bd2799 feat(selfhost): add observation logs for Ny compiler path diagnosis
Add NYASH_CLI_VERBOSE>=2 observation logs to trace the Ny compiler
child process path (NYASH_USE_NY_COMPILER=1):
- Log when spawning child process
- Log when receiving Program(JSON v0)
- Log before/after maybe_dump_mir with dump path info
- Report whether MIR dump file was created

Key finding: apps/selfhost/compiler/compiler.hako doesn't exist,
so the preferred child process route never fires. This explains
why RUST_MIR_DUMP_PATH doesn't create files in Ny compiler path.

Also update environment-variables.md with:
- NYASH_CLI_VERBOSE=2 level documentation
- Ny compiler observation template for Phase 29

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-25 07:08:32 +09:00
0852a397d9 Add experimental JoinIR runner and tests 2025-11-23 08:38:15 +09:00
8750186e55 chore: Phase 26-H セッション完了 - 全ドキュメント更新
Phase 26-H 完了内容:
 JoinIR 型定義実装(src/mir/join_ir.rs)
 MIR → JoinIR 自動変換実装(lower_min_loop_to_joinir)
 自動変換テスト実装(mir_joinir_min_auto_lowering)
 PHI/Loop箱 → JoinIR 移行対応表追加(loopform_ssot.md)

ドキュメント更新:
- Phase 27 JoinIR タスク計画追加
- Phase 26-H タスク完了記録
- 各種 README 更新(進捗反映)
- CURRENT_TASK.md 更新

コミット統計: $(git status --short | wc -l) files changed

次のステップ: Phase 27 一般化 MIR → JoinIR 変換
2025-11-23 05:53:27 +09:00
c344451087 fix(mir-builder): static method arity mismatch根治 - Phase 25.x
**問題**:
- ParserStmtBox.parse_using/4 に5引数が渡される
- me.method呼び出しで instance/static 判別なし
- static method に誤って receiver 追加

**修正**:
- MeCallPolicyBox: params[0]の型で instance/static 判別
- Instance method: receiver 追加
- Static method: receiver なし
- Arity検証(NYASH_ME_CALL_ARITY_STRICT=1)

**ドキュメント**:
- docs/reference/environment-variables.md 新規作成
- docs/development/architecture/mir-logs-observability.md 更新

**テスト**:
- src/tests/mir_stage1_cli_emit_program_min.rs 追加
- 既存 stage1 テスト全てパス

Phase: 25.x
2025-11-21 11:16:38 +09:00