275fe45ba4
feat(normalization): Phase 142 P0 - Statement-level normalization
...
## Summary
Changed normalization unit from "block suffix" to "statement (loop only)"
to prevent pattern explosion.
## Changes
1. **PlanBox** (`plan_box.rs`):
- Always return `loop_only()` for any `loop(true)`, regardless of what follows
- Subsequent statements (return, assignments) handled by normal MIR lowering
- ~70 lines reduced, 7 unit tests updated
2. **build_block** (`stmts.rs`):
- Removed `break` after consumed=1 from suffix_router
- Continue processing subsequent statements normally
- Phase 142 P0 comments added
3. **Tests**:
- Fixture: `phase142_loop_stmt_only_then_return_length_min.hako`
- VM smoke: exit code 3 (s="abc" → s.length() → 3)
## Results
- ✅ Unit tests: 10/10 passed
- ✅ Phase 142 VM smoke: PASS
- ✅ Phase 131 regression: PASS
- ✅ Build: Success
## Design
- **Pattern Explosion Prevention**: Normalize only the loop (consumed=1)
- **Out-of-Scope Policy**: Always Ok(None) for fallback
- **Fail-Fast**: Only for "in-scope but broken" cases
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com >
2025-12-19 04:41:01 +09:00
3ef929df53
docs(normalization): Update README for Phase 142 P0
...
- Document statement-level normalization unit change
- Add Phase 142 P0 section to Pattern Detection
- Mark Phase 132-135 patterns as LEGACY
- Update suffix_router description
- Clarify LoopWithPost deprecation status
Phase 142 P0: Normalization unit changed from "block suffix" to "statement"
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com >
2025-12-19 04:40:35 +09:00
aaba27d311
refactor(normalization): Deprecate LoopWithPost variant
...
- Mark LoopWithPost enum variant as deprecated (Phase 142 P0)
- Add deprecation to loop_with_post() constructor function
- Document migration path to LoopOnly
- Keep for backward compatibility until full migration
Phase 142 P0: Statement-level normalization makes LoopWithPost obsolete
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com >
2025-12-19 04:39:25 +09:00
21a3c6b5d4
docs(normalization): Update suffix_router comments for Phase 142 P0
...
- Reflect that post statements are no longer required
- Document LoopOnly pattern acceptance
- Update responsibility description
Phase 142 P0: Normalization unit changed to "statement (loop only)"
2025-12-19 04:31:45 +09:00
1742f0412e
feat(normalized): Phase 141 P1.5 - external env inputs + KnownIntrinsic SSOT
...
## Task B: External env input bug fix (Priority 1)
Fix: Suffix normalization couldn't access prefix-built local variables
**Problem**: `s.length()` failed because 's' (from prefix `s = "abc"`) was
not in available_inputs during suffix normalization.
**Root cause**: `AvailableInputsCollectorBox::collect()` only collected
function params and CapturedEnv, missing `builder.variable_map`.
**Solution**: Add `prefix_variables` parameter with 3-source merge:
1. Function params (highest priority)
2. Prefix variables (medium priority - NEW)
3. CapturedEnv (lowest priority)
**Changed files**:
- src/mir/control_tree/normalized_shadow/available_inputs_collector.rs
- src/mir/builder/control_flow/normalization/execute_box.rs
- src/mir/builder/control_flow/joinir/patterns/policies/normalized_shadow_suffix_router_box.rs
- src/mir/builder/control_flow/joinir/routing.rs
- src/mir/builder/stmts.rs
- src/mir/control_tree/normalized_shadow/dev_pipeline.rs
- docs/development/current/main/design/normalized-expr-lowering.md (Available Inputs SSOT section)
**Tests**: 3 new unit tests (prefix merge, priority order)
## Task A: KnownIntrinsic SSOT化 (Priority 2)
Eliminate string literal scattered matching by centralizing to registry.
**Problem**: Adding new intrinsics required editing if/match chains with
hard-coded string literals (`if method == KnownIntrinsic::Length0.method_name()`).
**Solution**: Create `KnownIntrinsicRegistryBox` as SSOT:
- `lookup(method, arity) -> Option<KnownIntrinsic>`
- `get_spec(intrinsic) -> KnownIntrinsicSpec`
- Adding new intrinsics now requires: (1) enum variant, (2) registry entry only
**Changed files**:
- src/mir/control_tree/normalized_shadow/common/known_intrinsics.rs (NEW)
- src/mir/control_tree/normalized_shadow/common/expr_lowerer_box.rs
- src/mir/control_tree/normalized_shadow/common/expr_lowering_contract.rs (deprecated methods removed)
- src/mir/control_tree/normalized_shadow/common/mod.rs
- docs/development/current/main/design/normalized-expr-lowering.md (Known Intrinsic SSOT section)
**Impact**: ~30% code reduction in intrinsic matching logic
## Task C: Better diagnostics (Priority 3)
Add `OutOfScopeReason::IntrinsicNotWhitelisted` for precise diagnostics.
**Changed files**:
- src/mir/control_tree/normalized_shadow/common/expr_lowering_contract.rs (enum variant)
- src/mir/control_tree/normalized_shadow/common/expr_lowerer_box.rs (diagnostic logic)
## Verification
✅ Build: `cargo build --release` - PASS
✅ Phase 97 regression: next_non_ws LLVM EXE - PASS
✅ Phase 131: loop(true) break-once VM - PASS
✅ Phase 136: return literal VM - PASS
✅ Phase 137: return x+2 VM - PASS
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com >
2025-12-19 03:59:41 +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
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
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
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
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
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
15c2eda1cf
feat(control_tree): Phase 130 assign var/add in if-only normalized
2025-12-18 09:13:08 +09:00
80df1cccd4
feat(control_tree): Phase 129-C post-if via post_k continuation
2025-12-18 08:33:56 +09:00
df23a52916
refactor(control_tree): modularize normalized_shadow dev pipeline
2025-12-18 08:14:49 +09:00
e0cbeb9aa0
feat(control_tree): Phase 129-B join_k as-last lowering
2025-12-18 07:53:27 +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
72f2c1f64d
feat(joinir/dev): Phase 126 wire available_inputs into normalized builder
...
- AvailableInputsCollectorBox::collect() called in lower_function_body (dev-only)
- try_lower_if_only() signature extended (accepts available_inputs)
- EnvLayout::from_contract() now uses real available_inputs (not empty stub)
- Unit tests updated (empty BTreeMap for backward compat)
- All 23 normalized_shadow tests PASS
2025-12-18 06:45:23 +09:00
89c2915fa0
feat(control_tree): Phase 126 AvailableInputsCollectorBox
...
- Collect available_inputs from function params + CapturedEnv (SSOT)
- BTreeMap for deterministic order
- Box-first modularization with unit tests (5 tests PASS)
- Source priority: params > CapturedEnv
- No AST inference (only pre-computed sources)
2025-12-18 06:43:27 +09:00
4c98313b58
refactor(control_tree): Phase 125 P2-P4 introduce EnvLayout (writes+inputs) + Return(Variable) from inputs
...
Phase 125 P2: EnvLayout introduction
- Add EnvLayout struct (writes + inputs)
- from_contract() creates layout from StepTreeContract + available_inputs
- SSOT: inputs = reads ∩ available_inputs (deterministic order)
- No AST inference (don't capture from AST, use provided available_inputs)
Phase 125 P2: Builder env mapping
- lower_if_only_to_normalized: Use EnvLayout to create env map
- writes: Generate ValueId (as before)
- inputs: Reference ValueId from available_inputs (placeholder for P3)
- Function params: writes only (inputs come from outer scope)
Phase 125 P4: Return(Variable) resolution extended
- lower_return_value: Check env (writes + inputs)
- If found: return it (Phase 124 for writes, Phase 125 for inputs)
- If not found: Fail-Fast with structured error + hint
- Hint: "Pass as param, add to pinned capture, or define before if"
- Phase 125 errors return Ok(None) (out of scope, graceful degradation)
Unit tests:
- test_return_variable_from_env: PASS (Phase 124 regression)
- test_return_variable_out_of_scope: PASS (updated for Phase 125)
- test_return_variable_from_inputs_stub: PASS (P3 not wired yet)
- All 1160 lib tests PASS (no regression)
Note:
- P3 (available_inputs wiring) not implemented yet
- available_inputs is empty BTreeMap (stub)
- EnvLayout.inputs will be empty until P3 is wired
- Structured error tags: [phase125/return/var_not_in_env]
Ref: docs/development/current/main/phases/phase-125/README.md
2025-12-18 06:30:55 +09:00
c40971dc74
feat(control_tree): Phase 124 return variable from env (dev-only)
...
Phase 124-P3:
- Add env: BTreeMap<String, ValueId> from writes in lower_if_only_to_normalized
- Pass env and contract to lower_return_from_tree, lower_if_node, lower_return_value
- Implement Return(Variable) support:
- If variable in env (writes): Ret(Some(vid))
- If variable not in env: Err (out of scope, phase124 error)
- Add phase124 errors to Ok(None) conversion (dev-only compatibility)
- Add unit test: test_return_variable_from_env (verifies Ret(Some(ValueId(1))))
- All 1159 tests PASS
2025-12-18 06:05:18 +09:00
320a23e3d1
refactor(control_tree): include reads in StepTreeContract signature
...
Phase 124-P2:
- Add reads: BTreeSet<String> to StepTreeContract
- Include reads in signature_basis_string (format: ...;reads=...;...)
- Update from_facts() to copy reads from StepTreeFacts
- Update all StepTreeContract construction sites (builder.rs, parity.rs tests)
- Update test expected signature to include reads field
- Maintains determinism: BTreeSet guarantees stable iteration order
2025-12-18 06:00:21 +09:00
95b25e54ad
feat(control_tree): Phase 124 add reads to StepTreeFacts
...
- Add reads: BTreeSet<String> to StepTreeFacts
- Add add_read() API and merge_reads() in merge()
- Add extract_variables_from_ast() helper for AST traversal
- Extract reads from:
- If/Loop condition AST
- Return value AST
- All Variable nodes recursively (BinaryOp, UnaryOp, FunctionCall, MethodCall, FieldAccess, Index, Assignment RHS, Print)
- SSOT: extract_variables_from_ast() is the single source for reads collection
2025-12-18 05:58:08 +09:00
7eec4ec0c8
feat(control_tree): Phase 123 if-only compare+return lowering (Normalized, dev-only)
...
Implements Phase 123 P3: If(cond_ast) minimal lowering with graceful degradation.
**What's Implemented**:
- If node lowering with minimal binary comparison (Variable op Integer)
- Supported operators: ==, !=, <, <=, >, >=
- Generates: Compare + Const + Ret structure
- Graceful degradation: returns Ok(None) for unsupported patterns
**Key Design Decisions**:
1. **Graceful Degradation**: Phase 123 limitations return `Ok(None)` instead of failing
- Allows dev-only mode to coexist with legacy code
- Error messages prefixed with `[phase123/...]` are caught
2. **Fail-Fast with Structured Errors**: All limitations use structured error codes
- Format: `[phase123/category/specific]`
3. **Box-First Principles**:
- `parse_minimal_compare`: Single responsibility parser
- `verify_branch_is_return_literal`: Branch validation box
- `lower_if_node`: If lowering box
**Implementation**:
- Added `lower_if_node`: If lowering with minimal compare
- Added `parse_minimal_compare`: Binary comparison parser
- Added `verify_branch_is_return_literal`: Branch validator
- Updated `lower_if_only_to_normalized` return type: `Result<Option<...>, ...>`
- Updated `test_return_variable_out_of_scope`: Verifies graceful degradation
- Added `test_if_minimal_compare`: Verifies If lowering structure
**Tests**: 8 passed (including graceful degradation test)
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com >
2025-12-18 05:50:09 +09:00
f72064f35a
feat(control_tree): Phase 123 P1 return integer literal in Normalized if-only
...
- Add value_ast to StepStmtKind::Return for payload tracking
- Implement lower_return_value for Integer literal → Compute(Const) + Ret
- Add 3 unit tests: integer literal, void, variable fail-fast
- All tests passing (7 passed)
2025-12-18 05:37:13 +09:00
cc1a0946b0
feat(joinir/dev): build Normalized if-only module with structure verification (no behavior change)
...
Phase 122 P2-P3: Dev-only wiring + structure verification
- Wire Phase 122 emission into existing Phase 121 dev path
- Add verify_normalized_structure() for module validation
- Check: phase, function count, entry point, env args count
- Strict mode: fail-fast on structure mismatch
- No behavior change to existing execution path
2025-12-18 04:52:09 +09:00
7603ef8a6a
feat(control_tree): emit Normalized JoinModule for if-only (dev-only)
...
Phase 122 P1: StepTree→Normalized JoinModule generation
- Generate env layout from writes (SSOT, deterministic)
- Minimal implementation: main function + Ret only
- Full If/Assign/Return lowering in future P2-P4
- Dev-only: no behavior change to existing path
2025-12-18 04:50:32 +09:00
89b868703f
feat(joinir/dev): wire Phase 121 StepTree shadow lowering (strict fail-fast)
2025-12-18 04:34:43 +09:00
1e5432f61a
feat(control_tree): add StepTree→Normalized shadow lowerer (if-only, dev-only)
2025-12-18 04:31:41 +09:00
dd125cb700
test(control_tree): cover facts→contract determinism
2025-12-18 04:19:14 +09:00
43d3e7c935
refactor(control_tree): split StepTree facts vs contract boxes
2025-12-18 04:18:37 +09:00
98061260a0
refactor(control_tree): store AST cond handles in StepTree (dev-only)
...
Phase 119: StepTree cond SSOT (AST handle)
- Add AstNodeHandle to StepNode::If and StepNode::Loop
- cond_ast holds Box<ASTNode> clone (dev-only, acceptable overhead)
- cond_sig (AstSummary) remains signature/log material
- signature_basis_string() unchanged (Span-free, deterministic)
- Tests: cond_ast population + signature stability confirmed
2025-12-18 04:09:00 +09:00
052040e59c
refactor(joinir): extract ExitArgsCollectorBox for jump_args SSOT
...
Phase 118 refactoring: Box modularization for exit value collection.
# Changes
- Created `exit_args_collector.rs` with ExitArgsCollectorBox
- Extracted jump_args processing logic from instruction_rewriter.rs
- Implemented SSOT for offset calculation (0 vs 1 legacy layout)
- Added comprehensive unit tests (6 tests, all passing)
# Design
- **Responsibility**: Collects exit PHI inputs + carrier inputs from jump_args
- **SSOT**: Centralized offset calculation logic
- **Fail-Fast**: Validates jump_args length against exit_bindings
- **Phase 118 P2 Contract**: Uses boundary.exit_bindings as SSOT
# Key Features
- Filters ConditionOnly carriers (no exit PHI needed)
- Handles both direct mapping (offset=0) and legacy layout (offset=1)
- Strict mode: Fail-Fast on validation errors
- Non-strict mode: Warns and continues with best effort
# Test Results
- Unit tests: 6/6 PASS
- Phase 118 smoke tests: PASS (VM + LLVM)
- Phase 117 regression: PASS
# Reduced Code Complexity
- instruction_rewriter.rs: ~90 lines → ~25 lines (box call)
- Offset logic: Centralized in ExitArgsCollectorBox
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com >
2025-12-18 03:56:21 +09:00
432fc96082
refactor(joinir): extract IfSumExitMetaBuilderBox for Fail-Fast carrier binding
...
Phase 118 refactoring: Box modularization for ExitMeta generation.
# Changes
- Created `exit_meta_builder.rs` with IfSumExitMetaBuilderBox
- Extracted ExitMeta generation logic from loop_with_if_phi_if_sum.rs
- Implemented Fail-Fast contract (carrier name validation)
- Added comprehensive unit tests (5 tests, all passing)
# Design
- **Responsibility**: Builds ExitMeta from carrier name + ValueId
- **Fail-Fast**: Validates carrier names immediately
- **Reusability**: Can be used by other patterns (Pattern 4, etc.)
# Test Results
- Unit tests: 5/5 PASS
- Phase 118 smoke tests: PASS (VM + LLVM)
- Phase 117 regression: PASS
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com >
2025-12-18 03:56:10 +09:00
1080dee58f
fix(joinir): Phase 118 Pattern3 exit carrier PHI SSOT
2025-12-18 03:43:00 +09:00
ce7e2c1b91
refactor(env): centralize NYASH_JOINIR_STRUCTURE_ONLY flag
...
Moved NYASH_JOINIR_STRUCTURE_ONLY environment variable handling
from inline std::env::var() in routing.rs to a centralized helper
function in src/config/env/joinir_flags.rs.
Changes:
- Added joinir_structure_only_enabled() helper function
- Replaced direct env::var() call in routing.rs with helper
- Maintains existing behavior: default ON, NYASH_JOINIR_STRUCTURE_ONLY=0/off to disable
- Follows env module centralization pattern (Box Theory: separation of concerns)
Testing:
- cargo test --lib: 1126 passed ✅
- Regression: Phase 107 VM smoke ✅
- Phase 113/114 maintained ✅
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com >
2025-12-18 02:19:14 +09:00
09ce24e132
feat(joinir): Phase 112 strict guard for StepTree required_caps
...
- Add control_tree_capability_guard.rs with check(tree, func_name, strict, dev)
- Allowlist: If, NestedIf, Loop, Return, Break, Continue
- Deny (strict): NestedLoop, TryCatch, Throw, Lambda, While, ForRange, Match, Arrow
- Wire into lower_function_body() (strict-only check)
- Error format: [joinir/control_tree/cap_missing/<Cap>] with 1-line Hint
- Unit tests: nested_loop_rejects, if_only_passes, strict_false_passes
- Default behavior unchanged (strict=false always Ok)
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com >
2025-12-18 01:38:25 +09:00
14730c227f
feat(control_tree): add StepTreeContract and signature (dev-only)
2025-12-18 00:57:58 +09:00
9bcda215f8
refactor(joinir): split Pattern2 orchestrator into smaller steps
2025-12-18 00:44:31 +09:00
e4735f4054
refactor(control_tree): use ASTNode::span SSOT
2025-12-18 00:32:23 +09:00
3987aa5b06
refactor(joinir): drop unused break helper wrappers
2025-12-18 00:30:01 +09:00
e65bb791b9
refactor(builder): route debug logs via trace
2025-12-18 00:29:57 +09:00
2b5c141e22
feat(control_tree): add StepTree builder (dev-only)
2025-12-18 00:22:21 +09:00