Commit Graph

11 Commits

Author SHA1 Message Date
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
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
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
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