feat: Phase 2.4 レガシーアーカイブ整理完了(151MB削減)

## 🎉 完了項目
-  plugin_box_legacy.rs削除(7.7KB、参照ゼロ確認済み)
-  REMOVEDコメント整理(encode.rs簡潔化)
-  venv削除(143MB節約、.gitignoreは既存)
-  llvm_legacyスタブ化(8KB、compile_error!による安全化)

## 🏆 成果
- **リポジトリサイズ改善**: 151MB削減
- **コード整理**: レガシーコード安全にアーカイブ
- **プラグインファースト**: StrictPluginFirst継続動作

##  検証完了
- cargo build --release --features llvm (警告のみ、エラーなし)
- LLVMハーネス実行: print出力正常
- プラグイン動作: StringBox等正常動作

codex先生の戦略に従った安全な段階的削除を実行

Co-Authored-By: codex <noreply@anthropic.com>
This commit is contained in:
Selfhosting Dev
2025-09-24 14:13:15 +09:00
parent f4fe548787
commit f0608e9bb1
42 changed files with 682 additions and 536 deletions

View File

@ -2,6 +2,8 @@
目的: ループ/分岐における Phi 選択を正道に戻し、借用衝突を避けつつ段階導入する。
> ステータス更新2025-09-26: Step 3 まで実装済みで、MIR ビルダーは既定で PHI-on になったよ。以下のプランはアーカイブとして残しているよ。
段階プラン80/20
- Step 1: 実行系での選択復帰(完了)
- `previous_block` に基づき `inputs[(bb==prev)]` を選択。見つからない場合は先頭をフォールバック。

View File

@ -1,50 +1,49 @@
MIR13 Mode (PHI-off by default)
MIR13 Mode (legacy PHI-off fallback)
Overview
- Goal: Stabilize execution by turning off PHI emission in the Bridge/Builder and letting the LLVM (llvmlite) layer synthesize PHIs as needed.
- Default: MIR13 is ON by default (PHI-off). Use env flags to flip.
- Goal: Retain the Phase14 edge-copy compatibility path for debugging historical MIR dumps or diagnosing SSA regressions.
- Default: MIR14 (PHI-on) now ships as the standard. MIR13 must be explicitly enabled through environment flags.
Why
- Fewer SSA obligations in the front-end (Bridge/Builder) reduces CFG corner cases (shortcircuit, nested if/loop merges).
- Centralizes SSA invariants in a single place (llvmlite resolver/finalizer), improving correctness and maintenance.
Why keep MIR13 around?
- Reproducibility: Some archived JSON v0 fixtures were captured before PHI-on shipped. MIR13 allows replaying them without regeneration.
- Diagnostics: Edge-copy runs make it easier to isolate builder regressions by removing PHI synthesis from the equation.
- Tooling parity: Certain scripts still compare MIR13 traces; they will be retired once PHI-on parity checks are complete.
Flags and Behavior
- NYASH_MIR_NO_PHI (default: 1)
- 1: Bridge/Builder emit edge copies instead of PHIs at merges (MIR13).
- 0: Bridge/Builder may emit PHIs (MIR14 experimental).
- NYASH_VERIFY_ALLOW_NO_PHI (default: 1)
- Relaxes verifier checks that assume PHIs at merges.
- NYASH_MIR_NO_PHI (default: 0)
- 0: Builders emit PHIs at merge heads (MIR14, default).
- 1: Builders drop PHIs and insert per-predecessor edge copies (MIR13 fallback).
- NYASH_VERIFY_ALLOW_NO_PHI (default: 0 unless PHI-off is requested)
- Set this to 1 together with `NYASH_MIR_NO_PHI=1` when you intentionally relax SSA verification.
- NYASH_LLVM_USE_HARNESS=1 (AOT via llvmlite harness)
- Resolver/finalizer synthesize PHIs at block heads when needed.
- In MIR13 mode the harness synthesizes PHIs. In MIR14 it simply validates incoming edges.
LLVM (llvmlite) Responsibilities
- setup_phi_placeholders(): predeclare JSONprovided PHIs and collect incoming metadata.
- block_end_values: snapshot per block end to materialize predecessor values (dominancesafe).
- finalize_phis(): wire incoming edges for declared PHIs at block heads.
- Resolver.resolve_i64():
- singlepred: take predecessor end value;
- multipred + declared PHI: reuse placeholder at block head;
- multipred + no PHI: synthesize a localization PHI at the current block head (MIR13 compatibility);
- avoids reusing nondominating vmap values across blocks.
- `setup_phi_placeholders()`: still records declared PHIs; in MIR13 mode it creates placeholders for later wiring.
- `block_end_values`: snapshots per block end to materialize predecessor values (dominance-safe).
- `finalize_phis()`: wires incoming edges for declared PHIs; when MIR13 runs, it creates PHIs on the fly to recover SSA.
- `Resolver.resolve_i64()`:
- single-pred: take predecessor end value;
- multi-pred + declared PHI: reuse the placeholder at the block head;
- multi-pred + no PHI: synthesize a localization PHI at the current block head (MIR13 compatibility);
- avoids reusing non-dominating vmap values across blocks.
Bridge/Builder (JSON v0) Behavior
- If/Loop/Try are lowered without PHIs when MIR13 is ON; merges are performed with edge copies (merge_var_maps) and the final value is reconstituted by the LLVM layer if needed.
- Helper split for readability (no behavior change):
- lowering/{if_else.rs, loop_.rs, try_catch.rs, merge.rs}
- MIR14 (default): If/Loop/Try placements emit PHIs up front; loop latches, break/continue, and structured joins have explicit incoming pairs.
- MIR13 (fallback): Merges are performed with edge copies (`merge_var_maps`). Use only when reproducing historical issues.
Testing
- Curated LLVM (default = PHIoff):
- tools/smokes/curated_llvm.sh (use --phi-on to exercise MIR14)
- Curated LLVM (default = PHI-on):
- `tools/smokes/curated_llvm.sh` (add `--phi-off` to exercise MIR13)
- PHI invariants/parity (AOT vs PyVM):
- tools/pyvm_vs_llvmlite.sh (default compares exit code; use CMP_STRICT=1 for stdout+exit)
- `tools/pyvm_vs_llvmlite.sh` (default compares exit code; use `CMP_STRICT=1` for stdout+exit)
- Bridge/PyVM:
- tools/selfhost_stage2_bridge_smoke.sh
- `tools/selfhost_stage2_bridge_smoke.sh`
How to Force PHIon (MIR14 experimental)
- Set: NYASH_MIR_NO_PHI=0 and run tools/smokes/curated_llvm.sh --phi-on
- Known: loop_if_phi may trip dominance issues in PHIon; MIR13 is the recommended default.
How to Force PHI-off (MIR13 fallback)
- Set: `NYASH_MIR_NO_PHI=1 NYASH_VERIFY_ALLOW_NO_PHI=1` and run `tools/smokes/curated_llvm.sh --phi-off`
- Label the run as legacy in `CURRENT_TASK.md` if results inform shared debugging.
Known Limitations (current)
- No full tracing GC; object lifetime is managed via handle registries and Arc lifetimes.
- PHIon path is still being refined for some controlflow patterns.
- MIR13 no longer receives new feature work; expect missing coverage for recent LoopForm updates.
- PHI-on is the supported path. MIR13 bugs are fixed only when they block diagnostics.

View File

@ -100,7 +100,7 @@ Call { callee: Callee, args }
- [ ] MIRダンプの可読性向上
- [ ] パフォーマンス向上(実行時オーバーヘッド削減)
- [ ] using systemとの完全統合
- 規約PHIoff 既定:
- 規約PHI 合流:
- merge 内に copy は置かない。then/else の pred へ edge_copy のみを挿入selfcopy は NoOp
- 分岐直前に pre_if_snapshot を取得し、then/else は snapshot ベースで独立構築。merge で snapshot を基底に戻す。
- 差分検出で“変更された変数のみ”をマージ対象にする。

View File

@ -63,6 +63,8 @@ This roadmap is a living checklist to advance Phase 15 with small, safe boxes. U
- 環境変数制御で段階的移行: `NYASH_USE_PLUGIN_CORE_BOXES=1`
- 削減目標: 約700行nyrt実装600行 + 特別扱い100行
- DLL動作確認→Nyashコード化の安全な移行戦略
- **using構文完全実装**: compiler.nyashのusing構文パース問題解決
- **LLVM ExternCall改善**: print出力問題修正LLVMバックエンド
- 詳細: [phase-15.5-core-box-unification.md](phase-15.5-core-box-unification.md)
6) PHI 自動化は Phase15 後LoopForm = MIR18
- Phase15: 現行の BridgePHI を維持し、E2E 緑とパリティを最優先

View File

@ -14,6 +14,7 @@
- **Plugin-First統一**: 旧VM依存システム完全根絶
- **ビルド成功**: libnyash_kernel.a完全生成0エラー・0警告
- **参照更新**: build_llvm.sh, ny-llvmc等すべて完了
- **🎯 ExternCall修正**: LLVM EXE print出力問題根本解決codex技術力
### 📊 **詳細実装データ**
```

View File

@ -17,7 +17,7 @@
- `NYASH_SELFHOST_TRACE=1`: Ny Executor の構造化ログJSON lines or 整形文字列)。
- `NYASH_SELFHOST_STEP_MAX=<int>`: 1 実行あたりの最大命令数(既定 200000 相当)。
- `NYASH_SELFHOST_STRICT=1`: 厳格モード(型/値のチェックを強化、未知 extern を拒否)。
- 参考: `NYASH_MIR_NO_PHI=1`(開発用。Edge Copy 経路の確認に使用)
- 参考: `NYASH_MIR_NO_PHI=1`(開発用。既定PHI-onからレガシー edge-copy 経路へ切り替えるときに使用)
## 構成(新規 Ny ファイル)
- `apps/selfhost-runtime/`