Commit Graph

2262 Commits

Author SHA1 Message Date
1154aeb40a docs: Phase 138 - ReturnValueLowererBox SSOT documentation
Phase 138 Documentation:
- Created docs/development/current/main/phases/phase-138/README.md
- Goal: Extract return lowering to shared Box for SSOT
- SSOT: common/return_value_lowerer_box.rs
- Supported: Variable, Integer literal, Add expression (x + 2, 5 + 3)
- Implementation: New files, modified files, call sites
- Tests: 5 unit tests + all regressions PASS
- Architecture Impact: Code reduction, maintainability, testability
- Phase 139 準備: Next step clearly indicated (post_if_post_k.rs unification)

10-Now.md Updates:
- Added Phase 138 entry (ReturnValueLowererBox SSOT)
- Implementation details and test coverage
- Design decision: Phase 138 P0 migrated loop paths only
- Link to Phase 138 README

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-19 00:56:02 +09:00
95daf230c4 refactor(normalized_shadow): Phase 138 - extract ReturnValueLowererBox (no behavior change)
Extract return value lowering logic to shared Box for SSOT:

New Files:
- common/return_value_lowerer_box.rs (~300 lines)
  - ReturnValueLowererBox::lower_to_value_id()
  - Supports: Variable, Integer literal, Add expression
  - 5 comprehensive unit tests
- common/mod.rs (module export)

Modified Files:
- loop_true_break_once.rs
  - Removed lower_return_value_to_vid() method (~115 lines)
  - Added import: use super::common::return_value_lowerer_box::ReturnValueLowererBox
  - Updated 2 call sites (post_k, k_exit)
  - Updated SSOT documentation
- mod.rs
  - Added pub mod common;

Code Reduction: ~115 lines removed from loop_true_break_once.rs

Tests:
- cargo test --lib: 1194 tests PASS (+5 new unit tests)
- Phase 137 regression: 6/6 PASS
- Phase 97 regression: 2/2 PASS
- Phase 131/135/136 regression: 3/3 PASS

Behavior: Unchanged (all Phase 136/137 fixtures/smokes PASS)

SSOT: common/return_value_lowerer_box.rs

Next: Phase 139 P0 - Migrate post_if_post_k.rs to ReturnValueLowererBox

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-19 00:55:51 +09:00
962d1803c9 docs: Phase 136/137 - return literal and add expression documentation
Phase 136 Documentation:
- Created docs/development/current/main/phases/phase-136/README.md
- Goal: loop(true) break-once with return literal (Integer)
- Supported: return 7, loop + post + return literal
- Implementation: lower_return_value_to_vid() method
- Tests: 2 fixtures + 4 smokes
- VM/LLVM EXE parity verification commands

Phase 137 Documentation:
- Created docs/development/current/main/phases/phase-137/README.md
- Goal: loop(true) break-once with return add expression
- Supported: return x+2, return 5+3, loop+post+return add
- Implementation: Extended lower_return_value_to_vid() for BinaryOp Add
- Return Value Lowering SSOT documented (lines 29-46)
- Boxification trigger: when 2+ files need identical logic
- Tests: 3 fixtures + 6 smokes
- VM/LLVM EXE parity verification commands

10-Now.md Updates:
- Added Phase 136 entry (return literal)
- Added Phase 137 entry (return add expression)
- Implementation details and test coverage
- Links to phase READMEs

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-19 00:16:06 +09:00
1264b3593d fix(normalization): Tighten loop(true) gate to prevent loop(i<n) mismatch
Problem:
- Phase 97 LLVM EXE tests (next_non_ws, json_loader_escape) were failing
- NormalizationPlan accepted loop(i < n) but couldn't lower it
- Execute stage returned hard error instead of fallback

Root Cause:
- Plan stage only checked `ASTNode::Loop`, not condition
- loop(i < n) got Plan → Execute tried to normalize → error
- Should: loop(i < n) returns Ok(None) → fallback to Pattern2

Fix:
- Tighten gate in plan_box.rs (lines 50-71)
- Only accept loop(true) - literal Bool true
- loop(i < n) now returns Ok(None) → clean fallback

Added:
- Test: test_plan_block_suffix_no_match_loop_not_true()
- Verifies loop(i < n) returns None (not Plan)

Verification:
- Phase 97 next_non_ws LLVM EXE: PASS
- Phase 97 json_loader_escape LLVM EXE: PASS
- Phase 131/135/136/137 regression: all PASS

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-19 00:15:51 +09:00
ff09adebe0 feat(control_tree): Phase 136/137 - return literal and add expression (dev-only)
Phase 136 P0: Return literal (Integer) support
- Extend loop(true) break-once to support `return 7`
- Fixtures: phase136_loop_true_break_once_return_literal_min.hako (exit code 7)
- VM/LLVM EXE parity achieved

Phase 137 P0: Return add expression support
- Extend to support `return x + 2` and `return 5 + 3`
- LHS: Variable or Integer literal
- RHS: Integer literal only
- Fixtures:
  - phase137_loop_true_break_once_return_add_min.hako (exit code 3)
  - phase137_loop_true_break_once_return_add_const_min.hako (exit code 8)
  - phase137_loop_true_break_once_post_return_add_min.hako (exit code 13)
- VM/LLVM EXE parity achieved

Implementation:
- Added lower_return_value_to_vid() method in loop_true_break_once.rs
- Replaced extract_variable_name() with unified return value lowering
- Supported patterns: Variable, Integer literal, BinaryOp Add
- Out-of-scope patterns return Ok(None) for fallback
- SSOT documentation added (lines 29-46)

Tests: 5 fixtures + 10 smoke tests (5 VM + 5 LLVM EXE), all PASS

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-19 00:15:32 +09:00
91c7dfbf0b refactor(normalization): Phase 135 P0 - Extend plan to zero post-loop assigns
Generalize NormalizationPlan suffix detection to accept zero post-loop assignments:

Goal: Improve entry point consistency by allowing `loop + assign* + return` (N >= 0)

Implementation:
- Modified plan_box.rs detection logic (only file changed)
- Removed `post_assign_count >= 1` requirement
- Unified Phase 131 (loop + return) and Phase 132-133 (loop + assign+ + return) paths

Changes:
- src/mir/builder/control_flow/normalization/plan_box.rs:
  - Removed assignment count constraint
  - Unified pattern detection: `loop + assign* + return` (N >= 0)
- apps/tests/phase135_loop_true_break_once_post_empty_return_min.hako (new fixture)
- tools/smokes/v2/profiles/integration/apps/phase135_*.sh (new smoke tests)

Pattern support:
- Phase 131/135: loop + return only (consumed: 2, post_assign_count: 0) 
- Phase 132: loop + 1 assign + return (consumed: 3, post_assign_count: 1) 
- Phase 133: loop + N assigns + return (consumed: 2+N, post_assign_count: N) 

Design principles maintained:
- **Minimal change**: Only plan_box.rs modified (execute_box unchanged)
- **SSOT**: Detection logic centralized in plan_box.rs
- **Box-First**: Responsibility separation preserved (Plan/Execute)

Test results:
- Unit tests (plan_box): 9/9 PASS (2 new tests added)
- Phase 135 VM/LLVM EXE: PASS (exit code 1)
- Phase 131 regression: 2/2 PASS (path now unified)
- Phase 133 regression: 2/2 PASS
- cargo test --lib: PASS

Benefits:
- Unified entry point for all loop + post patterns
- Easier maintenance (single detection logic)
- Future extensibility (easy to add new patterns)
- Clear separation of Phase 131 and Phase 132-135 paths

Default behavior unchanged: Dev-only guard maintained

Related: Phase 135 normalization pattern consistency improvement

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-18 22:46:32 +09:00
f4ab5ca5f4 refactor(control_flow): Phase 134 P0 - Normalization entry point SSOT
Consolidate dual entry points into unified NormalizationPlan system:

Problem:
- Dual entry points: try_normalized_shadow() + suffix_router_box
- ~220 lines of duplicated pattern detection logic
- Maintenance burden: changes required in two places

Solution:
- New normalization module with Box-First architecture
- NormalizationPlanBox: Single source of truth for pattern detection
- NormalizationExecuteBox: Single source of truth for execution

Implementation:
- src/mir/builder/control_flow/normalization/ (new module)
  - README.md: Design contract (SSOT)
  - plan.rs: NormalizationPlan data structure
  - plan_box.rs: Pattern detection (7 unit tests)
  - execute_box.rs: Execution logic
  - mod.rs: Module integration

Refactored files:
- routing.rs::try_normalized_shadow(): 165 → 87 lines (-78 lines)
- suffix_router_box::try_lower_loop_suffix(): 258 → 116 lines (-142 lines)

Pattern support maintained:
- Phase 131: loop(true) only (consumed: 1)
- Phase 132: loop + single post (consumed: 3)
- Phase 133: loop + multiple post (consumed: 2+N)

Box-First principles:
- Plan Box: Detection responsibility only
- Execute Box: Execution responsibility only
- README.md: Contract documentation (SSOT)
- Clear separation enables independent testing

Test results:
- cargo test --lib: 1186 PASS (10 new tests added)
- Phase 133 VM/LLVM EXE: PASS (exit code 6)
- Phase 132 LLVM EXE: PASS (exit code 3)
- Phase 131 LLVM EXE: PASS (exit code 1)

Benefits:
- Code duplication eliminated (~220 lines)
- Single source of truth for normalization decisions
- Improved maintainability and testability
- Future-proof extensibility (easy to add new patterns)

Default behavior unchanged: Dev-only guard maintained

Related: Phase 134 normalization infrastructure improvement

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-18 22:29:29 +09:00
ef71ea955c feat(control_tree): Phase 133 P0 - Multiple post-loop assigns support
Extend Phase 132's loop(true) + post-loop to accept multiple assignments:

Goal: `x=0; loop(true){ x=1; break }; x=x+2; x=x+3; return x` → exit code 6

Implementation:
- Extended loop_true_break_once.rs pattern detection (len() == 2 → len() >= 2)
- Added iterative assignment lowering (for loop over post_nodes)
- Reused Phase 130's lower_assign_stmt for each assignment
- Maintained ExitMeta DirectValue mode (PHI-free)

Changes:
- apps/tests/phase133_loop_true_break_once_post_multi_add_min.hako (new fixture)
- tools/smokes/v2/profiles/integration/apps/phase133_*_multi_add_*.sh (new smokes)
- src/mir/control_tree/normalized_shadow/loop_true_break_once.rs (+30 lines)
- docs/development/current/main/phases/phase-133/README.md (new documentation)
- docs/development/current/main/10-Now.md (Phase 133 entry added)

Scope (Phase 130 baseline):
-  x = <int literal>
-  x = y (variable copy)
-  x = x + <int literal> (increment)
-  Function calls / general expressions (future phases)

Design principles:
- Minimal change: ~30 lines added
- SSOT preservation: env_post_k remains single source of truth
- Reuse: Leveraged existing lower_assign_stmt
- Fail-Fast: Contract violations trigger freeze_with_hint

Test results:
- cargo test --lib: 1176 PASS
- Phase 133 VM: PASS (exit code 6)
- Phase 133 LLVM EXE: PASS (exit code 6)
- Phase 132 regression: PASS (exit code 3)
- Phase 131 regression: PASS (exit code 1)
- Phase 97 regression: PASS

Architecture maintained:
- 5-function structure unchanged (main/loop_step/loop_body/k_exit/post_k)
- PHI-free DirectValue mode
- Zero changes to ExitMeta, merge logic, or JoinIR contracts

Related: Phase 133 loop(true) + multiple post-loop assignments

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-18 22:11:08 +09:00
9fb35bbc05 docs: Phase 132 DONE - loop(true) + post-loop complete
Update documentation to mark Phase 132 as complete:

**10-Now.md**:
- Add Phase 132 completion entry (P0/P0.5/P1/R0)
- Document what was solved:
  - loop(true) + post VM/LLVM EXE parity (exit code 3)
  - Continuation contracts SSOT化
  - merge が by-name 推測禁止
- Entry link: docs/development/current/main/phases/phase-132/README.md

**phase-132/README.md**:
- Update Status: IN PROGRESS → DONE 
- Add Current Status section with P0/P0.5/P1/R0 completion details
- Document SSOT achievements:
  - JoinInlineBoundary::default_continuations()
  - src/mir/builder/control_flow/joinir/merge/README.md (merge contracts)
  - src/mir/builder/control_flow/joinir/legacy/README.md (removal conditions)
- Test placement: continuation_contract.rs
- Test results: All Phase 131/132/97 smokes PASS

Phase 132 Summary:
- P0: post_k generation (loop_true_break_once.rs extension)
- P0.5: Suffix router for StepTree (post statements visibility fix)
- P1: k_exit continuation classification fix (structural check)
- R0: Infrastructure refactoring (SSOT + legacy isolation + docs)

Key achievements:
- VM/LLVM EXE parity for loop(true) + post-loop
- Continuation contracts SSOT and documented
- Legacy code path isolated for future removal
- Code quality improved (warnings reduced)

Related: Phase 132 loop(true) + post-loop complete implementation

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-18 21:53:54 +09:00
d5a36cf818 refactor(joinir): Phase 132-R0 - Continuation SSOT + legacy isolation
**Task 1: Continuation SSOT 一本化** 
- Add JoinInlineBoundary::default_continuations()
- Replace all BTreeSet::from([JoinFuncId::new(2)]) hardcoding (7 locations)
- Single source of truth for continuation function IDs

**Task 2: merge 契約 docs SSOT 化** 
- New: src/mir/builder/control_flow/joinir/merge/README.md
- Document continuation contracts, skip conditions, forbidden behaviors
- Prohibit by-name/by-id classification

**Task 3: テスト配置正規化** 
- New: src/mir/builder/control_flow/joinir/merge/tests/continuation_contract.rs
- Move tests from instruction_rewriter.rs to dedicated test file
- Add 4 test cases (Case A-D)

**Task 4: legacy 導線隔離** 
- New: src/mir/builder/control_flow/joinir/legacy/
- Move routing_legacy_binding.rs → legacy/routing_legacy_binding.rs
- Add legacy/README.md with removal conditions
- No cfg(feature="legacy") (docs-only isolation for now)

**Task 5: ノイズ除去** 
- Remove unused imports (ConstValue, MirInstruction)
- Clean warnings in touched files

Changes:
- src/mir/join_ir/lowering/inline_boundary.rs: +default_continuations()
- src/mir/builder/control_flow/joinir/merge/README.md: +140 lines
- src/mir/builder/control_flow/joinir/merge/tests/: +180 lines
- src/mir/builder/control_flow/joinir/legacy/: +3 files

Test results:
- cargo test --lib: 1176 PASS
- All Phase 131/132/97 smokes: PASS

Benefits:
- Continuation definition centralized (SSOT)
- Merge contracts documented and tested
- Legacy code path clearly isolated
- Code quality improved (warnings reduced)

Related: Phase 132 infrastructure improvements

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-18 21:52:21 +09:00
149e30cae5 fix(joinir): Phase 132 P1 - k_exit continuation classification fix
Problem: k_exit with TailCall(post_k) was classified as skippable continuation,
causing post_k block to become unreachable.

Root cause:
- Continuation classification was name-based ("join_func_2")
- Skippable continuation check didn't examine function body
- k_exit with tail call to post_k had its block skipped during merge

Solution:
- Check function body structure before classifying as skippable
- Non-skippable pattern: continuation with TailCall to another function
- Properly emit tail call as Jump instruction

Changes:
- src/mir/builder/control_flow/joinir/merge/mod.rs:
  - Add structural check in is_skippable_continuation()
  - Detect TailCall(other_func) pattern
  - Skip only if function is truly empty (1 block, Return only)

- src/mir/builder/control_flow/joinir/merge/instruction_rewriter.rs:
  - Improve k_exit continuation handling
  - Properly rewrite TailCall → Jump for post_k

Test results:
- Phase 132 LLVM EXE: PASS (exit code 3)
- Phase 132 VM: PASS
- Phase 131 regression: PASS
- Phase 97 regression: PASS

Related: Phase 132 loop(true) + post-loop VM/LLVM parity

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-18 21:51:52 +09:00
b5d8ace6ab feat(control_tree): Phase 132 P0 + P0.5 - loop(true) + post-loop support
**Phase 132 P0**: Extend loop(true) break-once to support post-loop statements

Goal: Support `loop(true) { x = 1; break }; x = x + 2; return x` → exit code 3

Implementation:
- loop_true_break_once.rs: Add post_k continuation generation
- Reuse Phase 130's lower_assign_stmt for post statements
- ExitMeta uses DirectValue mode (PHI-free)

**Phase 132 P0.5**: Fix StepTree post-loop statement visibility

Root cause: routing.rs created StepTree from Loop node only, losing post statements

Solution:
- New: normalized_shadow_suffix_router_box.rs
- Detects block suffix: Loop + Assign* + Return
- Creates StepTree from entire suffix (Block([Loop, Assign, Return]))
- Modified build_block() to call suffix router (dev-only)

Changes:
- apps/tests/phase132_loop_true_break_once_post_add_min.hako (new fixture)
- tools/smokes/v2/profiles/integration/apps/phase132_loop_true_break_once_post_add_*.sh
- src/mir/control_tree/normalized_shadow/loop_true_break_once.rs (+150 lines)
- src/mir/builder/control_flow/joinir/patterns/policies/normalized_shadow_suffix_router_box.rs (+380 lines)
- src/mir/builder/stmts.rs (build_block modified to support suffix skipping)

Design principles:
- StepTree unchanged: Block is SSOT for statement order
- No data duplication: Loop doesn't hold post_nodes
- Suffix router handles detection + conversion
- build_block() handles wiring only

Test results:
- Phase 132 VM: PASS (exit code 3)
- Phase 131 regression: PASS
- Phase 97 regression: PASS

Related: Phase 132 loop(true) + post-loop minimal support

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-18 21:51:33 +09:00
4169da8c33 docs: Phase 131 refactoring tasks 1-7 completion
Update documentation with refactoring results:

**phase-131/README.md**:
- Document all 7 refactoring tasks (1: MergeContracts, 2: instruction_rewriter boxification,
  3-4: OutputContract + require_joinir_dev, 5: env.sh SSOT, 6: MergeConfig, 7: contract_checks tests)
- Add task descriptions and success criteria
- Document benefits and test results
- Reference implementation files and commits

**tools/build_llvm.sh**:
- Use TARGET_TMPDIR from env.sh for TMPDIR configuration
- Improve EXDEV mitigation for WSL compatibility
- Better artifact finalization handling

**Summary of Phase 131 Refactoring**:

7 refactoring tasks completed on schedule:
 Task 1 (MergeContracts): +30 lines, SSOT for merge contracts
 Task 2 (instruction_rewriter): +212 lines (policy box), -50 lines (rewriter)
 Task 3 (OutputContract): +90 lines, unified verification interface
 Task 4 (require_joinir_dev): +14 lines, dev-only helper
 Task 5 (env.sh SSOT): +1014 lines, centralized environment
 Task 6 (MergeConfig): +54 lines, unified configuration
 Task 7 (contract_checks tests): +116 lines, 4 new tests

Total: ~2500 new lines, 0 regressions, all tests PASS

Benefits:
- Code organization: Single responsibility principle
- Maintainability: SSOT reduces duplication
- Testability: Policy boxes and unit tests enable regression detection
- Developer experience: Clearer code, better documentation

Related: Phase 131 P1.5-P2 DirectValue exit reconnection + infrastructure improvement

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

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2025-12-18 18:29:02 +09:00
f42fcd33b4 refactor(joinir,smokes): Task 2,3,4 - instruction_rewriter boxification + OutputContract unification
Task 2: instruction_rewriter 分箱化
- Extract k_exit special case logic into TailCallLoweringPolicyBox
- Separate detect/collect/transform concerns into dedicated policy box
- Rewriter becomes pure transformation engine
- Added 5 unit tests for exit edge normalization
- New file: src/mir/builder/control_flow/joinir/merge/tail_call_lowering_policy.rs (212 lines)

Changes:
- instruction_rewriter.rs: Delegate k_exit detection to policy box (-50 lines)
- merge_result.rs: Add MirMergeResult struct for intermediate results
- Single responsibility principle: each box handles one concern

Task 3 & 4: smokes runner 改善
- Unify exit_code and numeric output verification into check_output_contract()
- Add require_joinir_dev() helper for dev-only fixture setup
- Reduce boilerplate in phase131_loop_true_break_once_*.sh scripts
- Consistent error message format across verification types

Changes:
- tools/smokes/v2/lib/llvm_exe_runner.sh: Add OutputContract interface (+90 lines)
- tools/smokes/v2/lib/test_runner.sh: Add require_joinir_dev() helper
- Phase 131 smoke scripts: Use new helpers (cleaner, less repetition)
- Build script: Improve TMPDIR configuration for EXDEV mitigation

Benefits:
- Single responsibility: policy box handles one concern
- Code reuse: OutputContract eliminates duplication
- Clarity: Smoke scripts are more concise and readable
- Maintainability: Easier to add new verification types

Test Results:
- Policy box unit tests: 5 PASS
- Smoke tests: 2/2 PASS
- No regression in existing functionality

Related: Phase 131 refactoring for improved code organization

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

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2025-12-18 18:28:50 +09:00
0ef032ccc8 refactor(smokes): Task 5 - Environment variable SSOT centralization
Create single source of truth for smoke test environment configuration:

**tools/smokes/v2/lib/env.sh** (new, 183 lines):
- Centralize 16 environment variables across 6 categories
- JoinIR development (NYASH_JOINIR_DEV, HAKO_JOINIR_STRICT)
- LLVM features (NYASH_LLVM_USE_HARNESS, NYASH_LLVM_BACKEND, etc.)
- Tmpdir EXDEV mitigation (TARGET_TMPDIR)
- Plugin loader strategy (NYASH_LOAD_NY_PLUGINS, NYASH_DISABLE_PLUGINS)
- Parser features (NYASH_FEATURES, using system variables)
- Debug features (NYASH_CLI_VERBOSE, etc.)

**Mode Presets**:
- dev: Verbose logging, unlimited fuel, JoinIR dev enabled
- integration: Moderate settings, JoinIR dev enabled
- quick: Minimal logging, fast execution

**Helper Functions**:
- setup_smoke_env [mode]: Configure environment for test profiles
- validate_env_setup: Validate configuration
- show_smoke_env: Display current configuration

**Documentation**:
- ENV_README.md: Comprehensive usage guide
- ENV_QUICK_START.md: Quick reference for script authors
- p1.5-task5-env-ssot.md: Implementation details and testing

Benefits:
- SSOT: Single file for all environment variables
- Sparrow prevention: No duplicate settings
- Clarity: Well-documented configuration
- Backward compatibility: Existing scripts work unchanged

Test Results:
- All environment presets work correctly
- Phase 131 smoke tests PASS
- Syntax validation for all shell files PASS

Related: Phase 131 smoke test infrastructure improvement

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

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2025-12-18 18:28:37 +09:00
d6225a88d0 refactor(joinir): Task 6 & 7 - MergeConfig unification + contract_checks tests
Task 6: MergeConfig 一構造体化
- Consolidate dispersed parameters (dev_log, strict_mode, exit_reconnect_mode)
- Reduce function argument clutter in merge/mod.rs
- Single source of truth for merge configuration
- Added MergeConfig struct with factory methods (default, strict, with_debug)

Task 7: contract_checks 単体テスト追加
- Add 4 test cases for verify_all_terminator_targets_exist
- Test coverage: all_present, missing_allowed, missing_disallowed, MergeContracts creation
- Validate fail-fast behavior with freeze_with_hint
- Enable regression detection during future refactoring

Changes:
- src/mir/builder/control_flow/joinir/merge/mod.rs (+54 -6 lines)
- src/mir/builder/control_flow/joinir/merge/contract_checks.rs (+116 lines)

Test Results:
- New tests: 4 PASS
- Regression tests: 1162 PASS
- No breaking changes

Related: Phase 131 refactoring to improve code organization and maintainability

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

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2025-12-18 18:28:24 +09:00
f775c0fe01 docs: Phase 131 P2 DirectValue exit reconnection complete
Update completion status for Phase 131 P2:
- CURRENT_TASK.md: Note WSL restart resolved EXDEV issue
- 10-Now.md: Add Phase 131 P2 completion entry
- phase-131/README.md: Document P1.5 and P2 deliverables

Phase 131 Status: DONE 
- loop(true) break-once executes correctly
- Exit values propagate through DirectValue mode
- VM + LLVM EXE parity verified

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-18 17:48:18 +09:00
02c4c313e5 feat(control_tree): Phase 131 P1.5-P2 DirectValue exit reconnection
Implement DirectValue mode for Normalized shadow exit handling:

**P1.5 Changes**:
- Add ExitReconnectMode::DirectValue (skip exit PHI generation)
- Carry remapped_exit_values through merge result
- Update host variable_map directly with exit values
- Fix loop(true) { x = 1; break }; return x to return 1 correctly

**P2 Changes**:
- Normalize k_exit continuation entry/exit edges
- Rewrite TailCall(k_exit) → Jump(exit_block) for proper merge
- Add verify_all_terminator_targets_exist contract check
- Extend ExitLineReconnector to handle DirectValue mode

**Infrastructure**:
- tools/build_llvm.sh: Force TMPDIR under target/ (EXDEV mitigation)
- llvm_exe_runner.sh: Add exit_code verification support
- Phase 131 smokes: Update for dev-only + exit code validation

**Contracts**:
- PHI-free: Normalized path uses continuations only
- Exit values reconnect via remapped ValueIds
- Existing patterns unaffected (既定挙動不変)

Related: Phase 131 loop(true) break-once Normalized support

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-18 17:48:05 +09:00
bfac188732 docs: Phase 131 P1.5 DirectValue exit reconnection design
Add design documents for Phase 131 P1.5 DirectValue mode:
- Root cause analysis of PHI-based exit merge assumptions
- Option B (DirectValue) analysis and trade-offs
- Implementation guide for exit value reconnection

Also add exit_reconnector.rs module stub for future extraction.

Related:
- Phase 131: loop(true) break-once Normalized support
- Normalized shadow path uses continuations, not PHI
- Exit values reconnect directly to host variable_map

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-18 17:47:45 +09:00
bd39e09c5d docs: Phase 131 P0 structure implementation complete
Document Phase 131 P0 Normalized loop(true) break-once:

**Documentation**:
- docs/development/current/main/phases/phase-131/README.md (234 lines)
  - Goal: loop(true) { <assign>* ; break } in Normalized (PHI-free)
  - Scope: one-time execution loop only
  - Contract: Bool(true) literal + break at end
  - SSOT: EnvLayout, loop structure contract, VM+LLVM parity
  - Current status: structure implemented, execution wiring pending
- docs/development/current/main/10-Now.md
  - Updated Next section with Phase 131 P0 status

**Deliverables** (P0):
-  Complete loop(true) break-once Normalized lowering logic
-  PHI-free implementation (env + continuations)
-  Box-First modular design
-  Foundation for execution (structure verified)
-  Unit tests passing (1155/1155)

**Known Limitation**:
- Execution path not yet wired (dev-only observation mode)
- Follow-up phase needed to route execution through Normalized shadow
- VM/LLVM smokes fail (expected until execution wiring)

**Next Steps**:
1. Modify try_cf_loop_joinir to check Normalized shadow first
2. Add dev-mode routing for loop(true) break-once
3. Implement JoinModule → MIR merge for loop patterns
4. Enable VM/LLVM smoke tests

Related: Phase 131 P0 - loop(true) break-once Normalized structure
2025-12-18 09:36:50 +09:00
b531a64d67 feat(control_tree): Phase 131 normalized loop(true) break-once builder (dev-only)
Implement Normalized shadow builder for loop(true) break-once pattern:

**New Module** (407 lines):
- src/mir/control_tree/normalized_shadow/loop_true_break_once.rs
  - LoopTrueBreakOnceBuilderBox: loop(true) { <assign>* ; break } lowering
  - PHI-free: env parameters + continuation-passing style
  - Generated structure: main → loop_step → loop_body → k_exit
  - Scope: Bool(true) literal condition only, break at end only

**Integration**:
- src/mir/control_tree/normalized_shadow/builder.rs
  - Added lower_with_loop_support() for loop patterns
  - try_lower_if_only() now falls through to loop support on capability reject
- src/mir/control_tree/normalized_shadow/mod.rs
  - Module declaration added

**Contract**:
- Accepted: loop(true) { <assign of int literal/var/add>* ; break }
- Rejected (Ok(None)): continue, return in body, nested control flow
- Out of scope: general loop conditions, complex post-loop statements

**Limitations**:
- Structure-only (dev-only observation mode)
- Execution path not yet wired (follow-up phase required)
- Shadow JoinModule generation working, structural verification passing
- Unit tests: 1155/1155 PASS

Related: Phase 131 P0
2025-12-18 09:36:38 +09:00
38d3c98822 test(joinir): Phase 131 loop(true) break-once fixture + VM/LLVM smokes
Add minimal fixture and smoke tests for loop(true) break-once pattern:

**Fixture**:
- apps/tests/phase131_loop_true_break_once_min.hako
  - Pattern: x=0; loop(true) { x=1; break }; return x
  - Expected: return value 1 (exit code 1)

**Smokes**:
- tools/smokes/v2/profiles/integration/apps/phase131_loop_true_break_once_vm.sh
  - VM backend test with dev-only flags
- tools/smokes/v2/profiles/integration/apps/phase131_loop_true_break_once_llvm_exe.sh
  - LLVM EXE backend test with plugin gating

**Note**: Smokes currently fail (execution path not yet wired).
Structure implementation only - follow-up phase will wire execution.

Related: Phase 131 P0 (Normalized shadow structure)
2025-12-18 09:36:25 +09:00
353b8022af docs: clarify Phase 130 LLVM EXE smoke gating 2025-12-18 09:22:15 +09:00
46a623fd75 fix(llvm): make LLVM EXE smokes use workspace target and reliable build_llvm 2025-12-18 09:22:11 +09:00
4a109eb6b9 test(smokes): make LLVM EXE runner skip when object emit unavailable 2025-12-18 09:13:23 +09:00
b5d628d8bf docs: Phase 130 DONE (if-only normalized small expr/assign) 2025-12-18 09:13:19 +09:00
1afbb17529 test(joinir): Phase 130 post-if add fixture + smokes 2025-12-18 09:13:13 +09:00
15c2eda1cf feat(control_tree): Phase 130 assign var/add in if-only normalized 2025-12-18 09:13:08 +09:00
05fccce09a docs: add Phase 130 plan and set Now to Phase 130 2025-12-18 08:36:38 +09:00
80df1cccd4 feat(control_tree): Phase 129-C post-if via post_k continuation 2025-12-18 08:33:56 +09:00
b2af9fb297 docs: update normalized_shadow references and Phase 129 status 2025-12-18 08:18:20 +09:00
df23a52916 refactor(control_tree): modularize normalized_shadow dev pipeline 2025-12-18 08:14:49 +09:00
36717cad4f docs: update Now/INDEX for Phase 129-B join_k as-last 2025-12-18 07:54:16 +09:00
e0cbeb9aa0 feat(control_tree): Phase 129-B join_k as-last lowering 2025-12-18 07:53:27 +09:00
f0a03d20d0 test(joinir): Phase 129 join_k as-last fixture + VM smoke 2025-12-18 07:53:27 +09:00
088122df71 docs: update Now/INDEX for Phase 127 DONE and Phase 129 next 2025-12-18 07:28:30 +09:00
b822355431 docs: Phase 129 progress report (P0-P3 complete)
## Completed 

P0: LLVM EXE smoke test for Phase 128
- VM+LLVM parity verified
- Regression tests pass (phase103, phase118, phase128)

P2: Post-if return var fixture + VM smoke
- phase129_if_only_post_if_return_var_min.hako
- Tests join_k env merge pattern
- Currently passes via fallback (non-Normalized)

P3: Documentation complete
- README.md: Goal, design, scope
- P1-implementation-plan.md: Detailed refactoring plan
- PROGRESS.md: This report

## In Progress 🔄

P1: Materialize join_k continuation
- Status: Analysis complete, awaiting user decision
- Options:
  - A: In-place (fast, risky)
  - B: Phased (recommended, safe)

## Test Results 

- cargo test --lib: 1165 passed
- phase128 VM: PASS
- phase128 LLVM EXE: PASS
- phase129 VM: PASS (fallback path)
- Regression: ALL PASS

## Feedback

Box-First:
- JoinKBuilder module proposed (join_k generation)
- EnvBuilder future consideration

Fail-Fast:
- verify_normalized_structure proposed
- verify_branch_is_return_literal too restrictive

Legacy:
- Phase 123-124 lower_if_node incomplete
- Placeholder logic in lhs_vid resolution

## Next Steps

Awaiting user/ChatGPT decision on Option A vs B
2025-12-18 07:20:46 +09:00
0d2eafd780 docs: Phase 129 P1 implementation plan (join_k materialization)
Detailed analysis of current state and required changes:

Current Issues:
- lower_if_node only processes then branch (incomplete)
- No join_k function generation
- verify_branch_is_return_literal too restrictive
- No env merging logic

Required Changes:
- Create JoinKBuilder helper (Box-First)
- Generate join_k as real JoinFunction
- then/else tail-call join_k with env
- Process post-if statements in join_k body
- Add verify_normalized_structure checks

Implementation Options:
- Option A: In-place modification (risky, fast)
- Option B: Phased approach (recommended, safe)

Recommended: Option B (3-phase rollout)
- Phase 129-A: JoinKBuilder foundation
- Phase 129-B: Branch lowering to join_k
- Phase 129-C: Post-if statement support

Open Questions:
1. Function ID allocation strategy
2. Post-if statement detection mechanism
3. env parameter passing representation
4. join_k naming convention

Next: User/ChatGPT decision on approach
2025-12-18 07:19:22 +09:00
083be99214 test(joinir): Phase 129 P2 - add post-if return var fixture + VM smoke
- Add phase129_if_only_post_if_return_var_min.hako
  - Pattern: x=1; if flag==1 { x=2 }; print(x)
  - Tests join_k continuation env merge

- Add phase129_if_only_post_if_return_var_vm.sh
  - Expected output: 2 (x updated in then branch)
  - Dev-only: NYASH_JOINIR_DEV=1 HAKO_JOINIR_STRICT=1

Note: Currently passes via fallback path (non-Normalized)
P1 implementation (join_k materialization) is next step
2025-12-18 07:18:00 +09:00
e7ad3d31ba test(joinir): Phase 129 P0 - add LLVM EXE smoke for Phase 128
- Add phase128_if_only_partial_assign_normalized_llvm_exe.sh
- VM+LLVM parity for if-only partial assign pattern
- Expected output: 2 (print(2) in then branch)

Regression verified:
- phase103_if_only_llvm_exe.sh: PASS
- phase118_loop_nested_if_merge_llvm_exe.sh: PASS
2025-12-18 07:15:23 +09:00
d74f77d2ed docs: Phase 128 DONE 2025-12-18 07:08:32 +09:00
daf1827c03 test(joinir): Phase 128 - add fixture + smoke test (VM)
- Fixture: phase128_if_only_partial_assign_normalized_min.hako
  - Tests basic assign lowering with if/return pattern
  - Expected output: 2 (from then branch with print)
- Smoke: phase128_if_only_partial_assign_normalized_vm.sh
  - Validates output: 2 with exit code 0
  - Dev-only: NYASH_JOINIR_DEV=1 HAKO_JOINIR_STRICT=1
- Result: PASS
2025-12-18 07:07:04 +09:00
505ce03dfc test(joinir): Phase 128 P3 - add minimal fixture for partial assign pattern
Note: Full join_k continuation implementation deferred to future phase.
Current fixture tests basic assign lowering with simplified if/return pattern.
2025-12-18 07:05:32 +09:00
c522d22daa feat(control_tree): Phase 128 - add Assign(int literal) to Normalized builder (dev-only) 2025-12-18 07:03:57 +09:00
44762a2467 refactor(control_tree): Phase 128 - add value_ast to Assign for Normalized lowering 2025-12-18 07:01:39 +09:00
85ee761858 docs: Phase 128 plan (if-only env merge) 2025-12-18 06:59:50 +09:00
9aedc19413 docs: add Phase 127 entry (planned) 2025-12-18 06:55:29 +09:00
49c2bdf2e9 docs: Phase 126 feedback report
- Box-first modularization: AvailableInputsCollectorBox (SSOT)
- All P0-P5 steps completed successfully
- Regression: 1165 tests PASS, all smokes PASS
- Next steps: Phase 127 (strict fail-fast, CapturedEnv integration)
2025-12-18 06:47:43 +09:00
b195e8bad9 docs: Phase 126 DONE (available_inputs wired)
- AvailableInputsCollectorBox: function params + CapturedEnv SSOT
- EnvLayout.inputs: reads ∩ available_inputs (deterministic)
- Reads-only inputs resolution実装完了(dev-only)
- Regression: 1165 tests PASS, Phase 121-125/118 smokes PASS
- 次: Phase 127 TBD
2025-12-18 06:46:43 +09:00
7ae424df3c test(joinir): Phase 126 assert readonly inputs actually wired
- phase125_if_only_return_readonly_input_min.hako enhanced
- Actual if-only pattern: outer_x is read-only (not in writes)
- return outer_x resolves from inputs (reads ∩ available_inputs)
- Smoke test PASS: exit code 7 (NYASH_JOINIR_DEV=1 HAKO_JOINIR_STRICT=1)
2025-12-18 06:45:56 +09:00