Files
hakorune/docs/development/roadmap/phases/phase-21.6-solidification
nyash-codex 52b62c5772 feat(phase21.5): Stage-B parser loop fix + delegate path stabilization
## 修正内容

### 1. Stage-B パーサー修正(偶然の回避)
- **ファイル**:
  - `lang/src/compiler/parser/expr/parser_expr_box.hako`
  - `lang/src/compiler/parser/stmt/parser_control_box.hako`
- **問題**: ネストループで gpos が正しく進まず、loop の cond/body が壊れる
- **回避策**: new 式のメソッドチェーン処理追加で別ループを導入
- **結果**: MIR 生成が変わって VM gpos バグを回避

### 2. delegate パス動作確認
- **テスト**: `/tmp/loop_min.hako` → rc=10 
- **MIR構造**: 正しい PHI/compare/binop を生成
- **チェーン**: hakorune parser → Rust delegate → LLVM EXE 完動

### 3. ドキュメント追加
- `docs/development/analysis/` - delegate 分析
- `docs/development/guides/` - ループテストガイド
- `docs/development/testing/` - Stage-B 検証報告

### 4. カナリーテスト追加
- `tools/smokes/v2/profiles/quick/core/phase2100/` 配下に複数追加
- emit_boxcall_length_canary_vm.sh
- stageb_parser_loop_json_canary_vm.sh
- 他

### 受け入れ基準
-  delegate パス: rc=10 返す
-  FORCE パス: rc=10 返す(既存)
-  MIR 構造: 正しい PHI incoming と compare
-  既定挙動: 不変(dev トグルのみ)

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-11 21:24:51 +09:00
..

Phase 21.6 — Solidification (Hakoruneonly chain)

Goal

  • Develop and validate the full chain using Hakorune only: Parser(StageB) → MirBuilder (selfhostfirst) → VM → nyllvmc(crate) object/exe.
  • Stop optimizations until the chain is green and repeatable on this host.

Scope

  • Parser(StageB): JSON v0 correctness for control flow, call/method, literals.
  • MirBuilder: stable MIR(JSON) emission (no spurious newbox/MapBox in loop JsonFrag path when not intended).
  • VM: execute MIR(JSON) deterministically; stats/dev toggles optional.
  • nyllvmc(crate): build obj/exe from MIR(JSON); no llvmlite dependency in the default path.

Default Policy

  • Defaults remain unchanged for users. All bringup aids behind env toggles.
  • Logs quiet by default. Dev tags require explicit env.
  • Rust layer is used for diagnosis only; development proceeds via Hakorune scripts.

Env Toggles (recommended dev)

  • HAKO_SELFHOST_BUILDER_FIRST=1
  • NYASH_USE_NY_COMPILER=0 (alias of NYASH_DISABLE_NY_COMPILER)
  • HAKO/NYASH_ENABLE_USING=1
  • NYASH_PARSER_STAGE3=1, HAKO_PARSER_STAGE3=1
  • NYASH_LLVM_BACKEND=crate
  • Optional (debug): HAKO_MIR_BUILDER_LOOP_FORCE_JSONFRAG=1, HAKO_MIR_BUILDER_JSONFRAG_NORMALIZE=1

How to run (chain E2E)

  1. Emit MIR(JSON):
    • bash tools/hakorune_emit_mir.sh input.hako /tmp/out.json
  2. Build EXE (crate):
    • NYASH_LLVM_BACKEND=crate bash tools/ny_mir_builder.sh --in /tmp/out.json --emit exe -o a.out
  3. Run + check rc:
    • ./a.out; echo $?

Canaries

  • tools/dev/stageb_loop_json_canary.sh — Program(JSON) shape for loop(i<n){i=i+1}
  • tools/dev/phase216_chain_canary.sh — endtoend EXE rc=10 for minimal loop

Removal Plan for temporary parser fallback

  • Once VM/gpos interaction is fixed and parser emits correct loop JSON without guards, remove the conservative fallback in ParserControlBox.parse_loop.