Commit Graph

8 Commits

Author SHA1 Message Date
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
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
8d1e580ab4 Phase 6: Complete type conversion unification (21 sites, 33 lines)
Completed conversion_helpers.rs implementation across all handlers:
- load_as_box(): reg_load().to_nyash_box() unified
- load_args_as_boxes(): bulk conversion helper

Files updated (final):
- boxes.rs: 2 sites (-6 lines) 
- calls.rs: 5 sites (-10 lines) 
- boxes_plugin.rs: 1 site (-3 lines) 
- externals.rs: 3 sites (-4 lines) 
- boxes_array.rs: 4 sites (-4 lines) 
- boxes_map.rs: 6 sites (-6 lines) 

Total: 21 sites unified, -33 lines (manual patterns)
Helper: +137 lines (conversion_helpers.rs)
Net: +104 lines (improved maintainability)

Tests: Phase 21.0 PASS (2/2, 100%)

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-07 00:26:07 +09:00
22b668927e refactor: complete error message unification (Phase 3.5)
Migrate remaining 45 error generation patterns to unified helpers:
- calls.rs: 13 sites → 0
- extern_provider.rs: 9 sites → 0
- externals.rs: 5 sites → 0
- boxes_plugin.rs: 5 sites → 0
- boxes.rs: 5 sites → 0
- boxes_string.rs: 4 sites → 0
- boxes_instance.rs: 2 sites → 0
- mod.rs + boxes_array.rs: 2 sites → 0

Error patterns now 100% unified:
- All 80 InvalidInstruction sites use helpers (100%)
- Consistent error formatting across entire codebase
- Single source of truth for error messages

Code reduction:
- Phase 3.5: 50-70 lines saved
- Cumulative (Phase 1+2+3+3.5): 200-267 lines removed (6-8% handlers)
- Total patterns unified: 192 (destination 60 + args 52 + errors 80)

Benefits:
- 100% error message consistency achieved
- Easy to modify error formats globally
- Foundation for i18n support ready
- Improved maintainability and testability

Test results: ✓ Build successful, Phase 21.0 smoke tests passing
Related: Phase 21.0 refactoring milestone complete
Risk: Low (error messages only, behavior preserved)
2025-11-06 23:34:46 +09:00
edf4513b5a refactor: complete MIR interpreter utility migration (Phase 2)
Migrate remaining argument validation and destination write patterns
to utility helpers introduced in Phase 1.

Changes:
- boxes_map.rs: 135 → 123 lines (-12)
  * 6 arg validations → validate_args_exact()
  * 7 destination writes → write_result()

- externals.rs: 219 → 206 lines (-13)
  * 12 destination patterns unified
  * Simplified env/future/modules handling

- boxes_string.rs: 209 → 197 lines (-12)
  * 4 arg validations + 4 destinations unified
  * Methods: replace, contains, lastIndexOf, concat, etc.

- boxes_array.rs: 64 lines (3 validations migrated)
  * Methods: push, get, set

- boxes_object_fields.rs: 400 → 394 lines (-6)
  * 2 arg validations (getField, setField)

Pattern Elimination:
- Argument validation: 15 → 0 (100% eliminated)
- Destination writes: 51 → 28 (45% eliminated)

Code Reduction:
- Phase 2: 43 lines removed (1.3%)
- Cumulative: 117-154 lines removed (3.5-4.6% of handlers/)

Test Results:
- Build:  SUCCESS (no new warnings)
- MapBox:  37/37 passed
- StringBox:  30/30 passed
- ArrayBox: ⚠️ 13/14 (1 pre-existing failure)

Benefits:
- Unified error messages across all handlers
- Single source of truth for validation logic
- Easier maintenance and future refactoring
- Consistent behavior throughout codebase

Related: Phase 21.0 refactoring (DUPLICATION_ANALYSIS_REPORT.md)
Risk: Low (pure refactoring, behavior preserved)
2025-11-06 22:59:47 +09:00
8d179e9499 refactor: add MIR interpreter utility helpers (Phase 1)
- Add destination write helpers (write_box_result, write_void, write_result)
- Add argument validation helpers (validate_args_exact/range/min)
- Add receiver conversion helper (convert_to_box)
- Update handlers to use new helpers

Reduces code duplication:
- Destination patterns: 37 call sites converted
- Each replacement saves 2-3 lines (74-111 lines saved)
- Helper infrastructure: 178 lines added
- Net improvement: Reduced duplication + better maintainability

Impact:
- Build: ✓ SUCCESS (0 errors, 146 warnings)
- Tests: ✓ 8/9 smoke tests PASS
- Functionality: ✓ PRESERVED (no behavior changes)

Files created:
- src/backend/mir_interpreter/utils/mod.rs
- src/backend/mir_interpreter/utils/destination_helpers.rs
- src/backend/mir_interpreter/utils/arg_validation.rs
- src/backend/mir_interpreter/utils/receiver_helpers.rs

Files modified: 15 handler files
- arithmetic.rs, boxes.rs, boxes_array.rs, boxes_instance.rs
- boxes_map.rs, boxes_object_fields.rs, boxes_plugin.rs
- boxes_string.rs, calls.rs, extern_provider.rs, externals.rs
- memory.rs, misc.rs, mod.rs

Related: Phase 21.0 refactoring
Risk: Low (pure refactoring, no behavior change)
2025-11-06 22:50:46 +09:00
c81dc20d5c Bridge canonicalize: add PhiInst.lower_phi and LLVMConstInstructionBox.lower_const diff tests; ArrayBox.pop empty strict tag [array/empty/pop] + smoke; VM README: document [map/missing] and [array/empty/pop] tags 2025-11-02 11:47:58 +09:00
cdf826cbe7 public: publish selfhost snapshot to public repo (SSOT using + AST merge + JSON VM fixes)
- SSOT using profiles (aliases/packages via nyash.toml), AST prelude merge
- Parser/member guards; Builder pin/PHI and instance→function rewrite (dev on)
- VM refactors (handlers split) and JSON roundtrip/nested stabilization
- CURRENT_TASK.md updated with scope and acceptance criteria

Notes: dev-only guards remain togglable via env; no default behavior changes for prod.
2025-09-26 14:34:42 +09:00