Commit Graph

687 Commits

Author SHA1 Message Date
97a76c0571 selfhost: stub stage3 parser nodes under gate 2025-09-16 18:36:54 +09:00
fa1619bf4b selfhost: add ternary parser and plugin prefix guard 2025-09-16 17:38:22 +09:00
fce0d2cdef docs: log parser/emitter Stage-2 update 2025-09-16 17:11:03 +09:00
7db2c24808 selfhost: harden parser Stage-2 defaults 2025-09-16 17:10:27 +09:00
63c8fda808 🔍 Research: GPT-5-Codex capabilities and GitHub PR integration
## Summary
Investigated OpenAI's new GPT-5-Codex model and Codex GitHub PR review integration capabilities.

## GPT-5-Codex Analysis

### Benchmark Performance (Good)
- SWE-bench Verified: 74.5% (vs GPT-5's 72.8%)
- Refactoring tasks: 51.3% (vs GPT-5's 33.9%)
- Code review: Higher developer ratings

### Real-World Issues (Concerning)
- Users report degraded coding performance
- Scripts that previously worked now fail
- Less consistent than GPT-4.5
- Longer response times (minutes vs instant)
- "Creatively and emotionally flat"
- Basic errors (e.g., counting letters incorrectly)

### Key Finding
Classic case of "optimizing for benchmarks vs real usability" - scores well on tests but performs poorly in practice.

## Codex GitHub PR Integration

### Setup Process
1. Enable MFA and connect GitHub account
2. Authorize Codex GitHub app for repos
3. Enable "Code review" in repository settings

### Usage Methods
- **Manual**: Comment '@codex review' in PR
- **Automatic**: Triggers when PR moves from draft to ready

### Current Limitations
- One-way communication (doesn't respond to review comments)
- Prefers creating new PRs over updating existing ones
- Better for single-pass reviews than iterative feedback

## 'codex resume' Feature
New session management capability:
- Resume previous codex exec sessions
- Useful for continuing long tasks across days
- Maintains context from interrupted work

🐱 The investigation reveals that while GPT-5-Codex shows benchmark improvements, practical developer experience has declined - a reminder that metrics don't always reflect real-world utility\!
2025-09-16 16:28:25 +09:00
47f4ca0e44 📚 docs: Record field declaration design discussion in papers
## Summary
Documented the "init block vs fields-at-top" design discussion as a valuable example of AI-human collaboration in language design.

## Changes

### Paper G (AI Collaboration)
- Added field-declaration-design.md documenting the entire discussion flow
- Showcased how complex init block proposal evolved to simple "fields at top" rule
- Demonstrates AI's tendency toward complexity vs human intuition for simplicity

### Paper H (AI Practical Patterns)
- Added Pattern #17: "Gradual Refinement Pattern" (段階的洗練型)
- Documents the process: Complex AI proposal → Detailed analysis → Human insight → Convergence
- Field declaration design as a typical example

### Paper K (Explosive Incidents)
- Added Incident #046: "init block vs fields-at-top incident"
- Updated total count to 46 incidents
- Shows how a single human comment redirected entire design approach

## Design Decision
After analysis, decided that BoxIndex should remain a compiler-internal structure, not a core Box:
- Core Boxes: User-instantiable runtime values (String, Integer, Array, Map)
- Compiler internals: BoxIndex for name resolution (compile-time only)
- Clear separation of concerns between language features and compiler tools

## Philosophy
This discussion exemplifies key principles:
- The best design needs no explanation
- Constraints provide clarity, not limitation
- "Everything is Box" doesn't mean "compiler internals are Boxes"
- AI tends toward theoretical completeness; humans toward practical simplicity

🐱 Sometimes the simplest answer is right in front of us\!
2025-09-16 14:57:05 +09:00
6ca56b0652 feat: 配列/Mapリテラル糖衣構文の実装とネームスペース解決の改善計画
- ArrayLiteral/MapLiteralのAST定義追加
- パーサーで[...]と{...}構文をサポート
- MIR Builderでnew Box() + push/setへのdesugaring実装
- テストケースとスモークスクリプト追加
- CURRENT_TASK.mdにネームスペース解決Phase-1計画を追記
- 3段階解決順序(ローカル→エイリアス→プラグイン)の設計合意
2025-09-16 06:13:44 +09:00
18bc386bc5 chore: 未使用インポートの削除と軽微な警告修正 2025-09-16 04:23:20 +09:00
edd95406aa fix: aotモジュール公開とビルドエラー修正 2025-09-16 04:13:33 +09:00
40db299bab refactor: Gemini/ChatGPT collaborative refactoring + build fixes
Major changes:
- Split runner module: 1358→580 lines (via Gemini)
- Create new modules: dispatch.rs, selfhost.rs, pipeline.rs, pipe_io.rs
- Fix build errors from incomplete method migrations
- Add warning to CLAUDE.md about JIT/Cranelift not working
- Create interpreter.rs mode module
- Refactor loop builder into separate module

Build status:
-  Executable builds successfully
-  Basic execution works (tested with print)
- ⚠️ 106 warnings remain (to be cleaned up next)
- ⚠️ execute_mir_mode still in mod.rs (needs further migration)

Note: ChatGPT correctly fixed runner.execute_mir_mode() calls
that I incorrectly changed to super::modes::mir::

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-16 03:54:44 +09:00
f9bd13f4e4 docs: Update CURRENT_TASK.md with refactoring progress
- Add module splitting completion status (runner module)
- Record successful build after phi visibility fixes
- Update incident log with 4 new entries (042-045)
- Document PyVM vs EXE-first strategy confusion resolution
- Track Phase 15.3 (Nyash compiler MVP) progress

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-16 02:01:19 +09:00
ab76cd35fa refactor: 大規模なモジュールを分割し、コードの構造を改善
runner, mir/builder, backend/llvm の各モジュールが肥大化していたため、責務ごとにファイルを分割し、見通しを改善するリファクタリングを実施。

### `runner`
- `mod.rs` に集中していたロジックを、以下のモジュールに分割:
    - `tasks.rs`: `nyash.toml` のタスク実行処理
    - `build.rs`: AOTビルドパイプラインの実装
    - `pipeline.rs`: `using` の解決など、パイプライン中のユーティリティ
    - `demos.rs`: デモの実行処理

### `mir/builder`
- `if/else` 文のPHIノード生成ロジックを `stmts.rs` から `phi.rs` へ切り出し。
- `utils.rs` にあったPHI関連のヘルパーも `phi.rs` に集約。
- ASTから自由変数を収集するロジックを `vars.rs` へ切り出し。

### `backend/llvm/compiler/codegen`
- 巨大だった `lower_one_function` 関数を、`function.rs` モジュールとして分離。
- `sanitize_symbol` などのヘルパー関数を `utils.rs` へ移動。
2025-09-16 01:54:00 +09:00
63717cf590 🏗️ Runner モジュール分割とセルフホスティング基盤整備
## 主な変更点

### 🔧 src/runner/ のモジュール分割実装
- mod.rs(1358行)を機能別に分割:
  - pipeline.rs: 入力正規化、using解決、環境注入
  - pipe_io.rs: stdin/fileのJSON v0受理・整形
  - selfhost.rs: セルフホストEXE/VM/Pythonフォールバック
  - dispatch.rs: backend選択と実行、PyVM委譲
- 責務の明確化と保守性向上

### 🚀 セルフホスティング改善
- selfhost.rs: 過渡的なshimから本格実装へ移行開始
- Result出力の調和(PyVM経路でも"Result: N"出力)
- タイムアウト処理とプロセス管理の改善

### 🐛 テストスクリプトの暴走対策
- selfhost_stage2_smoke.sh: 36,783プロセス生成問題への対応
- プロセス管理とタイムアウト処理の見直し

## 技術的詳細
- common.rsのrun_file_legacy()として旧実装を保持
- 新しいモジュール構造で循環依存を回避
- Phase 15.3のセルフホスティング基盤を強化

次のステップ:各モジュールの実装を段階的に移行

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-16 00:01:31 +09:00
94d95dfbcd 🚀 Break/Continue/Try-Catch構文のサポート追加とMIRループ制御強化
## 主な変更点

### 🎯 MIRループ制御の実装(根治対応)
- src/mir/loop_builder.rs: Break/Continue対応のループコンテキスト管理
  - ループのbreak/continueターゲットブロック追跡
  - ネストループの適切な処理
- src/mir/builder.rs: Break/Continue文のMIR生成実装
- src/tokenizer.rs: Break/Continue/Tryトークン認識追加

### 📝 セルフホストパーサーの拡張
- apps/selfhost-compiler/boxes/parser_box.nyash:
  - Stage-3: break/continue構文受理(no-op実装)
  - Stage-3: try-catch-finally構文受理(構文解析のみ)
  - エラー処理構文の将来対応準備

### 📚 ドキュメント更新
- 論文K(爆速事件簿): 45事例に更新(4件追加)
  - PyVM迂回路の混乱事件
  - Break/Continue無限ループ事件
  - EXE-first戦略の再発見
- 論文I(開発秘話): Day 38の重要決定追加

### 🧪 テストケース追加
- apps/tests/: ループ制御とPHIのテストケース
  - nested_loop_inner_break_isolated.nyash
  - nested_loop_inner_continue_isolated.nyash
  - loop_phi_one_sided.nyash
  - shortcircuit関連テスト

## 技術的詳細
- Break/ContinueをMIRレベルで適切に処理
- 無限ループ問題(CPU 99.9%暴走)の根本解決
- 将来の例外処理機能への準備

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-15 22:14:42 +09:00
d90216e9c4 📚 Phase 15 - セルフホスティング戦略の明確化とEXE-first実装
## 主な変更点

### 🎯 戦略の転換と明確化
- PyVMを開発ツールとして位置づけ(本番経路ではない)
- EXE-first戦略を明確に優先(build_compiler_exe.sh実装済み)
- Phase順序の整理: 15.2(LLVM)→15.3(コンパイラ)→15.4(VM)

### 🚀 セルフホスティング基盤の実装
- apps/selfhost-compiler/にNyashコンパイラMVP実装
  - compiler.nyash: メインエントリー(位置引数対応)
  - boxes/: parser_box, emitter_box, debug_box分離
- tools/build_compiler_exe.sh: ネイティブEXEビルド+dist配布
- Python MVPパーサーStage-2完成(local/if/loop/call/method/new)

### 📝 ドキュメント整備
- Phase 15 README/ROADMAP更新(Self-Hosting優先明記)
- docs/guides/exe-first-wsl.md: WSLクイックスタート追加
- docs/private/papers/: 論文G~L、爆速事件簿41事例収録

### 🔧 技術的改善
- JSON v0 Bridge: If/Loop PHI生成実装(ChatGPT協力)
- PyVM/llvmliteパリティ検証スイート追加
- using/namespace機能(gated実装、Phase 15では非解決)

## 次のステップ
1. パーサー無限ループ修正(未実装関数の実装)
2. EXEビルドとセルフホスティング実証
3. c0→c1→c1'ブートストラップループ確立

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-15 18:44:49 +09:00
8f11c79f19 📚 Add complete 41-incident collection to Paper K
- 世界記録級TOP10事件の詳細記録
- 16パターン別に全41事例を分類・整理
- JIT1日完成、20日でEXE、AIが人間に相談等の歴史的事件
- 統計データ: 45日間、破綻0回の奇跡
- 印象的なエピソード(こらー!事件、AIパニック等)収録

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-15 04:12:24 +09:00
af11c6855b 🚀 Start Phase 15.3: Nyash compiler MVP implementation
Major milestone:
- Set up apps/selfhost-compiler/ directory structure
- Implement basic Nyash compiler in Nyash (CompilerBox)
- Stage-1: Basic arithmetic parser (int/string/+/-/*/括弧/return)
- JSON v0 output compatible with --ny-parser-pipe
- Runner integration with NYASH_USE_NY_COMPILER=1 flag
- Comprehensive smoke tests for PHI/Bridge/Stage-2

Technical updates:
- Updated CLAUDE.md with Phase 15.3 status and MIR14 details
- Statement separation policy: newline-based with minimal ASI
- Fixed runaway ny-parser-pipe processes (CPU 94.9%)
- Clarified MIR14 as canonical instruction set (not 13/18)
- LoopForm strategy: PHI auto-generation during reverse lowering

Collaborative development:
- ChatGPT5 implementing compiler skeleton
- Codex provided LoopForm PHI generation guidance
- Claude maintaining documentation and coordination

🎉 セルフホスティングの歴史的一歩!自分自身をコンパイルする日が近いにゃ!

Co-Authored-By: ChatGPT <noreply@openai.com>
2025-09-15 01:21:37 +09:00
d01f9b9c93 Implement JSON v0 Bridge with full PHI support for If/Loop statements
Major implementation by ChatGPT:
- Complete JSON v0 Bridge layer with PHI generation for control flow
- If statement: Merge PHI nodes for variables updated in then/else branches
- Loop statement: Header PHI nodes for loop-carried dependencies
- Python MVP Parser Stage-2: Added local/if/loop/call/method/new support
- Full CFG guarantee: All blocks have proper terminators (branch/jump/return)
- Type metadata for string operations (+, ==, !=)
- Comprehensive PHI smoke tests for nested and edge cases

This allows MIR generation without Rust MIR builder - massive step towards
eliminating Rust build dependency!

🎉 ChatGPTが30分以上かけて実装してくれたにゃ!

Co-Authored-By: ChatGPT <noreply@openai.com>
2025-09-14 23:22:05 +09:00
5cad0ab20c 🔧 Fix peek expression terminator issues and add ternary operator support
- Fix LLVM IR terminator missing in peek expression entry blocks
- Add proper jump instructions between peek blocks
- Implement ternary operator (? :) as syntactic sugar for peek
- Update Python LLVM externcall handling for improved compatibility
- Add comprehensive test cases for peek and ternary expressions
- Update language guide with ternary operator documentation

ChatGPTが頑張って修正してくれたにゃ!🐱

Co-Authored-By: ChatGPT <noreply@openai.com>
2025-09-14 20:30:38 +09:00
8f1b2ffa12 📚 docs: Update CLAUDE.md with latest progress and discoveries
Major updates:
- Updated progress section (2025-09-14) with recent achievements:
  - Python LLVM backend reaching production level (all tests passing)
  - Nyash parser implementation started by ChatGPT5
  - peek expression rediscovery (when→peek rename)
  - Box theory simplifying SSA construction (650→100 lines)
  - AI collaboration paper completed

Documentation improvements:
- Changed 500-line limit to "guideline" (not strict requirement)
- Upgraded Python LLVM backend from "experimental" to "production level"
- Added peek expression examples and usage patterns
- Updated todo list status (parser planning completed, compiler MVP in progress)

These updates reflect the significant progress towards self-hosting,
especially the parser implementation using peek expressions to avoid
19-line if-else nesting.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-14 19:26:46 +09:00
3ba96d9a03 🚀 feat: Multiple improvements for Nyash parser and LLVM backend
Parser improvements:
- Added expression statement fallback in parse_statement() for flexible syntax
- Fixed ternary operator to use PeekExpr instead of If AST (better lowering)
- Added peek_token() check to avoid ?/?: operator conflicts

LLVM Python improvements:
- Added optional ESC_JSON_FIX environment flag for string concatenation
- Improved PHI generation with better default handling
- Enhanced substring tracking for esc_json pattern

Documentation updates:
- Updated language guide with peek expression examples
- Added box theory diagrams to Phase 15 planning
- Clarified peek vs when syntax differences

These changes enable cleaner parser implementation for self-hosting,
especially for handling digit conversion with peek expressions instead
of 19-line if-else chains.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-14 19:16:32 +09:00
ab1afbc57b perf: Set cargo default to 24 threads for all builds
Created .cargo/config.toml with:
- jobs = 24 (all cargo builds use 24 threads by default)
- CARGO_INCREMENTAL = 1 (enable incremental compilation)

This affects all cargo commands in the project, making explicit -j 24
unnecessary in build scripts (though keeping them for clarity is fine).

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-14 18:23:56 +09:00
42f6b15f81 perf: Add 24-thread parallel building to build_llvm.sh
- Added -j 24 to cargo build commands (lines 52, 83)
- Consistent with build_jit.sh which already uses 24 threads
- Significantly speeds up LLVM builds on multi-core systems

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-14 17:09:16 +09:00
4c0e6726e3 🔧 refactor(llvm-py): Fix resolver PHI handling and add trace improvements
Changes to resolver.py:
- Improved PHI value tracking in _value_at_end_i64() (lines 268-285)
- Added trace logging for snap hits with PHI detection
- Fixed PHI placeholder reuse logic to preserve dominance
- PHI values now returned directly from snapshots when valid

Changes to llvm_builder.py:
- Fixed externcall instruction parsing (line 522: 'func' instead of 'name')
- Improved block snapshot tracing (line 439)
- Added PHI incoming metadata tracking (lines 316-376)
- Enhanced definition tracking for lifetime hints

This should help debug the string carry=0 issue in esc_dirname_smoke where
PHI values were being incorrectly coerced instead of preserved.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-14 16:25:21 +09:00
3e07763af8 docs: update CURRENT_TASK with Box Theory PHI plan (defer/finalize) and MIR v0.5 type meta; add parity tooling and PyVM scaffolding
impl(pyvm/llvmlite):
- add tools/parity.sh; tools/pyvm_runner.py; src/llvm_py/pyvm/*
- emit string const as handle type in MIR JSON; add dst_type hints
- unify '+' to concat_hh with from_i64/from_i8_string bridges; console print via to_i8p_h
- add runtime bridges: nyash.box.from_i64, nyash.string.to_i8p_h

tests:
- add apps/tests/min_str_cat_loop (minimal repro for string cat loop)
2025-09-14 04:51:33 +09:00
658a0d46da feat(llvm-py): Major breakthrough in Python LLVM backend! 🎉
 Print and FileBox paths now working correctly
 Resolver simplified by removing overly aggressive fast-path optimization
 Both OFF/ON in compare_harness_on_off.sh now use Python version
 String handle propagation issues resolved

Key changes:
- Removed instruction reordering in llvm_builder.py (respecting MIR order)
- Resolver now more conservative but reliable
- compare_harness_on_off.sh updated to use Python backend for both paths

This marks a major milestone towards Phase 15 self-hosting with Python/llvmlite!

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-14 00:44:28 +09:00
2a9aa5368d harness(llvm/py): fix PHI/dominance via Resolver-only; per-pred localization and constant GEPs; stabilize Main.esc_json/1, dirname/1, node_json/3; docs: add NYASH_LLVM_TRACE_FINAL and Resolver-only invariants
- Resolver-only reads across BBs; remove vmap fallbacks
- Create PHIs at block start; insert casts in preds before terminators
- Re-materialize int in preds to satisfy dominance (add/zext/trunc)
- Use constant GEP for method strings to avoid order dependency
- Order non-PHI lowering to preserve producer→consumer dominance
- Update docs: RESOLVER_API.md, LLVM_HARNESS.md
- compare_harness_on_off: ON/OFF exits match; linking green
2025-09-13 19:49:03 +09:00
1d6fab4eda 📚 Phase 15計画を詳細化・更新: Python/llvmlite正式採用とプラグイン全方向ビルド戦略
 主な更新内容:
- Python/llvmlite実装の正式採用を明記(開発速度10倍、~2400行)
- プラグイン全方向ビルド戦略(.so/.o/.a同時生成)で単一EXE生成可能に
- 各実装の予想コード量を具体化(パーサー800行、MIR Builder 2500行、VM 5000行)
- 循環依存問題の解決を明記(nyrtがC ABI経由で提供)
- 現実的なスケジュール調整(2025年9月~2026年3月)

🎉 最新進捗:
- dep_tree_min_string.nyashオブジェクト生成成功(10.4KB)
- LLVM verifier green - dominance違反解決
- Resolver patternでSSA安全性確保

🚀 次のマイルストーン:
- Python/llvmliteでEXE生成パイプライン完成
- nyash-llvm-compiler分離設計
- NyashパーサーMVP実装開始

Everything is Boxの究極形が、ついに実現へ!

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-13 15:37:58 +09:00
8e4f6d774d refactor(llvm): Extract lower_one_function and emit_wrapper_and_object
Major refactoring to reduce mod.rs size (773 lines → more manageable):
- Extract lower_one_function() as separate function (421 lines)
- Extract emit_wrapper_and_object() for object generation
- Add helper functions: sanitize_symbol, build_const_str_map
- Keep old code in comments (BEGIN_OLD_BLOCK/END_OLD_BLOCK) for reference

This continues the modularization effort after ChatGPT's Context Boxing work.
Next step: Further split lower_one_function into smaller pieces.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-13 00:37:09 +09:00
3bef7e8608 feat(llvm): Implement Context Boxing pattern for cleaner APIs
Major improvement to reduce parameter explosion (15+ args → 3-4 contexts):
- Add LowerFnCtx/BlockCtx for grouping related parameters
- Add lightweight StrHandle/StrPtr newtypes for string safety
- Implement boxed API wrappers for boxcall/fields/invoke
- Add dev checks infrastructure (NYASH_DEV_CHECK_DISPATCH_ONLY_PHI)

Key achievements:
- lower_boxcall: 16 args → 7 args via boxed API
- fields/invoke: Similar parameter reduction
- BuilderCursor discipline enforced throughout
- String handle invariant: i64 across blocks, i8* only at call sites

Status:
- Internal migration in progress (fields → invoke → marshal)
- Full cutover pending due to borrow checker constraints
- dep_tree_min_string.o generation successful (sealed=ON)

Next: Complete internal migration before flipping to boxed APIs

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-13 00:07:38 +09:00
8b48480844 refactor(llvm): Complete Resolver pattern implementation across all instructions
Major structural improvement driven by ChatGPT 5 Pro analysis:
- Replace all direct vmap access with Resolver API calls
- Add proper cursor/bb_map/preds/block_end_values to all instruction handlers
- Ensure dominance safety by localizing values through Resolver
- Fix parameter passing in invoke/fields/extern handlers

Key changes:
- boxcall: Use resolver.resolve_i64/ptr instead of direct vmap access
- strings: Remove unused recv_v parameter, use Resolver throughout
- invoke: Add missing context parameters for proper PHI handling
- fields: Add resolver and block context parameters
- flow/arith/maps: Consistent Resolver usage pattern

This addresses the "structural invariant" requirements:
1. All value fetching goes through Resolver (no direct vmap.get)
2. Localization happens at BB boundaries via Resolver
3. Better preparation for PHI-only-in-dispatch pattern

Next: Consider boxing excessive parameters (15+ args in some functions)

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-12 22:36:20 +09:00
f77bbb5878 📝 CLAUDE.md cleanup and reorganization
- 重複していたPython LLVMバックエンドの記述を統一
- 日付を2025-09-10→09-12に更新
- 冗長な説明やコード例を簡潔に整理
- ビルド実証例の詳細をドキュメントリンクへ移動
- GUI開発セクションを削除(別ドキュメントへ)
- 573行に整理(目安の500行に近づけた)

クリーンで読みやすいドキュメントになったにゃ〜
2025-09-12 21:06:47 +09:00
ef44801fa6 Python LLVM backend implementation (experimental)
- Created llvmlite-based LLVM backend in src/llvm_py/
- Implemented all MIR14 instructions (const, binop, jump, branch, ret, compare, phi, call, boxcall, externcall, typeop, newbox, safepoint, barrier)
- Experimental LoopForm support
- ~2000 lines of clean Python code vs complex Rust/inkwell
- Useful for PHI/SSA validation and rapid prototyping
- Added documentation to CLAUDE.md

This was created while waiting for ChatGPT's investigation of BuilderCursor issues.
2025-09-12 20:55:13 +09:00
38aea59fc1 llvm: unify lowering via Resolver and Cursor; remove non-sealed PHI wiring; apply Resolver to extern/call/boxcall/arrays/maps/mem; add llvmlite harness docs; add LLVM layer overview; add LoopForm preheader 2025-09-12 20:40:48 +09:00
d5af6b1d48 docs: Create AI-assisted compiler development paper structure
Added paper-g-ai-assisted-compiler folder documenting:
- Week-long LLVM backend development with AI assistance
- Key insights from PHI/SSA struggles to Resolver API solution
- Development log capturing the chaotic reality
- Abstract in both English and Japanese

Key quote: 'I don't remember anymore' - capturing the authentic
experience of intensive AI-assisted development where the process
itself becomes the research data.

This represents potentially the first fully documented case of
building a compiler backend primarily through AI assistance.
2025-09-12 20:27:32 +09:00
c04b0c059d feat(llvm): Major refactor - BuilderCursor全域化 & Resolver API導入
Added:
- Resolver API (resolve_i64) for unified value resolution with per-block cache
- llvmlite harness (Python) for rapid PHI/SSA verification
- Comprehensive LLVM documentation suite:
  - LLVM_LAYER_OVERVIEW.md: Overall architecture and invariants
  - RESOLVER_API.md: Value resolution strategy
  - LLVM_HARNESS.md: Python verification harness

Updated:
- BuilderCursor applied to ALL lowering paths (externcall/newbox/arrays/maps/call)
- localize_to_i64 for dominance safety in strings/compare/flow
- NYASH_LLVM_DUMP_ON_FAIL=1 for debug IR output

Key insight: LoopForm didn't cause problems, it just exposed existing design flaws:
- Scattered value resolution (now unified via Resolver)
- Inconsistent type conversion placement
- Ambiguous PHI wiring responsibilities

Next: Wire Resolver throughout, achieve sealed=ON green for dep_tree_min_string
2025-09-12 20:06:48 +09:00
45f13cf7a8 docs: Add LLVM Python harness plan to CURRENT_TASK
- Added llvmlite verification harness strategy
- Python as parallel verification path for PHI/SSA issues
- Nyash ABI wrapper for LLVM emit abstraction
- NYASH_LLVM_USE_HARNESS=1 flag for mode switching
- Goal: Rust implementation in 1-2 days, Python for rapid verification

Acknowledging reality: When stuck at minimal viable implementation,
changing implementation language is a practical solution.
'Simple is Best' - the core Nyash philosophy.
2025-09-12 19:23:16 +09:00
da51f0e51b feat(llvm): Add optional latch→header connection in LoopForm
- Added NYASH_LOOPFORM_LATCH2HEADER environment variable
- When enabled, latch block jumps back to header (completing the loop)
- When disabled (default), latch remains unreachable (safe mode)
- Preserves header predecessor count stability in default mode

This allows gradual testing of full LoopForm loop structure.
2025-09-12 16:55:25 +09:00
65497bac04 feat(llvm): LoopForm experimental implementation Phase 1
- Added LoopForm IR scaffolding with 5-block structure (header/body/dispatch/latch/exit)
- Implemented dispatch block with PHI nodes for tag(i8) and payload(i64)
- Created registry infrastructure for future body→dispatch wiring
- Header→dispatch wiring complete with Break=1 signal
- Gated behind NYASH_ENABLE_LOOPFORM=1 environment variable
- Successfully tested with loop_min_while.nyash (1120 bytes object)

Next steps:
- Implement 2-step Jump chain detection
- Add NYASH_LOOPFORM_BODY2DISPATCH for body→dispatch redirect
- Connect latch→header when safe

🚀 Phase 1 foundation complete and working!
2025-09-12 16:41:29 +09:00
043472c170 docs(papers): Update MIR13 to MIR14 and create SSA construction paper
Major changes:
- Update all MIR13 references to MIR14 throughout paper-a-mir13-ir-design/
- Add evolution history: 27 → 13 → 14 instructions (UnaryOp restoration)
- Create new paper-d-ssa-construction/ for SSA implementation struggles
- Add PAPER_INDEX.md consolidating ChatGPT5's 3-paper analysis

MIR14 updates:
- README.md: Add instruction evolution timeline
- abstract.md: Emphasize practical balance over pure minimalism
- main-paper*.md: Update titles and core concepts
- MIR13_CORE13_SPEC.md: Add UnaryOp to instruction list
- chapters/01-introduction.md: Reframe as "14-Instruction Balance"
- RENAME_NOTE.md: Document folder naming consideration

SSA paper structure:
- README.md: Paper overview and positioning
- current-struggles.md: Raw implementation challenges
- technical-details.md: BuilderCursor, Sealed SSA, type normalization
- abstract.md: English/Japanese abstracts

LoopForm experiments continue in parallel (minor adjustments to detection).

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-12 15:58:20 +09:00
c782286080 feat(llvm): LoopForm IR experimental scaffolding (Phase 1)
- Add NYASH_ENABLE_LOOPFORM=1 gate for experimental loop normalization
- Detect simple while-patterns in Branch terminator (header→body→header)
- Add loopform.rs with scaffold for future Signal-based lowering
- Wire detection in codegen/mod.rs (non-invasive, logs only)
- Update CURRENT_TASK.md with LoopForm experimental plan
- Goal: Centralize PHIs at dispatch blocks, simplify terminator management

This is the first step towards the LoopForm IR revolution where
"Everything is Box × Everything is Loop". Currently detection-only,
actual lowering will follow once basic patterns are validated.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-12 15:35:56 +09:00
a530b454f6 📋 Phase 15セルフホスティング戦略整理 & LLVM改善
## Phase 15戦略整理
- セルフホスティング戦略2025年9月版を作成
- Phase 15.2-15.5の段階的実装計画を明確化
  - 15.2: LLVM独立化(nyash-llvm-compiler crate)
  - 15.3: Nyashコンパイラ実装でセルフホスト達成
  - 15.4: VM層のNyash化(革新的アプローチ)
  - 15.5: ABI移行(LLVM完成後)
- ROADMAP.mdの優先順位調整、README.md更新

## LLVM改善(ChatGPT5協力)
- BuilderCursor::with_block改善(状態の適切な保存/復元)
- seal_blockでの挿入位置管理を厳密化
- 前任ブロックのみ処理、重複PHI incoming防止
- defined_in_blockトラッキングで値のスコープ管理

## 洞察
- コンパイル不要のセルフホスティング実現可能
- VM層をNyashで書けば即座実行可能
- Phase 22(Nyash LLVMコンパイラ)への道筋

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-12 14:59:03 +09:00
f307c4f7b1 🔧 LLVM: Compare/PHI値欠落への防御的対策強化
## 主な変更点
- arith.rs: Compare演算でlhs/rhs欠落時にguessed_zero()でフォールバック
- flow.rs: seal_block()でPHI入力値の欠落時により賢明なゼロ生成
- mod.rs: 各ブロックで定義された値のみをスナップショット(defined_in_block)
- strings.rs: 文字列生成をエントリブロックにホイスト(dominance保証)

## 防御的プログラミング
- 値が見つからない場合は型情報に基づいてゼロ値を生成
- パラメータは全パスを支配するため信頼
- 各ブロックごとに定義された値のみを次ブロックに引き継ぎ

ChatGPT5の実戦的フィードバックを反映した堅牢性向上。

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-12 14:34:13 +09:00
53a869136f 📚 ABI統合ドキュメント整理 & LLVM BuilderCursor改善
## ABI関連
- docs/reference/abi/ABI_INDEX.md 作成(統合インデックス)
- 分散していたABI/TypeBoxドキュメントへのリンク集約
- CLAUDE.mdに「ABI統合インデックス」リンク追加
- ABI移行タイミング詳細検討(LLVM完成後のPhase 15.5推奨)

## LLVM改善(ChatGPT5協力)
- BuilderCursor導入でposition管理を構造化
- emit_return/jump/branchをcursor経由に統一
- PHI/terminator問題への対策改善
- より明確なbasic block位置管理

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-12 14:12:54 +09:00
696b282ae8 🔍 Add extensive LLVM debug logging and builder position tracking
ChatGPT5's investigation revealed builder position management issues:
- Added verbose logging for block lowering and terminator emission
- Enhanced position_at_end calls before all terminator operations
- Added debug output for emit_jump/emit_branch operations
- Improved snapshot vs vmap fallback reporting in seal_block

Key findings:
- Sealed SSA snapshot mechanism is working correctly
- Block terminator issues persist due to builder position drift
- Main.has_in_stack/2 shows terminator missing after emit

Next steps:
- Add immediate terminator verification after each emit
- Track builder position changes in complex operations
- Investigate specific functions where builder drift occurs

This commit adds diagnostic infrastructure to pinpoint
where LLVM IR builder position gets misaligned.
2025-09-12 13:20:59 +09:00
fc18a925fd 🛡️ Add terminator safety guard for LLVM blocks
Added extra safety check after block lowering:
- Check if LLVM basic block still lacks terminator
- Insert conservative jump to next block (or entry if last)
- This prevents 'Basic Block does not have terminator' errors

Also updated CURRENT_TASK.md with:
- Reproduction steps for esc_json/1 PHI issue
- Sealed ON/OFF comparison commands
- Root cause hypothesis: vmap snapshot timing issue
- Next steps for block_end_values implementation

Current blocker analysis:
- Sealed OFF: PHI incoming count mismatch
- Sealed ON: 'phi incoming (seal) value missing'
- Likely cause: seal_block using work vmap instead of
  end-of-block snapshot

Progress: Main.esc_json/1 terminator issue resolved,
now focusing on PHI value availability.
2025-09-12 12:38:06 +09:00
a28fcac368 🔧 Add sealed SSA mode for PHI debugging (ChatGPT5)
Added NYASH_LLVM_PHI_SEALED env var to toggle PHI wiring modes:
- NYASH_LLVM_PHI_SEALED=0 (default): immediate PHI wiring
- NYASH_LLVM_PHI_SEALED=1: sealed SSA style (wire after block completion)
- Added seal_block() function for deferred PHI incoming setup
- Enhanced PHI tracing with NYASH_LLVM_TRACE_PHI=1

This helps debug 'phi incoming value missing' errors by
comparing immediate vs sealed wiring approaches.
2025-09-12 12:30:42 +09:00
4fe1212d36 🚀 Major LLVM breakthrough by ChatGPT5\!
PHI type coercion and core-first routing fixes:
- Auto type conversion for PHI nodes (i64↔i8*↔i1↔f64)
- Fixed ArrayBox.get misrouting to Map path
- Core-first strategy for Array/Map creation
- Added comprehensive debug logging ([PHI], [ARR], [MAP])

Results:
 Array smoke test: 'Result: 3'
 Map smoke test: 'Map: v=42, size=1'

After 34+ minutes of battling Rust lifetime errors,
ChatGPT5 achieved a major breakthrough\!

Key insight: The bug wasn't in PHI/SSA logic but in
Box type routing - ArrayBox.get was incorrectly caught
by Map fallback due to missing annotations.

We're SO CLOSE to Nyash self-hosting paradise\! 🌟
Once this stabilizes, everything can be written in
simple, beautiful Nyash code instead of Rust complexity.
2025-09-12 12:07:07 +09:00
1f5ba5f829 💢 The truth about Rust + LLVM development hell
ChatGPT5 struggling for 34+ minutes with Rust lifetime/build errors...
This perfectly illustrates why we need Phase 22 (Nyash LLVM compiler)\!

Key insights:
- 'Rust is safe and beautiful' - Gemini (who never fought lifetime errors)
- Reality: 500-line error messages, 34min debug sessions, lifetime hell
- C would just work: void* compile(void* mir) { done; }
- Python would work: 100 lines with llvmlite
- ANY language with C ABI would work\!

The frustration is real:
- We're SO CLOSE to Nyash self-hosting paradise
- Once bootstrapped, EVERYTHING can be written in Nyash
- No more Rust complexity, no more 5-7min builds
- Just simple, beautiful Box-based code

Current status:
- PHI/SSA hardening in progress (ChatGPT5)
- 'phi incoming value missing' in Main.esc_json/1
- Sealed SSA approach being implemented

The dream is near: Everything is Box, even the compiler\! 🌟
2025-09-12 05:48:59 +09:00
23fea9258f 🔧 Fix LLVM basic block naming collision (ChatGPT5)
- Add function name prefix to basic block labels to avoid cross-function conflicts
- blocks.rs: create_basic_blocks now takes fn_label parameter
- Format: 'Main_join_2_bb23' instead of just 'bb23'
- Add conservative fallback for missing terminators (jump to next or entry)
- This fixes 'Basic Block does not have terminator' verification error

Analysis insights:
- MIR output was correct (all blocks had terminators)
- Problem was LLVM-side block name collision between functions
- Classic case of 'Rust complexity' - simple C++ style fix works best
- Sometimes the simplest solution is the right one\!
2025-09-12 04:54:09 +09:00