Files
hakorune/lang/src/llvm_ir
nyash-codex 71ff310471 feat(aot): add backpropagation pass to CollectionsHot for improved type inference
Implement call-site type signal backpropagation to reduce Unknown receiver types
and increase Array/Map get/set/has externcall conversion coverage.

**Implementation:**
- New function: tmap_backprop (collections_hot.hako:82-164)
  - Propagates type signals from call sites: push→Array, stringy key→Map, linear index→Array
  - Fixpoint iteration (max 2 rounds)
  - Control: NYASH_AOT_CH_BACKPROP=1 (default ON)
- Enhanced is_stringy_key_in_block
  - Detects toString method, StringBox const, binop + StringBox const
- Diagnostic logging with NYASH_AOT_CH_TRACE=1
  - "[aot/collections_hot] backprop recv=<vid> => arr|map via method=<mname>"

**Results:**
Test case: /tmp/arraymap_min.hako
- ORIG: 7 boxcalls, 0 externcalls
- PREP: 1 boxcall, 6 externcalls (86% reduction)
- jsonfrag: 0 (structure preserved)

Benchmark: tools/perf/microbench.sh --case arraymap --exe
- ORIG: 8 boxcalls
- PREP: 2 boxcalls, 6 externcalls (75% reduction)
- Array: push(1), get(1), set(1) = 3 externcalls
- Map: set(2), get(1) = 3 externcalls
- Remaining: toString(2) = 2 boxcalls (expected)

**Benefits:**
- Unknown receiver type reduction via call-site analysis
- Improved optimization coverage for Array/Map operations
- Opt-in design, CFG unchanged, jsonfrag=0

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-14 06:42:52 +09:00
..

LLVM Script Builder (opt-in, Phase 20.11)

目的

  • Python llvmlite ハーネスで行っている IR 構築を、Hakorune スクリプトの薄い箱で段階的に置き換える。
  • 責務は「IR 構築」に限定し、リンクおよび実行は小ライブラリlibhako_aot/AotBox に委譲する。

ゲート

  • HAKO_LLVM_SCRIPT_BUILDER=1 で有効化既定OFF
  • 厳格化未実装はFAIL: HAKO_LLVM_SCRIPT_BUILDER_STRICT=1既定はFAIL推奨

責務境界Box

  • LLVMModuleBox: モジュール作成・型/レイアウト設定・関数登録
  • LLVMFunctionBox: 関数定義・基本ブロック追加
  • LLVMBuilderBox: 命令構築v0: const/binop/ret から開始)
  • LLVMTypesBox: 代表的なプリミティブ型クエリ
  • LLVMEmitBox: オブジェクト出力(当面は AotBox へ委譲予定)

FailFast

  • 未実装/未対応は UNSUPPORTED: <op> を短文で出力して負値を返す(将来は統一エラーへ)。

将来拡張

  • v1: compare/branch/phi、v2: call/externhako_* の C-ABI のみ)
  • MIR→IR の対応は SSOT に集約し、Builder は小さな純関数にまとめる。