88 Commits

Author SHA1 Message Date
8a8c90fc74 docs(joinir): Phase 86 SSOT 追記完了 + Phase 88 準備
Phase 86 SSOT 追記(P0 完了):
- 10-Now.md: carrier_init_builder / error_tags 確立を追記
- CURRENT_TASK.md: P0→P1 繰り上げ、Done 節追加

Phase 88 準備:
- nyash_kernel/lib.rs: AOT 実行器で Ring0Context 初期化
- nyash.toml: プラグインパス正規化(plugins/...)
- auto_detect.conf: integration タイムアウト 120秒に延長

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-14 00:05:16 +09:00
e328be0307 Phase 122.5-126完了:ConsoleBox 品質改善・最適化・統合
## 実装成果(Phase 122.5-126)

### Phase 122.5: nyash.toml method_id 修正
- println method_id を 2 → 1 に統一(log と同じ)
- TypeRegistry slot 400 との整合性確保

### Phase 123: ConsoleBox WASM/非WASM コード統一化
- マクロ define_console_impl! による重複排除
- 67行削減(27.3% 削減達成)
- ビルド成功・全テストパス

### Phase 124: VM Method Dispatch 統一化
- TypeRegistry ベースの統一ディスパッチ (dispatch_by_slot)
- String/Array/ConsoleBox を一元化
- 100行削減、メソッド解決の高速化

### Phase 125: 削除:deprecated builtin ConsoleBox
- src/box_factory/builtin_impls/console_box.rs 削除
- Plugin-only 移行で "Everything is Plugin" 実現
- 52行削減

### Phase 126: ドキュメント統合
- consolebox_complete_guide.md (27KB統合マスター)
- core_boxes_design/logging_policy/hako_logging_design 更新
- ~750行の navigation・cross-reference 改善

## 数値成果

- **総コード削減**: 219行
- **新規ドキュメント**: 1ファイル (+27KB)
- **更新ドキュメント**: 6ファイル (+~750行)
- **テスト**: Phase 120 representative tests  PASS
- **ビルド**: Zero errors

## 設計原則の完全実現

 println/log エイリアス統一(Phase 122)
 WASM/非WASM 統一化(Phase 123)
 TypeRegistry 統合(Phase 124)
 Plugin-only 移行(Phase 125)
 ドキュメント統合(Phase 126)

🤖 Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-04 06:02:03 +09:00
024a09c15b feat(core): Phase 122 ConsoleBox.println / log unification
## Phase 122: ConsoleBox.println / log の統一 (完了)

### 概要
ConsoleBox.printlnをlogのエイリアスとしてVM/TypeRegistryレベルで統一。
Phase 120で発見されたesc_dirname_smoke.hakoの「Unknown method 'println'」
エラーを完全解消。

### 完了タスク
-  TypeRegistry修正: printlnをlogのエイリアス(slot 400)として追加
-  ConsoleBox実装: printlnメソッドのラッパ追加
-  VM Method Dispatch: ConsoleBox専用ハンドラ追加
-  Plugin設定: nyash.tomlにprintln (method_id 2)追加
-  ドキュメント更新: 3ファイル(hako_logging/logging_policy/core_boxes)

### 実装詳細

#### 1. TypeRegistry (src/runtime/type_registry.rs)
```rust
const CONSOLE_METHODS: &[MethodEntry] = &[
    MethodEntry { name: "log",     arity: 1, slot: 400 },
    MethodEntry { name: "warn",    arity: 1, slot: 401 },
    MethodEntry { name: "error",   arity: 1, slot: 402 },
    MethodEntry { name: "clear",   arity: 0, slot: 403 },
    // Phase 122: println は log のエイリアス
    MethodEntry { name: "println", arity: 1, slot: 400 },
];
```

#### 2. ConsoleBox (src/boxes/console_box.rs)
- WASM/非WASM両方にprintln()メソッド追加
- 内部的にlog()に委譲

#### 3. VM Method Dispatch (src/backend/mir_interpreter/handlers/calls/method.rs)
- ConsoleBox専用ハンドラ追加
- log/println/warn/error/clearをサポート
- args配列の正しい処理(len > 1時はargs[1]を使用)

#### 4. Plugin設定 (nyash.toml)
- ConsoleBox.methodsにprintln追加(method_id=2)
- method_id整合性: log=1, println=2

### テスト結果
-  esc_dirname_smoke.hako実行成功
  - 旧エラー: "Unknown method 'println'" ← **完全解消**
  - 新出力: `[Console LOG] dir1/dir2`

### Phase 120問題解決
**Phase 120ベースラインでの課題**:
-  esc_dirname_smoke.hako: ConsoleBox.println未実装

**Phase 122での解決**:
-  TypeRegistryレベルでprintln→log正規化
-  全経路(JSON v0/selfhost/通常VM)で一貫性保証

### ファイル構成
**新規作成**:
- docs/development/current/main/phase122_consolebox_println_unification.md

**修正**:
- src/runtime/type_registry.rs (+5行)
- src/boxes/console_box.rs (+14行, WASM/非WASM両対応)
- src/backend/mir_interpreter/handlers/calls/method.rs (+60行)
- nyash.toml (+1メソッド定義)
- docs/development/current/main/hako_logging_design.md (+40行)
- docs/development/current/main/logging_policy.md (+30行)
- docs/development/current/main/core_boxes_design.md (+20行)

### 技術的成果
- **Alias First原則**: VM/TypeRegistryレベルで正規化
- **Phase 120連携**: ベースライン確立→問題発見→根本解決
- **全経路統一**: selfhost/JSON v0/通常VMすべてで動作

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-04 05:16:06 +09:00
8633224061 JoinIR/SSA/Stage-3: sync CURRENT_TASK and dev env 2025-12-01 11:10:46 +09:00
f9d100ce01 chore: Phase 25.1 完了 - LoopForm v2/Stage1 CLI/環境変数削減 + Phase 26-D からの変更
Phase 25.1 完了成果:
-  LoopForm v2 テスト・ドキュメント・コメント完備
  - 4ケース(A/B/C/D)完全テストカバレッジ
  - 最小再現ケース作成(SSAバグ調査用)
  - SSOT文書作成(loopform_ssot.md)
  - 全ソースに [LoopForm] コメントタグ追加

-  Stage-1 CLI デバッグ環境構築
  - stage1_cli.hako 実装
  - stage1_bridge.rs ブリッジ実装
  - デバッグツール作成(stage1_debug.sh/stage1_minimal.sh)
  - アーキテクチャ改善提案文書

-  環境変数削減計画策定
  - 25変数の完全調査・分類
  - 6段階削減ロードマップ(25→5、80%削減)
  - 即時削除可能変数特定(NYASH_CONFIG/NYASH_DEBUG)

Phase 26-D からの累積変更:
- PHI実装改善(ExitPhiBuilder/HeaderPhiBuilder等)
- MIRビルダーリファクタリング
- 型伝播・最適化パス改善
- その他約300ファイルの累積変更

🎯 技術的成果:
- SSAバグ根本原因特定(条件分岐内loop変数変更)
- Region+next_iパターン適用完了(UsingCollectorBox等)
- LoopFormパターン文書化・テスト化完了
- セルフホスティング基盤強化

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: ChatGPT <noreply@openai.com>
Co-Authored-By: Task Assistant <task@anthropic.com>
2025-11-21 06:25:17 +09:00
80f8a7bc8c 🔧 Hotfix 7 (Enhanced): ValueId receiver alias tracking for nested loops
- Problem: Pinned receiver variables in loops cause undefined ValueId errors
- Enhanced fix: Update all receiver aliases (me + all __pin$N$@recv levels)
- Handles nested loops by updating previous pin levels
- Test status: Partial improvement, ValueId(50) → ValueId(40)
- Further investigation needed for complete fix

Files modified:
- src/mir/phi_core/loopform_builder.rs (emit_header_phis)
2025-11-19 00:02:41 +09:00
5bb094d58f feat(.hako): Exit PHI実装(Phase 2-5完了)- リファレンス実装
.hakoコンパイラにExit PHI生成機能を実装(将来の本命実装)

実装ファイル(585行):
- break_finder.hako (~250行): break文検出
- phi_injector.hako (~280行): PHI命令生成・挿入
- loopssa.hako (更新): BreakFinder/PhiInjector統合
- README.md: アーキテクチャ説明・使用方法

設計:
- 箱化・モジュール化(3Box分離)
- JSON文字列→文字列処理
- HAKO_LOOPSSA_EXIT_PHI=1 で有効化

重要な発見:
- Exit PHI生成はMIRレベルで行うべき(JSON v0では情報不足)
- 現在のTest 2エラーはRust MIRビルダーのバグ
- .hako実装は将来のリファレンス・Phase 25.1f用に温存

次のステップ:
- Rust側 loopform_builder.rs のphi pred mismatchバグ修正
- .hakoへの完全移行はPhase 25.1e後半〜25.1f

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-18 04:05:45 +09:00
9f45ebaced feat(.hako): CompilerBuilder.apply_all()配線追加 (Phase 1)
Exit PHI実装の準備として、.hakoコンパイラに
CompilerBuilder.apply_all()呼び出しを追加

変更内容:
- compiler_stageb.hako: parse_program2直後にapply_all()配線
- hako_module.toml: builder.mod export追加
- nyash.toml: モジュールマッピング追加

デバッグ:
- HAKO_COMPILER_BUILDER_TRACE=1 で詳細ログ出力
- [compiler-builder] before/after で変換前後を確認可能

次のステップ:
- Phase 2: BreakFinderBox実装
- Phase 3: PhiInjectorBox実装
- Phase 4: LoopSSA.stabilize_merges実装

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-18 03:37:47 +09:00
eadde8d1dd fix(mir/builder): use function-local ValueId throughout MIR builder
Phase 25.1b: Complete SSA fix - eliminate all global ValueId usage in function contexts.

Root cause: ~75 locations throughout MIR builder were using global value
generator (self.value_gen.next()) instead of function-local allocator
(f.next_value_id()), causing SSA verification failures and runtime
"use of undefined value" errors.

Solution:
- Added next_value_id() helper that automatically chooses correct allocator
- Fixed 19 files with ~75 occurrences of ValueId allocation
- All function-context allocations now use function-local IDs

Files modified:
- src/mir/builder/utils.rs: Added next_value_id() helper, fixed 8 locations
- src/mir/builder/builder_calls.rs: 17 fixes
- src/mir/builder/ops.rs: 8 fixes
- src/mir/builder/stmts.rs: 7 fixes
- src/mir/builder/emission/constant.rs: 6 fixes
- src/mir/builder/rewrite/*.rs: 10 fixes
- + 13 other files

Verification:
- cargo build --release: SUCCESS
- Simple tests with NYASH_VM_VERIFY_MIR=1: Zero undefined errors
- Multi-parameter static methods: All working

Known remaining: ValueId(22) in Stage-B (separate issue to investigate)

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-17 00:48:18 +09:00
5f06d82ee5 Phase 25.1b: Step B完了(multi-carrier LoopForm対応)
Step B実装内容(fibonacci風マルチキャリアループ対応):
- LoopFormBox拡張:
  - multi_count mode追加(build2メソッド)
  - build_loop_multi_carrierメソッド実装(4-PHI, 5 blocks)
  - 3変数(i, a, b)同時追跡のfibonacci構造生成

- LowerLoopMultiCarrierBox新規実装:
  - 複数Local/Assign検出(2+変数)
  - キャリア変数抽出
  - mode="multi_count"でLoopOptsBox.build2呼び出し
  - Fail-Fast: insufficient_carriersタグ出力

- FuncBodyBasicLowerBox拡張:
  - _try_lower_loopに呼び出し導線追加
  - 優先順位: sum_bc → multi_carrier → simple
  - [funcs/basic:loop.multi_carrier]タグ出力

- Module export設定:
  - lang/src/mir/hako_module.toml: sum_bc/multi_carrier追加
  - nyash.toml: 対応するmodule path追加

既存mode完全保持(Rust Freeze遵守):
- count, sum_bcは一切変更なし
- multi_countは完全に独立して追加
- 既存テストへの影響ゼロ

Technical Details:
- PHI構造: 3-PHI (i, a, b) in Header
- Block構成: Preheader → Header → Body → Latch → Exit
- Fibonacci計算: t = a+b, a' = b, b' = t
- copy命令でLatchから Headerへ値を渡す

Task先生調査結果を反映:
- Rust層のパターンC(4-PHI, multi-carrier)に対応
- MirSchemaBox経由で型安全なMIR生成

Next: スモークテスト追加、既存テスト全通確認

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-16 03:11:49 +09:00
7ca7f646de Phase 25.1b: Step2完了(FuncBodyBasicLowerBox導入)
Step2実装内容:
- FuncBodyBasicLowerBox導入(defs専用下請けモジュール)
- _try_lower_local_if_return実装(Local+単純if)
- _inline_local_ints実装(軽い正規化)
- minimal lowers統合(Return/BinOp/IfCompare/MethodArray系)

Fail-Fast体制確立:
- MirBuilderBox: defs_onlyでも必ずタグ出力
- [builder/selfhost-first:unsupported:defs_only]
- [builder/selfhost-first:unsupported:no_match]

Phase構造整備:
- Phase 25.1b README新設(Step0-3計画)
- Phase 25.2b README新設(次期計画)
- UsingResolverBox追加(using system対応準備)

スモークテスト:
- stage1_launcher_program_to_mir_canary_vm.sh追加

Next: Step3 LoopForm対応

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-15 22:32:13 +09:00
6856922374 Phase 25.1a: selfhost builder hotfix (fn rename, docs) 2025-11-15 05:42:32 +09:00
a85045df26 fix(aot): Phase 25 MVP - numeric_core transformation完全動作
2つの重大バグを修正してBoxCall→Call変換を実現:

1. nyash.toml: numeric_coreモジュールマッピング追加
   - selfhost.llvm.ir.aot_prep.passes.numeric_core パスが解決できなかった
   - 224行目に追加してusing解決を修正

2. numeric_core.hako: JSONパース処理の根本修正
   - 問題: text.indexOf("{") が全JSONのルート{を検出
   - 結果: 全体が1命令として扱われ型検出が完全に破綻
   - 修正: op-marker-first パターンに変更
     - "op":"..." を先に検出
     - lastIndexOf("{") で命令開始を特定
     - 各命令を個別に正しく処理

成果:
- 型テーブルサイズ: 1 → 3 (MatI64インスタンス完全検出)
- 変換: BoxCall(MatI64, "mul_naive") → Call("NyNumericMatI64.mul_naive")
- 検証: 全テストパス(単体・E2E・変換・残骸確認)

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-15 00:02:13 +09:00
8214176814 feat(perf): add Phase 21.8 foundation for IntArrayCore/MatI64 numeric boxes
Prepare infrastructure for specialized numeric array benchmarking:
- Add IntArrayCore plugin stub (crates/nyash_kernel/src/plugin/intarray.rs)
- Add IntArrayCore/MatI64 box definitions (lang/src/runtime/numeric/)
- Add Phase 21.8 documentation and task tracking
- Update nyash.toml/hako.toml with numeric library configuration
- Extend microbench.sh for matmul_core benchmark case

Next: Resolve Stage-B MirBuilder to recognize MatI64/IntArrayCore as boxes

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-14 15:18:14 +09:00
f1fa182a4b AotPrep collections_hot matmul tuning and bench tweaks 2025-11-14 13:36:20 +09:00
8b44c5009f fix(mir): fix else block scope bug - PHI materialization order
Root Cause:
- Else blocks were not propagating variable assignments to outer scope
- Bug 1 (if_form.rs): PHI materialization happened before variable_map reset,
  causing PHI nodes to be lost
- Bug 2 (phi.rs): Variable merge didn't check if else branch modified variables

Changes:
- src/mir/builder/if_form.rs:93-127
  - Reordered: reset variable_map BEFORE materializing PHI nodes
  - Now matches then-branch pattern (reset → materialize → execute)
  - Applied to both "else" and "no else" branches for consistency
- src/mir/builder/phi.rs:137-154
  - Added else_modified_var check to detect variable modifications
  - Use modified value from else_var_map_end_opt when available
  - Fall back to pre-if value only when truly not modified

Test Results:
 Simple block: { x=42 } → 42
 If block: if 1 { x=42 } → 42
 Else block: if 0 { x=99 } else { x=42 } → 42 (FIXED!)
 Stage-B body extraction: "return 42" correctly extracted (was null)

Impact:
- Else block variable assignments now work correctly
- Stage-B compiler body extraction restored
- Selfhost builder path can now function
- Foundation for Phase 21.x progress

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-13 20:16:20 +09:00
1ac0c6b880 feat(stageb): implement UsingResolverBox foundation (partial)
Implemented:
- UsingResolverBox full implementation in using_resolver_box.hako
  - state_new(): Empty state creation
  - load_modules_json(): Load modules JSON from nyash.toml
  - resolve_path_alias(): Resolve paths from aliases
  - resolve_namespace_alias(): Tail segment matching with case-insensitive support
  - to_context_json(): Generate context JSON for ParserBox
- Added sh_core entry to nyash.toml modules section
  - Maps to lang/src/shared/common/string_helpers.hako
  - Fixes "using not found: 'sh_core'" errors
- Cleaned up compiler_stageb.hako
  - Removed problematic using statements
  - Added documentation

Known Issue (to be fixed next):
- Body extraction bug in compiler_stageb.hako:51-197
  - Multiline source extraction fails for "static box Main { main() {...} }"
  - Results in empty Program JSON body
  - Causes Stage-B emit pipeline to fall back to jsonfrag (ratio=207900%)
  - This is the root cause blocking selfhost builder path

Impact:
-  sh_core resolution errors fixed
-  UsingResolverBox infrastructure complete
-  Stage-B emit pipeline not restored (body extraction bug)
-  Selfhost builder path still blocked

Next Priority: Fix body extraction bug to restore Stage-B pipeline

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-13 18:11:25 +09:00
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
9e2fa1e36e Phase 21.6 solidification: chain green (return/binop/loop/call); add Phase 21.7 normalization plan (methodize static boxes). Update CURRENT_TASK.md and docs. 2025-11-11 22:35:45 +09:00
2299da7663 feat(phase21.5): selfhost CWD fix + loop executable semantics + diagnostics
## Task 1: Selfhost Child Process CWD Fix 
- Fix: try_selfhost_builder() now runs from repo root
- Implementation: (cd "$ROOT" && ... "$NYASH_BIN" ...)
- Benefit: nyash.toml using mappings are reliably loaded
- Location: tools/hakorune_emit_mir.sh:96-108
- Resolves: "using not found: 'hako.mir.builder.internal.*'" errors

## Task 2: Loop JSONFrag Executable Semantics 
- Upgrade: FORCE=1 now generates complete executable while-loop
- Structure: entry(0) → loop(1) → body(2) → exit(3)
- Semantics:
  - PHI node: i = {i0, entry} | {i_next, body}
  - Increment: i_next = i + 1
  - Backedge: body → loop
  - Exit: ret i (final loop variable value)
- Location: lang/src/mir/builder/internal/loop_opts_adapter_box.hako:24-44
- Expected: rc=10 (limit value) instead of structure-only validation

## Task 3: Enhanced Diagnostics 
- Added: HAKO_SELFHOST_TRACE=1 outputs comprehensive diagnostics
- Info: prog_json_len, tokens (Loop/Compare counts), cwd, nyash.toml status
- Example: [builder/selfhost-first:trace] prog_json_len=90 tokens=Loop:0,Compare:0 cwd=... nyash.toml=present
- Location: tools/hakorune_emit_mir.sh:87-100
- Benefit: One-line diagnosis of CWD/nyash.toml/using issues

## Task 4: nyash.toml Missing Entries 
- Added: hako.mir.builder.internal.builder_config mapping
- Added: hako.mir.builder.internal.loop_opts_adapter mapping
- Location: nyash.toml
- Benefit: Selfhost-first can resolve internal builder dependencies

## Implementation Principles
- 既定挙動不変 (Default unchanged, FORCE=1 guarded)
- Dev toggle controlled (TRACE=1, NO_DELEGATE=1)
- Minimal diff with clear rollback path
- CWD fix ensures stable using resolution
- Executable semantics enable proper EXE testing

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-11 09:09:55 +09:00
ece91306b7 mirbuilder: integrate Normalizer (toggle), add tag-quiet mode, share f64 canonicalization; expand canaries; doc updates for quick timeout + dev toggles; Phase 21.5 optimization readiness 2025-11-10 23:17:46 +09:00
6055d53eff feat(phase21.5/22.1): MirBuilder JsonFrag refactor + FileBox ring-1 + registry tests
Phase 21.5 (AOT/LLVM Optimization Prep)
- FileBox ring-1 (core-ro) provider: priority=-100, always available, no panic path
  - src/runner/modes/common_util/provider_registry.rs: CoreRoFileProviderFactory
  - Auto-registers at startup, eliminates fallback panic structurally
- StringBox fast path prototypes (length/size optimization)
- Performance benchmarks (C/Python/Hako comparison baseline)

Phase 22.1 (JsonFrag Unification)
- JsonFrag.last_index_of_from() for backward search (VM fallback)
- Replace hand-written lastIndexOf in lower_loop_sum_bc_box.hako
- SentinelExtractorBox for Break/Continue pattern extraction

MirBuilder Refactor (Box → JsonFrag Migration)
- 20+ lower_*_box.hako: Box-heavy → JsonFrag text assembly
- MirBuilderMinBox: lightweight using set for dev env
- Registry-only fast path with [registry:*] tag observation
- pattern_util_box.hako: enhanced pattern matching

Dev Environment & Testing
- Dev toggles: SMOKES_DEV_PREINCLUDE=1 (point-enable), HAKO_MIR_BUILDER_SKIP_LOOPS=1
- phase2160: registry opt-in tests (array/map get/set/push/len) - content verification
- phase2034: rc-dependent → token grep (grep -F based validation)
- run_quick.sh: fast smoke testing harness
- ENV documentation: docs/ENV_VARS.md

Test Results
 quick phase2034: ALL GREEN (MirBuilder internal patterns)
 registry phase2160: ALL GREEN (array/map get/set/push/len)
 rc-dependent tests → content token verification complete
 PREINCLUDE policy: default OFF, point-enable only where needed

Technical Notes
- No INCLUDE by default (maintain minimalism)
- FAIL_FAST=0 in Bring-up contexts only (explicit dev toggles)
- Tag-based route observation ([mirbuilder/min:*], [registry:*])
- MIR structure validation (not just rc parity)

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-10 19:42:42 +09:00
981ddd890c Phase 22.1 WIP: SSOT resolver + TLV infrastructure + Hako MIR builder setup
Setup infrastructure for Phase 22.1 (TLV C shim & Resolver SSOT):

Core changes:
- Add nyash_tlv, nyash_c_core, nyash_kernel_min_c crates (opt-in)
- Implement SSOT resolver bridge (src/using/ssot_bridge.rs)
- Add HAKO_USING_SSOT=1 / HAKO_USING_SSOT_HAKO=1 env support
- Add HAKO_TLV_SHIM=1 infrastructure (requires --features tlv-shim)

MIR builder improvements:
- Fix using/alias consistency in Hako MIR builder
- Add hako.mir.builder.internal.{prog_scan,pattern_util} to nyash.toml
- Normalize LLVM extern calls: nyash.console.* → nyash_console_*

Smoke tests:
- Add phase2211 tests (using_ssot_hako_parity_canary_vm.sh)
- Add phase2220, phase2230, phase2231 test structure
- Add phase2100 S3 backend selector tests
- Improve test_runner.sh with quiet/timeout controls

Documentation:
- Add docs/ENV_VARS.md (Phase 22.1 env vars reference)
- Add docs/development/runtime/C_CORE_ABI.md
- Update de-rust-roadmap.md with Phase 22.x details

Tools:
- Add tools/hakorune_emit_mir.sh (Hako-first MIR emission wrapper)
- Add tools/tlv_roundtrip_smoke.sh placeholder
- Improve ny_mir_builder.sh with better backend selection

Known issues (to be fixed):
- Parser infinite loop in static method parameter parsing
- Stage-B output contamination with "RC: 0" (needs NYASH_JSON_ONLY=1)
- phase2211/using_ssot_hako_parity_canary_vm.sh fork bomb (needs recursion guard)

Next steps: Fix parser infinite loop + Stage-B quiet mode for green tests
2025-11-09 15:11:18 +09:00
fa3091061d trace: add execution route visibility + debug passthrough; phase2170 canaries; docs
- Add HAKO_TRACE_EXECUTION to trace executor route
  - Rust hv1_inline: stderr [trace] executor: hv1_inline (rust)
  - Hakovm dispatcher: stdout [trace] executor: hakovm (hako)
  - test_runner: trace lines for hv1_inline/core/hakovm routes
- Add HAKO_VERIFY_SHOW_LOGS and HAKO_DEBUG=1 (enables both)
  - verify_v1_inline_file() log passthrough with numeric rc extraction
  - test_runner exports via HAKO_DEBUG
- Canary expansion under phase2170 (state spec)
  - Array: push×5/10 → size, len/length alias, per‑recv/global, flow across blocks
  - Map: set dup-key non-increment, value_state get/has
  - run_all.sh: unify, remove SKIPs; all PASS
- Docs
  - ENV_VARS.md: add Debug/Tracing toggles and examples
  - PLAN.md/CURRENT_TASK.md: mark 21.7 green, add Quickstart lines

All changes gated by env vars; default behavior unchanged.
2025-11-08 23:45:29 +09:00
772149c86d Analyzer安定化完了: NYASH_DISABLE_PLUGINS=1復元 + plugin無効化根治
## 修正内容
1. **hako_check.sh/run_tests.sh**: NYASH_DISABLE_PLUGINS=1 + NYASH_BOX_FACTORY_POLICY=builtin_first追加
2. **src/box_factory/plugin.rs**: NYASH_DISABLE_PLUGINS=1チェック追加
3. **src/box_factory/mod.rs**: plugin shortcut pathでNYASH_DISABLE_PLUGINS尊重
4. **tools/hako_check/render/graphviz.hako**: smart quotes修正(parse error解消)

## 根本原因
- NYASH_USE_PLUGIN_BUILTINS=1が自動設定され、ArrayBox/MapBoxがplugin経由で生成を試行
- bid/registry.rsで"Plugin loading temporarily disabled"の状態でも試行されエラー
- mod.rs:272のshortcut pathがNYASH_DISABLE_PLUGINSを無視していた

## テスト結果
- 10/11 PASS(HC011,13-18,21-22,31)
- HC012: 既存issue(JSON安定化未完)

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-08 15:49:25 +09:00
301b1d212a Phase 21.2 Complete: VM Adapter正規実装 + devブリッジ完全撤去
## 🎉 Phase 21.2完全達成

###  実装完了
- VM static box 永続化(singleton infrastructure)
- devブリッジ完全撤去(adapter_dev.rs削除、by-name dispatch削除)
- .hako正規実装(MirCallV1Handler, AbiAdapterRegistry等)
- text-merge経路完全動作
- 全phase2120 adapter reps PASS(7テスト)

### 🐛 バグ修正
1. strip_local_decl修正
   - トップレベルのみlocal削除、メソッド内は保持
   - src/runner/modes/common_util/hako.rs:29

2. static box フィールド永続化
   - MirInterpreter singleton storage実装
   - me parameter binding修正(1:1マッピング)
   - getField/setField string→singleton解決
   - src/backend/mir_interpreter/{mod,exec,handlers/boxes_object_fields}.rs

3. Map.len alias rc=0修正
   - [map/missing]パターン検出でnull扱い(4箇所)
   - lang/src/vm/boxes/mir_call_v1_handler.hako:91-93,131-133,151-153,199-201

### 📁 主要変更ファイル

#### Rust(VM Runtime)
- src/backend/mir_interpreter/mod.rs - static box singleton storage
- src/backend/mir_interpreter/exec.rs - parameter binding fix
- src/backend/mir_interpreter/handlers/boxes_object_fields.rs - singleton resolution
- src/backend/mir_interpreter/handlers/calls.rs - dev bridge removal
- src/backend/mir_interpreter/utils/mod.rs - adapter_dev module removal
- src/backend/mir_interpreter/utils/adapter_dev.rs - DELETED (7555 bytes)
- src/runner/modes/vm.rs - static box declaration collection
- src/runner/modes/common_util/hako.rs - strip_local_decl fix
- src/instance_v2.rs - Clone implementation

#### Hako (.hako実装)
- lang/src/vm/boxes/mir_call_v1_handler.hako - [map/missing] detection
- lang/src/vm/boxes/abi_adapter_registry.hako - NEW (adapter registry)
- lang/src/vm/helpers/method_alias_policy.hako - method alias support

#### テスト
- tools/smokes/v2/profiles/quick/core/phase2120/s3_vm_adapter_*.sh - 7 new tests

### 🎯 テスト結果
```
 s3_vm_adapter_array_len_canary_vm.sh
 s3_vm_adapter_array_len_per_recv_canary_vm.sh
 s3_vm_adapter_array_length_alias_canary_vm.sh
 s3_vm_adapter_array_size_alias_canary_vm.sh
 s3_vm_adapter_map_len_alias_state_canary_vm.sh
 s3_vm_adapter_map_length_alias_state_canary_vm.sh
 s3_vm_adapter_map_size_struct_canary_vm.sh
```

環境フラグ: HAKO_ABI_ADAPTER=1 HAKO_ABI_ADAPTER_DEV=0

### 🏆 設計品質
-  ハードコード禁止(AGENTS.md 5.1)完全準拠
-  構造的・一般化設計(特定Box名のif分岐なし)
-  後方互換性保持(既存コード破壊ゼロ)
-  text-merge経路(.hako依存関係正しくマージ)

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-07 19:32:44 +09:00
e326e787a4 release: v21.0.0 – Full Self‑Hosting (S1/S2/S3 complete)
- DoD met: S1/S2 determinism (const/compare/threeblock-collect), PRIMARY hv1 inline no-fallback, S3 (llvmlite+kernel) reps green
- Harness: v1→llvmlite direct, EXE links to libnyash_kernel.a
- Python LLVM builder fixes: cmp normalization, ret PHI synthesis, mir_call flat shape
- Using/alias polish (prod): modules-first; missing aliases added; duplicate using cleaned
- Docs: phase-21.0 COMPLETE; CurrentTask closed; release notes added
2025-11-06 16:59:34 +09:00
77d4fd72b3 phase: 20.49 COMPLETE; 20.50 Flow+String minimal reps; 20.51 selfhost v0/v1 minimal (Option A/B); hv1-inline binop/unop/copy; docs + run_all + CURRENT_TASK -> 21.0 2025-11-06 15:41:52 +09:00
96ea3892af phase-20.45: PRIMARY no-fallback reps + MIR v0 shape fixes
- Fix MIR v0 shape in lowers: functions[] + name="main" + blocks.id
  * lower_return_int_box.hako
  * lower_return_binop_box.hako
- runner_min: adopt LowerReturnBinOpBox before ReturnInt
- Add PRIMARY no-fallback canaries (all PASS):
  * return-binop / array-size / load-store / return-logical (OR)
- Fix phase2043 runner_min canary alias (Runner -> BuilderRunnerMinBox)
- Update docs: phase-20.45 README (PRIMARY reps), CURRENT_TASK progress

Ancillary: keep builder/provider/canary files in sync; no unrelated behavior changes.
2025-11-05 18:57:03 +09:00
44a5158a14 hv1: early-exit at main (no plugin init); tokenizer: Stage-3 single-quote + full escapes (\/ \b \f \' \r fix); builder: route BinOp via SSOT emit_binop_to_dst; hv1 verify canary route (builder→Core); docs: phase-20.39 updates 2025-11-04 20:46:43 +09:00
30aa39f50b hv1 verify: add direct route (env JSON) and clean inline path; fix v1 phi incoming order; make test_runner use hv1 direct; add phase2037 phi canaries; load modules.workspace exports for alias; update docs (phase-20.38, source extensions) and CURRENT_TASK 2025-11-04 16:33:04 +09:00
06a729ff40 vm(hako): add v1 reader/dispatcher (flagged), commonize mir_call handler, share block scan; smokes: add v1 hakovm canary; docs: 20.37/20.38 plans, OOB policy; runner: v1 hakovm toggle; include SKIP summary 2025-11-03 23:21:48 +09:00
a4f30ae827 Phase 20.34: expand MirBuilder internal library with comprehensive lowering boxes; add pattern registry and program scanning infrastructure; implement internal lowerers for if/loop/return patterns; add dev tools and comprehensive canary tests; update VM boxes and host providers for internal delegation; wire phase2034 test suite with 30+ canary scripts covering internal lowering scenarios
Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
2025-11-03 16:09:19 +09:00
63f1242a57 Phase 20.34 prep: add using aliases in nyash.toml for hako.mir.builder & hako.llvm.emit; add README contracts for MirBuilderBox/LLVMEmitBox; verify canaries green 2025-11-02 19:27:29 +09:00
df9068a555 feat(stage-b): Add FLOW keyword support + fix Stage-3 keyword conflicts
##  Fixed Issues

### 1. `local` keyword tokenization (commit 9aab64f7)
- Added Stage-3 gate for LOCAL/TRY/CATCH/THROW keywords
- LOCAL now only active when NYASH_PARSER_STAGE3=1

### 2. `env.local.get` keyword conflict
- File: `lang/src/compiler/entry/compiler_stageb.hako:21-23`
- Problem: `.local` in member access tokenized as `.LOCAL` keyword
- Fix: Commented out `env.local.get("HAKO_SOURCE")` line
- Fallback: Use `--source` argument (still functional)

### 3. `flow` keyword missing
- Added FLOW to TokenType enum (`src/tokenizer/kinds.rs`)
- Added "flow" → TokenType::FLOW mapping (`src/tokenizer/lex_ident.rs`)
- Added FLOW to Stage-3 gate (requires NYASH_PARSER_STAGE3=1)
- Added FLOW to parser statement dispatch (`src/parser/statements/mod.rs`)
- Added FLOW to declaration handler (`src/parser/statements/declarations.rs`)
- Updated box_declaration parser to accept BOX or FLOW (`src/parser/declarations/box_definition.rs`)
- Treat `flow FooBox {}` as syntactic sugar for `box FooBox {}`

### 4. Module namespace conversion
- Renamed `lang.compiler.builder.ssa.local` → `localvar` (avoid keyword)
- Renamed file `local.hako` → `local_ssa.hako`
- Converted 152 path-based using statements to namespace format
- Added 26+ entries to `nyash.toml` [modules] section

## ⚠️ Remaining Issues

### Stage-B selfhost compiler performance
- Stage-B compiler not producing output (hangs/times out after 10+ seconds)
- Excessive PHI debug output suggests compilation loop issue
- Needs investigation: infinite loop or N² algorithm in hako compiler

### Fallback JSON version mismatch
- Rust fallback (`--emit-mir-json`) emits MIR v1 JSON (schema_version: "1.0")
- Smoke tests expect MIR v0 JSON (`"version":0, "kind":"Program"`)
- stageb_helpers.sh fallback needs adjustment

## Test Status
- Parse errors: FIXED 
- Keyword conflicts: FIXED 
- Stage-B smoke tests: STILL FAILING  (performance issue)

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-02 04:13:17 +09:00
756af0da6c Phase 20.33: migrate docs to lang compiler entry; add Bridge canonicalize canary skeletons (opt-in); dep_tree.sh fail-fast legacy path; Gate-C OOB strict already present 2025-11-01 19:01:55 +09:00
b9340a1b19 refactor(mir): Phase 6-2 - Apply helper methods to reduce ~28 lines in JSON v0 Bridge
**Phase 6-2完了:ヘルパーメソッド適用で28行削減達成!**

## 📊 削減実績
- **loop_.rs**: 8行→1行(7行削減) - PHI更新ループ統一
- **if_else.rs**: 6行→1行(5行削減) - Branch終端設定統一
- **try_catch.rs**: 8箇所×2-3行(16行削減) - Jump終端設定統一
- **合計**: ~28行削減

## 🔧 適用内容
### 1. loop_.rs - PHI更新の統一化
- **Before**: 手動でPHI命令を検索してinputs.push()
- **After**: `bb.update_phi_input(phi_dst, (bend, latch_val))?`

### 2. if_else.rs - Branch終端設定の統一化
- **Before**: if-let-Some + bb.set_terminator(Branch {...})
- **After**: `f.set_branch_terminator(cur, cval, then_bb, else_bb)?`

### 3. try_catch.rs - Jump終端設定の統一化(8箇所)
- **Before**: if-let-Some + bb.set_terminator(Jump {...})
- **After**: `f.set_jump_terminator(bb_id, target)?`

##  テスト結果
- `loop_min_while.nyash`:  PASS(0,1,2出力)
- `loop_phi_one_sided.nyash`:  PASS(ArrayBox警告のみ)
- ビルド:  88 warnings(既存レベル)

## 🎯 Phase 6進捗
- **Phase 6-1**:  ヘルパーメソッド追加(+46行)
- **Phase 6-2**:  ヘルパー適用(-28行)
- **実質削減**: -28行(基盤整備込み)

## 📋 次のステップ
- **Phase 6-3**: BranchMergeBuilder pattern(~100行削減見込み)
- **Phase 6-4**: 全体統合・最終テスト

Related: Phase 1-5(3,824行削減)に続く段階的リファクタリング

🐱 にゃーん!実用化成功!
2025-11-01 15:23:28 +09:00
6a452b2dca fix(mir): PHI検証panic修正 - update_cfg()を検証前に呼び出し
A案実装: debug_verify_phi_inputs呼び出し前にCFG predecessorを更新

修正箇所(7箇所):
- src/mir/builder/phi.rs:50, 73, 132, 143
- src/mir/builder/ops.rs:273, 328, 351

根本原因:
- Branch/Jump命令でsuccessorは即座に更新
- predecessorはupdate_cfg()で遅延再構築
- PHI検証が先に実行されてpredecessor未更新でpanic

解決策:
- 各debug_verify_phi_inputs呼び出し前に
  if let Some(func) = self.current_function.as_mut() {
      func.update_cfg();
  }
  を挿入してCFGを同期

影響: if/else文、論理演算子(&&/||)のPHI生成が正常動作
2025-11-01 13:28:56 +09:00
978bb4a5c6 runner: add NyVM wrapper core_bridge (canonicalize/dump) + opt-in wrapper canary; export module in common_util 2025-11-01 02:51:49 +09:00
34be7d2d79 vm/router: minimal special-method extension (equals/1); toString mapping kept
mir: add TypeCertainty to Callee::Method (diagnostic only); plumb through builder/JSON/printer; backends ignore behaviorally

using: confirm unified prelude resolver entry for all runner modes

docs: update Callee architecture with certainty; update call-instructions; CURRENT_TASK note

tests: quick 40/40 PASS; integration (LLVM) 17/17 PASS
2025-09-28 01:33:58 +09:00
cb236b7f5a json(vm): fix birth dispatch; unify constructor naming (Box.birth/N); JsonNode factories return JsonNodeInstance; quick: enable heavy JSON with probe; builder: NYASH_BUILDER_DEBUG_LIMIT guard; json_query_min(core) harness; docs/tasks updated 2025-09-27 08:45:25 +09:00
85084664c2 docs+runner+parser: SSOT+AST using finalized (legacy text inlining removed); provider verify reads nyash.toml; preflight warn hook; method-body guard removed; CURRENT_TASK updated for next JSON work 2025-09-26 00:27:02 +09:00
d9f26d4549 feat: nyash.toml SSOT + using AST統合完了(12時間の戦い)
- nyash.tomlを唯一の真実(SSOT)として依存管理確立
- dev/ci/prodプロファイルによる段階的厳格化実装
- AST結合で宣言/式の曖昧性を根本解決
- Fail-Fast原則をCLAUDE.md/AGENTS.mdに明文化
- VM fallbackでもASTベース using有効化(NYASH_USING_AST=1)
- 静的メソッドの is_static=true 修正で解決安定化
- STATICブレークハック既定OFF化で堅牢性向上

🎉 usingシステム完全体への道筋確立!JSONライブラリ・Nyash VM開発が可能に

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-25 16:03:29 +09:00
9384c80623 using: safer seam defaults (fix_braces OFF by default) + path-alias handling; json_native: robust integer parse + EscapeUtils unquote; add JsonCompat layer; builder: preindex static methods + fallback for bare calls; diagnostics: seam dump + function-call trace 2025-09-25 10:23:14 +09:00
f0608e9bb1 feat: Phase 2.4 レガシーアーカイブ整理完了(151MB削減)
## 🎉 完了項目
-  plugin_box_legacy.rs削除(7.7KB、参照ゼロ確認済み)
-  REMOVEDコメント整理(encode.rs簡潔化)
-  venv削除(143MB節約、.gitignoreは既存)
-  llvm_legacyスタブ化(8KB、compile_error!による安全化)

## 🏆 成果
- **リポジトリサイズ改善**: 151MB削減
- **コード整理**: レガシーコード安全にアーカイブ
- **プラグインファースト**: StrictPluginFirst継続動作

##  検証完了
- cargo build --release --features llvm (警告のみ、エラーなし)
- LLVMハーネス実行: print出力正常
- プラグイン動作: StringBox等正常動作

codex先生の戦略に従った安全な段階的削除を実行

Co-Authored-By: codex <noreply@anthropic.com>
2025-09-24 14:13:15 +09:00
73b90a7c28 feat: スモークテストv2実装&Phase 15.5後のプラグイン対応
Phase 15.5 Core Box削除後の新テストシステム構築:

## 実装内容
- スモークテストv2システム完全実装(3段階プロファイル)
- 共通ライブラリ(test_runner/plugin_manager/result_checker/preflight)
- インタープリター層完全削除(約350行)
- PyVM重要インフラ特化保持戦略(JSON v0ブリッジ専用)
- nyash.tomlパス修正(13箇所、プラグイン正常ロード確認)

## 動作確認済み
- 基本算術演算(+, -, *, /)
- 制御構文(if, loop, break, continue)
- 変数代入とスコープ
- プラグインロード(20個の.soファイル)

## 既知の問題
- StringBox/IntegerBoxメソッドが動作しない
  - オブジェクト生成は成功するがメソッド呼び出しでエラー
  - Phase 15.5影響でプラグイン実装が不完全な可能性

## ドキュメント
- docs/development/testing/smoke-tests-v2.md 作成
- docs/reference/pyvm-usage-guidelines.md 作成
- CODEX_QUESTION.md(Codex相談用)作成

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-24 09:30:42 +09:00
8bbc30509c feat: Phase 15.5-A 予約型保護解除完了+StringBox問題調査
🎯 **Phase 15.5 Phase A実装完了**
-  is_reserved_type()修正: 環境変数による条件付きバイパス実装
-  NYASH_USE_PLUGIN_BUILTINS=1 + NYASH_PLUGIN_OVERRIDE_TYPES対応
-  ビルド確認: エラーなしでコンパイル成功
-  プラグインロード確認: 予約型拒否エラーなし

🔍 **StringBox問題完全調査**
- 問題特定: get()/set()が空文字を返す(length=4で内部データあり)
- 全バックエンド影響: VM/プラグイン/コア すべて同じ問題
- MIRレベル正常: newbox/boxcall正しく生成
- 調査資料: /tmp/stringbox_test_results.md完備

📂 **変更ファイル**
- src/box_factory/mod.rs: 予約型保護条件付き解除
- docs/phase-15.5: Phase A完了ドキュメント更新
- nyash.toml: StringBox/IntegerBoxプラグイン設定追加

🚀 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-24 05:57:08 +09:00
8e4cadd349 selfhost(pyvm): MiniVmPrints – prefer JSON route early-return (ok==1) to avoid fallback loops; keep default behavior unchanged elsewhere 2025-09-22 07:54:25 +09:00
27568eb4a6 json: add v2 JsonDoc/JsonNode plugin with runtime provider switch; vendored yyjson + FFI; loader resolve(name)->method_id; PyVM JSON shims; smokes + CI gate; disable MiniVmPrints fallbacks by default
- plugin_loader_v2: store per-Box resolve() from TypeBox FFI; add resolve_method_id() and use in invoke_instance_method
- plugin_loader_unified: resolve_method() falls back to loader’s resolve when TOML lacks method entries
- nyash.toml: register JsonDocBox/JsonNodeBox methods (birth/parse/root/error; kind/get/size/at/str/int/bool)
- plugins/nyash-json-plugin:
  * serde/yyjson provider switch via env NYASH_JSON_PROVIDER (default serde)
  * vendored yyjson (c/yyjson) + shim; parse/root/get/size/at/str/int/bool implemented for yyjson
  * TLV void returns aligned to tag=9
- PyVM: add minimal JsonDocBox/JsonNodeBox shims in ops_box.py (for dev path)
- tests/smokes: add jsonbox_{parse_ok,parse_err,nested,collect_prints}; wire two into min-gate CI
- tools: collect_prints_mixed now uses JSON-based app
- MiniVmPrints: move BinaryOp and fallback heuristics behind a dev toggle (default OFF)
- CURRENT_TASK.md: updated with provider policy and fallback stance
2025-09-22 06:16:20 +09:00
c8063c9e41 pyvm: split op handlers into ops_core/ops_box/ops_ctrl; add ops_flow + intrinsic; delegate vm.py without behavior change
net-plugin: modularize constants (consts.rs) and sockets (sockets.rs); remove legacy commented socket code; fix unused imports
mir: move instruction unit tests to tests/mir_instruction_unit.rs (file lean-up); no semantic changes
runner/pyvm: ensure using pre-strip; misc docs updates

Build: cargo build ok; legacy cfg warnings remain as before
2025-09-21 08:53:00 +09:00