Files
hakorune/docs/development/roadmap/phases/phase-21.6-solidification
nyash-codex dda65b94b7 Phase 21.7 normalization: optimization pre-work + bench harness expansion
- Add opt-in optimizations (defaults OFF)
  - Ret purity verifier: NYASH_VERIFY_RET_PURITY=1
  - strlen FAST enhancement for const handles
  - FAST_INT gate for same-BB SSA optimization
  - length cache for string literals in llvmlite
- Expand bench harness (tools/perf/microbench.sh)
  - Add branch/call/stringchain/arraymap/chip8/kilo cases
  - Auto-calculate ratio vs C reference
  - Document in benchmarks/README.md
- Compiler health improvements
  - Unify PHI insertion to insert_phi_at_head()
  - Add NYASH_LLVM_SKIP_BUILD=1 for build reuse
- Runtime & safety enhancements
  - Clarify Rust/Hako ownership boundaries
  - Strengthen receiver localization (LocalSSA/pin/after-PHIs)
  - Stop excessive PluginInvoke→BoxCall rewrites
- Update CURRENT_TASK.md, docs, and canaries

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-13 16:40:58 +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

Provider Path Notes (Dev)

  • Optional normalization for provider output is available via HAKO_MIR_NORMALIZE_PROVIDER=1.
    • This applies the same JsonFrag normalizer/purifier to MIR(JSON) emitted by the Rust Provider path.
    • Keep defaults unchanged; use only during bringup to eliminate retafter effects.
  • HAKO_MIR_BUILDER_LOOP_FORCE_JSONFRAG=1 now shortcircuits both selfhostfirst and providerfirst wrappers to emit a minimal, pure controlflow MIR suitable for EXE build sanity.
    • Default OFF; intended for small canaries and performance harness bringup.

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.