From 1714eaa00cbb58d5f922b143265b2555e32989ea Mon Sep 17 00:00:00 2001 From: nyash-codex Date: Fri, 28 Nov 2025 19:00:03 +0900 Subject: [PATCH] feat(joinir): Phase 48-2 from_loop_form method for Trio absorption MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add LoopScopeShape::from_loop_form() that creates Trio internally - Remove LoopExitLivenessBox import from loop_to_join.rs - Switch loop_to_join.rs to use from_loop_form() instead of from_existing_boxes() This is the first step in absorbing Classifier Trio into LoopScopeShape. External Trio dependency reduced from 3 boxes to 2 (intake_loop_form only). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- src/mir/join_ir/lowering/loop_scope_shape.rs | 35 ++++++++++++++++++++ src/mir/join_ir/lowering/loop_to_join.rs | 24 ++++---------- 2 files changed, 42 insertions(+), 17 deletions(-) diff --git a/src/mir/join_ir/lowering/loop_scope_shape.rs b/src/mir/join_ir/lowering/loop_scope_shape.rs index 43f5ad64..daba01ac 100644 --- a/src/mir/join_ir/lowering/loop_scope_shape.rs +++ b/src/mir/join_ir/lowering/loop_scope_shape.rs @@ -253,6 +253,41 @@ impl LoopScopeShape { Self::from_existing_boxes_legacy(loop_form, intake, var_classes, exit_live_box, query) } + /// Phase 48-2: Trio引数なしでLoopScopeShapeを構築 + /// + /// # Purpose + /// + /// 外部からTrioを渡す必要をなくし、LoopScopeShape内部に完全吸収。 + /// `loop_to_join.rs` などで空のTrioを作成して渡すパターンを解消する。 + /// + /// # Arguments + /// + /// - `loop_form`: LoopForm containing block structure + /// - `intake`: LoopFormIntake containing classified variable info + /// - `query`: MirQuery for liveness computation + /// - `func_name`: Optional function name for Case-A minimal routing + /// + /// # Returns + /// + /// Some(LoopScopeShape) if successful, None if critical data is missing. + /// + /// # History + /// + /// - Phase 48-2: 新規追加(Trio依存の内部化) + pub(crate) fn from_loop_form( + loop_form: &LoopForm, + intake: &LoopFormIntake, + query: &impl MirQuery, + func_name: Option<&str>, + ) -> Option { + // Phase 48-2: Trio を内部で作成(空箱) + let var_classes = LoopVarClassBox::new(); + let exit_live_box = LoopExitLivenessBox::new(); + + // 既存の from_existing_boxes を呼び出し + Self::from_existing_boxes(loop_form, intake, &var_classes, &exit_live_box, query, func_name) + } + /// Check if a variable needs header PHI #[allow(dead_code)] // Phase 30: will be used in F-3 generic lowering pub fn needs_header_phi(&self, var_name: &str) -> bool { diff --git a/src/mir/join_ir/lowering/loop_to_join.rs b/src/mir/join_ir/lowering/loop_to_join.rs index b5e0395d..c1dff17a 100644 --- a/src/mir/join_ir/lowering/loop_to_join.rs +++ b/src/mir/join_ir/lowering/loop_to_join.rs @@ -31,8 +31,7 @@ use crate::mir::join_ir::lowering::loop_form_intake::intake_loop_form; use crate::mir::join_ir::lowering::loop_scope_shape::LoopScopeShape; use crate::mir::join_ir::JoinModule; use crate::mir::loop_form::LoopForm; -use crate::mir::phi_core::loop_exit_liveness::LoopExitLivenessBox; -use crate::mir::phi_core::loop_var_classifier::LoopVarClassBox; +// Phase 48-2: Trio imports removed - now internal to LoopScopeShape::from_loop_form() use crate::mir::query::MirQueryBox; use crate::mir::MirFunction; @@ -98,22 +97,13 @@ impl LoopToJoinLowerer { // Step 1: MirQuery を構築 let query = MirQueryBox::new(func); - // Step 2: 分類箱を構築(Phase 31 では空箱、将来 MIR 解析で埋める) - let var_classes = LoopVarClassBox::new(); - let exit_live = LoopExitLivenessBox::new(); + // Step 2: LoopFormIntake を構築 + // Phase 48-2: intake_loop_form は空の var_classes を使用(将来は from_loop_form に統合) + let intake = intake_loop_form(loop_form, &Default::default(), &query, func)?; - // Step 3: LoopFormIntake を構築 - let intake = intake_loop_form(loop_form, &var_classes, &query, func)?; - - // Step 4: LoopScopeShape を構築 - let scope = LoopScopeShape::from_existing_boxes( - loop_form, - &intake, - &var_classes, - &exit_live, - &query, - func_name, - )?; + // Step 3: LoopScopeShape を構築 + // Phase 48-2: from_loop_form() で Trio を内部化(LoopExitLivenessBox 依存削除) + let scope = LoopScopeShape::from_loop_form(loop_form, &intake, &query, func_name)?; if self.debug { eprintln!(