Commit Graph

2241 Commits

Author SHA1 Message Date
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
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
b7a16aacd0 docs: Phase 126 plan (wire available_inputs) 2025-12-18 06:40:36 +09:00
aabb67cdc2 docs: Phase 125 P2-P5 feedback (boxification review)
Feedback summary:
- 単一責任: EnvLayout / lower_return_value
- SSOT: reads ∩ available_inputs
- Fail-Fast: 構造化エラー + hint
- 段階的投入: 構造のみ(P3 で完成)

Good:
- Single responsibility principle maintained
- SSOT approach for env layout
- Fail-Fast with structured errors
- Graceful degradation (Ok(None))

Improvement proposals:
- P3 wiring clarification
- EnvLayout responsibility scope
- Error hint context-awareness
- Fixture completeness after P3

Next: Phase 125 P3 (available_inputs wiring)

Ref: docs/development/current/main/phases/phase-125/FEEDBACK.md
2025-12-18 06:33:55 +09:00
d7c77e1046 docs: Phase 125 P2-P5 DONE (structure-only, P3 pending)
Phase 125 P2-P5 完了:
- EnvLayout (writes + inputs) 導入
- Return(Variable) 解決拡張(writes or inputs)
- Fail-Fast with hint(構造化エラー)
- Unit tests: 18/18 PASS
- Integration smoke: PASS
- Regression: Phase 121-124, 118 維持

Next: Phase 125 P3 (available_inputs wiring)
- routing.rs / lowering.rs で available_inputs を配線
- SSOT: function params + CapturedEnv

Ref: docs/development/current/main/phases/phase-125/README.md
2025-12-18 06:33:03 +09:00
92b3c2afb5 test(joinir): Phase 125 P5 fixture + smoke (VM, structure-only)
Phase 125 P5: Integration smoke test
- fixture: apps/tests/phase125_if_only_return_readonly_input_min.hako
  - Expected: 7 (return x from reads-only input)
  - Note: Demonstrates structure, full functionality needs P3 wiring
- smoke: tools/smokes/v2/profiles/integration/apps/phase125_if_only_return_input_vm.sh
  - NYASH_JOINIR_DEV=1 HAKO_JOINIR_STRICT=1
  - VM backend only

Test results:
- Phase 125 smoke: PASS (exit code 7)
- Regression (Phase 121-124, 118): PASS
  - phase124_if_only_return_var_vm: PASS
  - phase123_if_only_normalized_semantics_vm: PASS
  - phase121_shadow_if_only_vm: PASS (3/3 tests)
  - phase118_loop_nested_if_merge_vm: PASS

Note:
- P3 (available_inputs wiring) not implemented yet
- Fixture uses simple return (no if-only pattern yet)
- Serves as design document for future P3 implementation
- EnvLayout.inputs will be populated when P3 is complete

Ref: docs/development/current/main/phases/phase-125/README.md
2025-12-18 06:32:10 +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
7eeeb588e4 docs: add Phase 125 entry (planned) 2025-12-18 06:28:39 +09:00
d044af1fbc docs: Phase 124 DONE
Phase 124 完了:
- reads facts SSOT 化(StepTreeFacts/Contract に追加)
- Return(Variable) from env (writes) サポート(dev-only)
- env マッピング(変数名 → ValueId)を writes から生成
- extract_variables_from_ast() で Variable 抽出を SSOT 化
- Fail-Fast 原則(env に無い Variable はエラー)
- Unit tests: 1159 PASS (including test_return_variable_from_env)
- Integration smoke: PASS (phase124_if_only_return_var_vm.sh)
- 回帰確認: Phase 121/123/118 全て PASS
- 10-Now.md 更新(Phase 124 完了、Phase 125 計画追加)
2025-12-18 06:10:17 +09:00
8e6791a623 test(joinir): Phase 124 return-var normalized smoke (VM)
Phase 124-P4:
- Add fixture: apps/tests/phase124_if_only_return_var_min.hako
  - local x; x = 7; print(x); return x
  - Expected output: 7 (print), RC: 7 (return x)
- Add smoke: tools/smokes/v2/profiles/integration/apps/phase124_if_only_return_var_vm.sh
  - NYASH_JOINIR_DEV=1 HAKO_JOINIR_STRICT=1 for dev-only features
  - Accept exit code 7 (return x where x=7) as valid
- Verify all Phase 121/123/118 smokes still PASS
2025-12-18 06:09:36 +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
fb4ec2c2bf docs: Phase 124 plan (reads facts + return var) 2025-12-18 05:54:51 +09:00
4f0ffae70d docs: Phase 123 DONE
Updates documentation to reflect Phase 123 completion.

**Updates**:
1. `docs/development/current/main/phases/phase-123/README.md`:
   - Marked all success criteria as complete
   - Added comprehensive DONE section with implementation details
   - Documented key design decisions (graceful degradation, fail-fast, box-first)
   - Added verification commands and next steps (Phase 124)

2. `docs/development/current/main/10-Now.md`:
   - Moved Phase 123 from "Next" to "2025-12-18: Phase 123 完了"
   - Added Phase 123 summary (Return literal, If minimal compare, graceful degradation)
   - Updated "Next" to Phase 124 (Normalized reads facts + Return(Variable))

3. `docs/development/current/main/01-JoinIR-Selfhost-INDEX.md`:
   - Added Phase 123 entry: "Normalized semantics (Return literal + If minimal compare, dev-only)"

**Phase 123 Summary**:
- P0: Docs complete, scope frozen 
- P1: Return(Integer literal) working 
- P2: Return(Variable) returns Ok(None) (graceful degradation) 
- P3: If(minimal compare) generates correct JoinIR 
- P4: Integration smoke passing 
- P5: Docs updated 

**Verification**:
- Unit tests: 8 passed
- Integration smoke: PASS
- Legacy tests: Still passing (graceful degradation confirmed)

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-18 05:50:29 +09:00
b3cd7c0884 test(joinir): Phase 123 normalized semantics smoke (VM)
Adds integration smoke test for Phase 123 normalized semantics lowering.

**New Files**:
- `apps/tests/phase123_if_only_return_literal_min.hako`: Minimal test fixture (output: 7)
- `tools/smokes/v2/profiles/integration/apps/phase123_if_only_normalized_semantics_vm.sh`: Smoke test script

**What's Tested**:
- Return(Integer literal) generates correct output
- Dev+strict mode does not fail (graceful degradation works)

**Test Status**: PASS

**Verification**:
```bash
bash tools/smokes/v2/profiles/integration/apps/phase123_if_only_normalized_semantics_vm.sh
# Result: PASS (output: 7)
```

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-18 05:50:16 +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
51ed137339 docs: Phase 123 plan (if-only normalized semantics) 2025-12-18 05:29:34 +09:00
bf7d3899b0 docs: Phase 122 DONE (if-only Normalized emit dev-only) 2025-12-18 04:54:49 +09:00
4abd434366 test: Phase 122 if-only Normalized emit smoke
Phase 122 P4: Fixtures and smoke tests
- New fixture: phase122_if_only_normalized_emit_min.hako
- Smoke test: phase122_if_only_normalized_emit_vm.sh
- Verifies: module emission + structure verification in dev+strict mode
- Regression check: phase103 fixture still passes
- All tests PASS
2025-12-18 04:53:04 +09:00