Commit Graph

6 Commits

Author SHA1 Message Date
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
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
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
1e5432f61a feat(control_tree): add StepTree→Normalized shadow lowerer (if-only, dev-only) 2025-12-18 04:31:41 +09:00