Files
hakorune/docs/development/current/main/joinir-boundary-builder-pattern.md
nyash-codex cbeab6abd7 feat(joinir): Phase 201 - JoinInlineBoundaryBuilder expansion to Pattern3/4
- Task 201-1: Established canonical Builder pattern documentation
  - Created docs/development/current/main/joinir-boundary-builder-pattern.md
  - Documented Builder usage patterns for all patterns (P1/P2/P3/P4)
  - Added reference comments in pattern lowerers

- Task 201-2: Refactored Pattern3 to use Builder (removed field mutations)
  - Replaced new_with_exit_bindings + field mutation with Builder chain
  - Pattern3: 2 carriers (i + sum), exit_bindings, loop_var_name
  - Proper LoopExitBinding struct usage

- Task 201-3: Refactored Pattern4 to use Builder (continue/Trim support)
  - Replaced new_with_exit_bindings + field mutation with Builder chain
  - Pattern4: Dynamic carrier count, proper boundary construction

- Task 201-4: Added unit tests for Pattern3/4 style boundaries
  - test_builder_pattern3_style: Two carriers, exit_bindings validation
  - test_builder_pattern4_style: Dynamic carrier count validation
  - Verified no field mutations remain (exit_binding.rs uses deprecated fields only)

- Task 201-5: Updated architecture docs and CURRENT_TASK
  - joinir-architecture-overview.md: Builder now applied to all patterns
  - CURRENT_TASK.md: Phase 201 completion entry

All patterns now use consistent boundary construction via Builder.
Tests: All patterns pass (挙動不変).
2025-12-08 06:14:03 +09:00

96 lines
2.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# JoinInlineBoundaryBuilder 使用パターンPhase 201
## Pattern2 の Canonical 形式
Pattern2 で確立した Builder 使用パターンを他の Pattern に適用する際の基準。
### Builder 構築順序
```rust
let boundary = JoinInlineBoundaryBuilder::new()
.with_inputs(join_inputs, host_inputs)
.with_condition_bindings(condition_bindings)
.with_exit_bindings(exit_bindings)
.with_loop_var_name(Some(loop_var_name.clone()))
.with_expr_result(fragment_meta.expr_result)
.build();
```
### 各メソッドの意味
1. **with_inputs(join_inputs, host_inputs)**
- ループパラメータの橋渡し
- join_inputs: JoinIR 側の ValueId リスト
- host_inputs: MIR 側の ValueId リスト
2. **with_condition_bindings(bindings)**
- 条件式専用変数の橋渡し
- ConditionBinding のリスト(変数名 + JoinIR ValueId のペア)
3. **with_exit_bindings(bindings)**
- キャリア出口の橋渡し
- (変数名, JoinIR ValueId) のペア
4. **with_loop_var_name(name)**
- ループ変数名LoopHeader PHI 生成用)
- Some(変数名) または None
5. **with_expr_result(expr)**
- ループが式として返す値
- Some(ValueId) または None
### フィールド直書き禁止
-`boundary.loop_var_name = ...;` 等の直接代入は禁止
- ✅ Builder の fluent API のみ使用
### Pattern別の使用パターン
#### Pattern2 (with break)
```rust
let boundary = JoinInlineBoundaryBuilder::new()
.with_inputs(vec![ValueId(0)], vec![loop_var_id])
.with_condition_bindings(condition_bindings)
.with_exit_bindings(exit_bindings)
.with_loop_var_name(Some(loop_var_name.clone()))
.with_expr_result(fragment_meta.expr_result)
.build();
```
#### Pattern3 (with if-phi)
```rust
let boundary = JoinInlineBoundaryBuilder::new()
.with_inputs(
vec![ValueId(0), ValueId(1)], // i, sum
vec![loop_var_id, sum_var_id],
)
.with_exit_bindings(vec![
("sum".to_string(), ValueId(18))
])
.with_loop_var_name(Some(loop_var_name.clone()))
.build();
```
#### Pattern4 (with continue)
```rust
let boundary = JoinInlineBoundaryBuilder::new()
.with_inputs(join_inputs, host_inputs) // Dynamic carrier count
.with_exit_bindings(exit_bindings)
.with_loop_var_name(Some(loop_var_name.clone()))
.build();
```
## Phase 201 目標
- ✅ Pattern2/3/4 全てで Builder 使用に統一
- ✅ フィールド直書き(`boundary.field = value;`)完全排除
- ✅ 境界情報の組み立てを 1 箇所Builderに集約
- ✅ テスト全 PASS挙動不変
## 実装ファイル
- Builder 本体: `src/mir/join_ir/lowering/inline_boundary_builder.rs`
- Pattern2: `src/mir/builder/control_flow/joinir/patterns/pattern2_with_break.rs`
- Pattern3: `src/mir/builder/control_flow/joinir/patterns/pattern3_with_if_phi.rs`
- Pattern4: `src/mir/builder/control_flow/joinir/patterns/pattern4_with_continue.rs`