**Problem**: ValueId(14)/ValueId(17) circular dependency in multi-carrier loop PHI construction. Loop body PHIs referenced ValueIds not defined in header exit block, causing SSA use-before-def violations. **Root Cause**: Interleaved ValueId allocation when processing pinned (parameters like 'me', 'args') and carrier (locals like 'i', 'n') variables created forward references: ``` Iteration 1: pre_copy=%13, phi=%14 ✅ Iteration 2: pre_copy=%15, phi=%19 ✅ (but %14 not yet emitted!) Body PHI: phi %17 = [%14, bb3] ❌ %14 doesn't exist in bb3 ``` **Solution**: LoopForm Meta-Box with 3-pass PHI construction algorithm inspired by Braun et al. (2013) "Simple and Efficient SSA Construction". **Core Design**: - **Meta-Box abstraction**: Treat entire loop as single Box with explicit carrier/pinned separation - **Three-pass algorithm**: 1. Allocate ALL ValueIds upfront (no emission) 2. Emit preheader copies in deterministic order 3. Emit header PHIs (incomplete) 4. Seal PHIs after loop body (complete) - **Guarantees**: No circular dependencies possible (all IDs pre-allocated) **Academic Foundation**: - Cytron et al. (1991): Classical SSA with dominance frontiers - Braun et al. (2013): Simple SSA with incomplete φ-nodes ✅ Applied here - LLVM Canonical Loop Form: Preheader→Header(PHI)→Body→Latch **Files Added**: 1. **src/mir/phi_core/loopform_builder.rs** (360 lines): - LoopFormBuilder struct with carrier/pinned separation - LoopFormOps trait (abstraction layer) - Three-pass algorithm implementation - Unit tests (all pass ✅) 2. **docs/development/analysis/loopform-phi-circular-dependency-solution.md**: - Comprehensive problem analysis (600+ lines) - Academic literature review - Alternative approaches comparison - Detailed implementation plan 3. **docs/development/analysis/LOOPFORM_PHI_SOLUTION_SUMMARY.md**: - Executive summary (250 lines) - Testing strategy - Migration timeline (4 weeks) - Risk assessment 4. **docs/development/analysis/LOOPFORM_PHI_NEXT_STEPS.md**: - Step-by-step integration guide (400 lines) - Code snippets for mir/loop_builder.rs - Troubleshooting guide - Success metrics **Testing**: - ✅ Unit tests pass (deterministic allocation verified) - ⏳ Integration tests (Week 2 with feature flag) - ⏳ Selfhost support (Week 3) **Migration Strategy**: - Week 1 (Current): ✅ Prototype complete - Week 2: Integration with NYASH_LOOPFORM_PHI_V2=1 feature flag - Week 3: Selfhost compiler support - Week 4: Full migration, deprecate old code **Advantages**: 1. **Correctness**: Guarantees SSA definition-before-use 2. **Simplicity**: ~360 lines (preserves Box Theory philosophy) 3. **Academic alignment**: Matches state-of-art SSA construction 4. **Backward compatible**: Feature-flagged with rollback capability **Impact**: This resolves the fundamental ValueId circular dependency issue blocking Stage-B selfhosting, while maintaining the LoopForm design philosophy of "normalize everything, confine to scope". **Total Contribution**: ~2,000 lines of code + documentation **Next Steps**: Integrate LoopFormBuilder into src/mir/loop_builder.rs following LOOPFORM_PHI_NEXT_STEPS.md guide (estimated 2-4 hours). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
📚 Nyash Documentation
🚀 はじめに(導線)
- 現在のタスクと進行状況: ../CURRENT_TASK.md
- コア概念の速習: reference/architecture/nyash_core_concepts.md
- 設計ブループリント(文字列/文字コード): development/design/blueprints/strings-utf8-byte.md
📂 ドキュメント構造(指針)
📖 reference/ - 正式な技術仕様
- language/ - 言語仕様(構文、型システム、Box仕様)
- architecture/ - システムアーキテクチャ(MIR、VM、実行バックエンド)
- api/ - ビルトインBoxのAPI仕様
- plugin-system/ - プラグインシステム、BID-FFI仕様
- 🆕🔥 TypeBox ABI統合 + セルフホスティング - ABIすらBoxとして扱う革命的設計!
- まずはこちら:
reference/boxes-system/plugin_lifecycle.md(PluginBoxV2のライフサイクル、singleton、nyash.tomlの要点)
📚 guides/ - 利用者向けガイド
- getting-started.md - はじめに(統一版)
- tutorials/ - ステップバイステップのチュートリアル
- examples/ - 実践的なサンプルコード
- wasm-guide/ - WebAssemblyビルドガイド
🧩 how-to/ - 目的別ハウツー
- 手順重視の短いガイド(前提→コマンド→検証)
🔧 development/ - 開発者向け
- current/ - 現在進行中のタスク(CURRENT_TASK.md等)
- roadmap/ - 開発計画
- phases/ - Phase 8~12の詳細計画
- phase-12/ - 🆕🔥 TypeBox統合ABI + Nyash ABI C実装(セルフホスティング実現!)
- native-plan/ - ネイティブビルド計画
- proposals/ - RFC、新機能提案
🔌 Net Plugin(HTTP/TCP)
- 使い方と仕様:
reference/plugin-system/net-plugin.md
🗄️ archive/ - アーカイブ
- consultations/ - AI相談記録(gemini/chatgpt/codex)
- decisions/ - 過去の設計決定
- build-logs/ - ビルドログ、ベンチマーク結果
- old-versions/ - 古いドキュメント
🎯 クイックアクセス
すぐ始める
- guides/getting-started.md
- guides/language-guide.md
- guides/p2p-guide.md
技術リファレンス
- reference/language/LANGUAGE_REFERENCE_2025.md
- reference/language/EBNF.md(演算子: ! 採用 / do-while 非採用)
- reference/language/strings.md(UTF‑8/Byte 二本柱)
- reference/architecture/TECHNICAL_ARCHITECTURE_2025.md
- reference/architecture/execution-backends.md
- reference/runtime/gc.md
- reference/plugin-system/
- tools/cli-options.md(CLI早見表)
デザイン/ガイド
- guides/language-core-and-sugar.md(コア最小+糖衣)
- guides/loopform.md(ループ正規化)
- guides/scopebox.md(開発時の可視化)
- guides/dev-local-alias.md(開発向け: 行頭 @name = expr → local 宣言糖衣)
- guides/box-patterns.md(Boxパターン集:Ownership/Lease/Cancel/Capability/Affinity/Observable)
- guides/box-design-checklist.md(Box 設計チェックリスト)
- proposals/concurrency/boxes.md(並行モデルのBox設計:Routine/Channel/Select/Scope)
- reference/concurrency/semantics.md(ブロッキング/close/select/観測の規約)
- design/(設計ノート入口)
- development/design/legacy/flow-blocks.md(矢印フロー/匿名ブロック・設計草案)
- development/proposals/scope-reuse.md(スコープ再利用ブロック・MVP提案)
- reference/language/match-guards.md(ガード連鎖/Range・CharClass設計)
- guides/core-principles.md(最小構文・ゼロランタイム・可視化の原則)
開発状況
- 現在のタスク
- 開発ロードマップ
- Phase別計画
- 🔥 Phase 12: TypeBox統合ABI
- 🔥 Phase 16: マクロ革命
- 🧪 Phase 17: LoopForm Self‑Hosting
- 💡 Rust所有権統合(候補) - Phase 17+候補
- 🧩 Mini‑VM 構築ロードマップ
- 🧭 Using→Loader 統合(最小設計): development/design/legacy/using-loader-integration.md
- 🗂️ Docsの書き方(小さく・リンク駆動): guides/contributing-docs.md
📋 再編成について / フォルダの見分け方
ドキュメントは2025年8月20日に再編成されました。詳細はREORGANIZATION_REPORT.mdを参照してください。
旧パスから新パスへの主な変更:
説明書/→guides/とreference/に分割予定/→development/roadmap/- 散在していたファイル → 適切なカテゴリに整理
補足:
reference/は正本(仕様)。guides/は読み物、how-to/は手順書。design/は公開できる設計ノート。private/は下書き保管庫(将来reference//design/に昇格)。
Nyash は「Everything is Box」哲学に基づく言語です。詳細はコア概念とガイドを参照してください。