refactor(joinir): Phase 183-3 Document LoopScopeShape construction paths

Clarifies that LoopScopeShape has two complementary construction paths
for different contexts (AST-based vs LoopForm-based).

## Analysis

After investigating, discovered these builders serve **different purposes**:

1. **AST-based** (`patterns/loop_scope_shape_builder.rs`):
   - Builds from AST during MIR generation
   - Extracts body_locals from ASTNode::Local declarations
   - Used in Pattern 1-4 lowerers

2. **LoopForm-based** (`loop_scope_shape/builder.rs`):
   - Builds from LoopForm during JoinIR lowering
   - Analyzes LoopFormIntake snapshots
   - Used in generic_case_a and pattern routing

These are NOT duplicates - they're complementary paths!

## Changes

1. **Cross-Reference Documentation**:
   - `patterns/loop_scope_shape_builder.rs`: Added Phase 183-3 section
   - `loop_scope_shape/builder.rs`: Added Phase 183-3 section
   - Both now reference each other for clarity

2. **LoopScopeShape Struct Documentation**:
   - Added "Phase 183-3: Construction Paths" section
   - Documents two construction paths and their contexts
   - Explains when to use each builder

3. **Clarified Responsibilities**:
   - AST-based: For MIR building phase
   - LoopForm-based: For JoinIR lowering phase
   - Both maintain consistent field initialization

## Benefits

- **Clear separation**: Documented different contexts for each builder
- **Maintainability**: Future developers understand which builder to use
- **No code changes**: Pure documentation improvement
- **Cross-references**: Easy navigation between related modules

## Testing

 All loop_scope_shape tests pass (24 tests)
 No behavioral changes
 Documentation-only refactoring

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
nyash-codex
2025-12-08 22:22:25 +09:00
parent a32791b0ed
commit 94bf00faf9
3 changed files with 31 additions and 1 deletions

View File

@ -6,6 +6,14 @@
//! Trio legacy boxes は完全に除去済み。
//! LoopForm / LoopFormIntake から LoopScopeShape を構築し、変数分類と定義位置を
//! LoopScopeShape の内部に閉じ込める。
//!
//! # Phase 183-3: LoopForm-Based Construction Context
//!
//! This builder constructs LoopScopeShape from **LoopForm** during JoinIR lowering.
//! For AST-based construction (MIR building), see:
//! - `src/mir/builder/control_flow/joinir/patterns/loop_scope_shape_builder.rs`
//!
//! Both builders maintain consistent field initialization for LoopScopeShape.
use std::collections::{BTreeMap, BTreeSet};

View File

@ -56,6 +56,20 @@ impl LoopVarClass {
/// - Variable classification: `pinned`, `carriers`, `body_locals`, `exit_live`
/// - `progress_carrier`: 進捗チェック用(将来の Verifier で使用予定)
/// - `variable_definitions`: definition blocks collected from LoopFormIntake snapshots
///
/// # Phase 183-3: Construction Paths
///
/// LoopScopeShape has two construction paths depending on context:
///
/// 1. **AST-based** (MIR building): `patterns/loop_scope_shape_builder.rs`
/// - Extracts body_locals from AST nodes
/// - Used during initial MIR generation from source
///
/// 2. **LoopForm-based** (JoinIR lowering): `loop_scope_shape/builder.rs`
/// - Analyzes LoopForm and LoopFormIntake
/// - Used during JoinIR lowering from LoopForm
///
/// Both paths maintain consistent field initialization and variable classification.
#[derive(Debug, Clone)]
pub(crate) struct LoopScopeShape {
pub header: BasicBlockId,