From 94bf00faf949638b24276105072dda5757088426 Mon Sep 17 00:00:00 2001 From: nyash-codex Date: Mon, 8 Dec 2025 22:22:25 +0900 Subject: [PATCH] refactor(joinir): Phase 183-3 Document LoopScopeShape construction paths MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../joinir/patterns/loop_scope_shape_builder.rs | 10 +++++++++- .../join_ir/lowering/loop_scope_shape/builder.rs | 8 ++++++++ src/mir/join_ir/lowering/loop_scope_shape/shape.rs | 14 ++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/mir/builder/control_flow/joinir/patterns/loop_scope_shape_builder.rs b/src/mir/builder/control_flow/joinir/patterns/loop_scope_shape_builder.rs index fad37b2c..feb18602 100644 --- a/src/mir/builder/control_flow/joinir/patterns/loop_scope_shape_builder.rs +++ b/src/mir/builder/control_flow/joinir/patterns/loop_scope_shape_builder.rs @@ -1,4 +1,4 @@ -//! LoopScopeShapeBuilder - Unified LoopScopeShape initialization +//! LoopScopeShapeBuilder - AST-based LoopScopeShape initialization //! //! Phase 171-172: Issue 4 //! @@ -11,6 +11,14 @@ //! - Extract body_locals from loop body AST when needed //! - Maintain consistent initialization defaults across patterns //! +//! # Phase 183-3: AST-Based Construction Context +//! +//! This builder constructs LoopScopeShape from **AST nodes** during MIR building. +//! For LoopForm-based construction (JoinIR lowering), see: +//! - `src/mir/join_ir/lowering/loop_scope_shape/builder.rs` +//! +//! Both builders maintain consistent field initialization for LoopScopeShape. +//! //! # Usage //! //! ```rust diff --git a/src/mir/join_ir/lowering/loop_scope_shape/builder.rs b/src/mir/join_ir/lowering/loop_scope_shape/builder.rs index 51b3dbc5..eb9767ad 100644 --- a/src/mir/join_ir/lowering/loop_scope_shape/builder.rs +++ b/src/mir/join_ir/lowering/loop_scope_shape/builder.rs @@ -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}; diff --git a/src/mir/join_ir/lowering/loop_scope_shape/shape.rs b/src/mir/join_ir/lowering/loop_scope_shape/shape.rs index 91536bcf..83434b90 100644 --- a/src/mir/join_ir/lowering/loop_scope_shape/shape.rs +++ b/src/mir/join_ir/lowering/loop_scope_shape/shape.rs @@ -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,