## Phase 92全体の成果 **Phase 92 P0-P2**: ConditionalStep JoinIR生成とbody-local変数サポート - ConditionalStep(条件付きキャリア更新)のJoinIR生成実装 - Body-local変数(ch等)の条件式での参照サポート - 変数解決優先度: ConditionEnv → LoopBodyLocalEnv **Phase 92 P3**: BodyLocalPolicyBox + 安全ガード - BodyLocalPolicyDecision実装(Accept/Reject判定) - BodyLocalSlot + DualValueRewriter(JoinIR/MIR二重書き込み) - Fail-Fast契約(Cannot promote LoopBodyLocal検出) **Phase 92 P4**: E2E固定+回帰最小化 (本コミット) - Unit test 3本追加(body-local変数解決検証) - Integration smoke追加(phase92_pattern2_baseline.sh、2ケースPASS) - P4-E2E-PLAN.md、P4-COMPLETION.md作成 ## 主要な実装 ### ConditionalStep(条件付きキャリア更新) - `conditional_step_emitter.rs`: JoinIR Select命令生成 - `loop_with_break_minimal.rs`: ConditionalStep検出と統合 - `loop_with_continue_minimal.rs`: Pattern4対応 ### Body-local変数サポート - `condition_lowerer.rs`: body-local変数解決機能 - `lower_condition_to_joinir`: body_local_env パラメータ追加 - 変数解決優先度実装(ConditionEnv優先) - Unit test 3本追加: 変数解決/優先度/エラー - `header_break_lowering.rs`: break条件でbody-local変数参照 - 7ファイルで後方互換ラッパー(lower_condition_to_joinir_no_body_locals) ### Body-local Policy & Safety - `body_local_policy.rs`: BodyLocalPolicyDecision(Accept/Reject) - `body_local_slot.rs`: JoinIR/MIR二重書き込み - `dual_value_rewriter.rs`: ValueId書き換えヘルパー ## テスト体制 ### Unit Tests (+3) - `test_body_local_variable_resolution`: body-local変数解決 - `test_variable_resolution_priority`: 変数解決優先度(ConditionEnv優先) - `test_undefined_variable_error`: 未定義変数エラー - 全7テストPASS(cargo test --release condition_lowerer::tests) ### Integration Smoke (+1) - `phase92_pattern2_baseline.sh`: - Case A: loop_min_while.hako (Pattern2 baseline) - Case B: phase92_conditional_step_minimal.hako (条件付きインクリメント) - 両ケースPASS、integration profileで発見可能 ### 退行確認 - ✅ 既存Pattern2Breakテスト正常(退行なし) - ✅ Phase 135 smoke正常(MIR検証PASS) ## アーキテクチャ設計 ### 変数解決メカニズム ```rust // Priority 1: ConditionEnv (loop params, captured) if let Some(value_id) = env.get(name) { return Ok(value_id); } // Priority 2: LoopBodyLocalEnv (body-local like `ch`) if let Some(body_env) = body_local_env { if let Some(value_id) = body_env.get(name) { return Ok(value_id); } } ``` ### Fail-Fast契約 - Delta equality check (conditional_step_emitter.rs) - Variable resolution error messages (ConditionEnv) - Body-local promotion rejection (BodyLocalPolicyDecision::Reject) ## ドキュメント - `P4-E2E-PLAN.md`: 3レベルテスト戦略(Level 1-2完了、Level 3延期) - `P4-COMPLETION.md`: Phase 92完了報告 - `README.md`: Phase 92全体のまとめ ## 将来の拡張(Phase 92スコープ外) - Body-local promotionシステム拡張 - P5bパターン認識の汎化(flagベース条件サポート) - 完全なP5b E2Eテスト(body-local promotion実装後) 🎯 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Hybrid Selfhost Build (80/20)
Purpose
- Provide a minimal, fast path to compile Hako source via Hakorune Stage‑B to Program(JSON v0), and optionally run it via Core‑Direct (in‑proc).
- Future: add MIR emit and ny-llvmc EXE build in small increments.
Script
- tools/selfhost/selfhost_build.sh
- --in <file.hako>: input Hako source
- --json <out.json>: write Program(JSON v0); default: /tmp/hako_stageb_$$.json
- --mir <out.json>: emit MIR(JSON) from source (runner path)
- --exe : build native executable via ny-llvmc (llvmlite harness)
- --run: run via Gate‑C/Core Direct (in‑proc). Exit code mirrors program return.
- Env:
- NYASH_BIN: path to hakorune/nyash binary (auto-detected)
- NYASH_ROOT: repo root (auto-detected)
- HAKO_USE_BUILDBOX=1: use BuildBox for emit-only (no run/exe)
Examples
# Emit JSON only (Stage‑B)
tools/selfhost/selfhost_build.sh --in apps/demo/main.hako --json /tmp/demo.json
# Run and use exit code
tools/selfhost/selfhost_build.sh --in apps/demo/return7.hako --run; echo $?
Notes
- Stage‑B emit uses either the Stage‑B entry or BuildBox(HAKO_USE_BUILDBOX=1 for emit-only)
- Runner executes Core‑Direct in-proc under HAKO_CORE_DIRECT_INPROC=1.
- For heavier cases (bundles/alias/require), keep Stage‑B canaries opt‑in in quick profile.
Stage1 Selfhost Binary (Phase 25.1 — initial wiring)
Purpose
- Provide a concrete Stage1 binary (
hakorune) built from Hako sources. - Separate the Rust bootstrap binary (Stage0,
nyash) from the Hakorune selfhost binary at the build-script level.
Script
- tools/selfhost/build_stage1.sh
- Builds a Stage1 selfhost executable from a Nyash/Hako entry point.
- Current entry (default):
lang/src/runner/launcher.hako— Stage1 CLI launcher (commands: emit program-json/mir-json, etc.).
- Output:
target/selfhost/hakoruneby default.
Usage
# Build Stage1 selfhost binary with defaults
tools/selfhost/build_stage1.sh
# Custom output path
tools/selfhost/build_stage1.sh --out /tmp/hakorune-dev
# Custom entry (experimental)
tools/selfhost/build_stage1.sh --entry apps/selfhost-minimal/main.hako --out /tmp/hako_min
How it works
- Pipeline:
- Stage‑B + MirBuilder:
tools/hakorune_emit_mir.sh <entry.hako> <mir.json>
- LLVM EXE build:
tools/ny_mir_builder.sh --in <mir.json> --emit exe -o <exe>
- Stage‑B + MirBuilder:
- The Rust binary (Stage0) is resolved via the existing helpers inside
hakorune_emit_mir.sh/ny_mir_builder.sh:- Prefers
target/release/hakorunewhen present. - Falls back to
target/release/nyashotherwise.
- Prefers
Notes
- This Stage1 binary is a minimal Ny Executor and not yet a full CLI replacement.
- Full CLI / mode selection for Stage1 will be implemented in later phases; this script focuses on establishing the binary layout and build wiring.
Helper — Stage1 CLI Runner
tools/selfhost/run_stage1_cli.sh- Wraps a Stage1 binary (default
target/selfhost/hakorune) with the required runtime env:NYASH_NYRT_SILENT_RESULT=1(Result 行を抑止して JSON stdout を維持)NYASH_DISABLE_PLUGINS=1,NYASH_FILEBOX_MODE=core-ro(FileBox などのコア実装を強制)
- Pass arguments verbatim to the Stage1 CLI:
tools/selfhost/run_stage1_cli.sh emit program-json apps/tests/minimal.hako tools/selfhost/run_stage1_cli.sh --bin /tmp/hakorune-dev emit mir-json apps/tests/minimal.hako - Use this helper (or set the env vars manually) whenever CLI output is consumed by scripts, so that stdout matches llvmlite harness expectations.
- Wraps a Stage1 binary (default