refactor(joinir): Phase 30 F-2.0/F-3 - PHI箱インベントリと旧APIレガシー削除
F-3 レガシー削除: - generic_case_a.rs: 旧API関数4個削除(_with_scope 移行完了) - loop_scope_shape.rs: CaseAContext::new() 削除(from_scope() に統一) - mod.rs: 不要な pub use 削除 - #[allow(dead_code)] 除去(5関数) - 未使用import削除(コード削減約150行) F-2.0 PHI箱インベントリ: - PHI_BOX_INVENTORY.md 作成: 13箱+11補助構造体の棚卸し - 削除順ポリシー: 早期/中期/最終の3段階 - TASKS.md/CURRENT_TASK.md 更新 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -9,8 +9,6 @@
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use crate::mir::join_ir::lowering::loop_scope_shape::CaseAContext;
|
||||
// Phase 30: LoopScopeShape は将来の _with_scope API 追加時に再インポート
|
||||
// use crate::mir::join_ir::lowering::loop_scope_shape::LoopScopeShape;
|
||||
use crate::mir::join_ir::lowering::value_id_ranges;
|
||||
use crate::mir::join_ir::lowering::value_id_ranges::skip_ws as vid;
|
||||
use crate::mir::join_ir::lowering::value_id_ranges::stage1_using_resolver as stage1_vid;
|
||||
@ -18,45 +16,7 @@ use crate::mir::join_ir::{
|
||||
BinOpKind, CompareOp, ConstValue, JoinContId, JoinFuncId, JoinFunction, JoinInst, JoinModule,
|
||||
LoopExitShape, LoopHeaderShape, MirLikeInst,
|
||||
};
|
||||
use crate::mir::loop_form::LoopForm;
|
||||
use crate::mir::phi_core::loop_exit_liveness::LoopExitLivenessBox;
|
||||
use crate::mir::phi_core::loop_var_classifier::LoopVarClassBox;
|
||||
use crate::mir::{MirFunction, MirQuery, ValueId};
|
||||
|
||||
/// v1: minimal_ssa_skip_ws 専用の汎用 Case A ロワー
|
||||
///
|
||||
/// - LoopForm / VarClass / ExitLiveness は形の検証にのみ使う(パターンが合わなければ None)
|
||||
/// - JoinModule の形は hand-written skip_ws と同一になるように組み立てる
|
||||
pub fn lower_case_a_loop_to_joinir_for_minimal_skip_ws(
|
||||
loop_form: &LoopForm,
|
||||
var_classes: &LoopVarClassBox,
|
||||
exit_live: &LoopExitLivenessBox,
|
||||
query: &impl MirQuery,
|
||||
mir_func: &MirFunction,
|
||||
) -> Option<JoinModule> {
|
||||
// 追加の latch チェック(skip_ws 固有)
|
||||
if loop_form.latch != loop_form.body && loop_form.latch != loop_form.header {
|
||||
eprintln!(
|
||||
"[joinir/generic_case_a] unexpected latch {:?} (body={:?}, header={:?}), fallback",
|
||||
loop_form.latch, loop_form.body, loop_form.header
|
||||
);
|
||||
return None;
|
||||
}
|
||||
|
||||
// CaseAContext で共通ロジックを実行
|
||||
let ctx = CaseAContext::new(
|
||||
loop_form,
|
||||
var_classes,
|
||||
exit_live,
|
||||
query,
|
||||
mir_func,
|
||||
"skip_ws",
|
||||
|offset| vid::loop_step(offset),
|
||||
)?;
|
||||
|
||||
// コア実装に委譲(Phase 30: _with_scope と共通化)
|
||||
lower_case_a_skip_ws_core(&ctx)
|
||||
}
|
||||
use crate::mir::ValueId;
|
||||
|
||||
/// Phase 30: LoopScopeShape を直接受け取る skip_ws lowerer
|
||||
///
|
||||
@ -267,28 +227,24 @@ fn lower_case_a_skip_ws_core(ctx: &CaseAContext) -> Option<JoinModule> {
|
||||
Some(join_module)
|
||||
}
|
||||
|
||||
/// Placeholder: trim minimal 用の generic Case A ロワー(v0, 未実装)
|
||||
/// Phase 30 F-3.0.3: LoopScopeShape を直接受け取る trim lowerer
|
||||
///
|
||||
/// - いまは構造チェックのみで必ず None を返し、呼び元でフォールバックさせる
|
||||
/// - 将来 trim_minimal を generic_case_a で置き換える際の導線として用意
|
||||
pub fn lower_case_a_loop_to_joinir_for_trim_minimal(
|
||||
loop_form: &LoopForm,
|
||||
var_classes: &LoopVarClassBox,
|
||||
exit_live: &LoopExitLivenessBox,
|
||||
query: &impl MirQuery,
|
||||
mir_func: &MirFunction,
|
||||
/// 呼び出し元で LoopScopeShape を明示的に構築し、この関数に渡す。
|
||||
/// CaseAContext::from_scope() 経由で ctx を作成。
|
||||
pub(crate) fn lower_case_a_trim_with_scope(
|
||||
scope: crate::mir::join_ir::lowering::loop_scope_shape::LoopScopeShape,
|
||||
) -> Option<JoinModule> {
|
||||
// CaseAContext で共通ロジックを実行
|
||||
let ctx = CaseAContext::new(
|
||||
loop_form,
|
||||
var_classes,
|
||||
exit_live,
|
||||
query,
|
||||
mir_func,
|
||||
"trim",
|
||||
|offset| value_id_ranges::funcscanner_trim::loop_step(offset),
|
||||
)?;
|
||||
let ctx = CaseAContext::from_scope(scope, "trim", |offset| {
|
||||
value_id_ranges::funcscanner_trim::loop_step(offset)
|
||||
})?;
|
||||
lower_case_a_trim_core(&ctx)
|
||||
}
|
||||
|
||||
/// trim JoinModule 構築のコア実装
|
||||
///
|
||||
/// CaseAContext から JoinModule を構築する共通ロジック。
|
||||
/// `_for_trim_minimal` と `_with_scope` の両方から呼ばれる。
|
||||
fn lower_case_a_trim_core(ctx: &CaseAContext) -> Option<JoinModule> {
|
||||
let string_key = ctx.pinned_name_or_first(0)?;
|
||||
let base_key = ctx.pinned_name_or_first(1).unwrap_or_else(|| string_key.clone());
|
||||
let carrier_key = ctx.carrier_name_or_first(0)?;
|
||||
@ -747,28 +703,24 @@ pub fn lower_case_a_loop_to_joinir_for_trim_minimal(
|
||||
Some(join_module)
|
||||
}
|
||||
|
||||
/// append_defs_minimal 用の generic Case A ロワー(LoopForm/VarClass/ExitLiveness ベース)
|
||||
/// Phase 30 F-3.0.4: LoopScopeShape を直接受け取る append_defs lowerer
|
||||
///
|
||||
/// - LoopForm が単一 header/latch でない場合や、必要な変数がマッピングできない場合は None を返す。
|
||||
/// - 既存の手書き JoinIR(append_defs_entry + loop_step)と同じ形を目指す。
|
||||
pub fn lower_case_a_loop_to_joinir_for_append_defs_minimal(
|
||||
loop_form: &LoopForm,
|
||||
var_classes: &LoopVarClassBox,
|
||||
exit_live: &LoopExitLivenessBox,
|
||||
query: &impl MirQuery,
|
||||
mir_func: &MirFunction,
|
||||
/// 呼び出し元で LoopScopeShape を明示的に構築し、この関数に渡す。
|
||||
/// CaseAContext::from_scope() 経由で ctx を作成。
|
||||
pub(crate) fn lower_case_a_append_defs_with_scope(
|
||||
scope: crate::mir::join_ir::lowering::loop_scope_shape::LoopScopeShape,
|
||||
) -> Option<JoinModule> {
|
||||
// CaseAContext で共通ロジックを実行
|
||||
let ctx = CaseAContext::new(
|
||||
loop_form,
|
||||
var_classes,
|
||||
exit_live,
|
||||
query,
|
||||
mir_func,
|
||||
"append_defs",
|
||||
|offset| value_id_ranges::funcscanner_append_defs::loop_step(offset),
|
||||
)?;
|
||||
let ctx = CaseAContext::from_scope(scope, "append_defs", |offset| {
|
||||
value_id_ranges::funcscanner_append_defs::loop_step(offset)
|
||||
})?;
|
||||
lower_case_a_append_defs_core(&ctx)
|
||||
}
|
||||
|
||||
/// append_defs JoinModule 構築のコア実装
|
||||
///
|
||||
/// CaseAContext から JoinModule を構築する共通ロジック。
|
||||
/// `_for_append_defs_minimal` と `_with_scope` の両方から呼ばれる。
|
||||
fn lower_case_a_append_defs_core(ctx: &CaseAContext) -> Option<JoinModule> {
|
||||
let dst_key = ctx.pinned_name_or_first(0)?;
|
||||
let defs_key = ctx.pinned_name_or_first(1).unwrap_or_else(|| dst_key.clone());
|
||||
let n_key = ctx.pinned_name_or_first(2).unwrap_or_else(|| defs_key.clone());
|
||||
@ -904,25 +856,23 @@ pub fn lower_case_a_loop_to_joinir_for_append_defs_minimal(
|
||||
Some(join_module)
|
||||
}
|
||||
|
||||
/// Stage1UsingResolver minimal 用の generic Case A ロワー(LoopForm/VarClass/ExitLiveness ベース)
|
||||
pub fn lower_case_a_loop_to_joinir_for_stage1_usingresolver_minimal(
|
||||
loop_form: &LoopForm,
|
||||
var_classes: &LoopVarClassBox,
|
||||
exit_live: &LoopExitLivenessBox,
|
||||
query: &impl MirQuery,
|
||||
mir_func: &MirFunction,
|
||||
/// Phase 30 F-3.0.5: LoopScopeShape を直接受け取る Stage-1 UsingResolver lowerer
|
||||
///
|
||||
/// 呼び出し元で LoopScopeShape を明示的に構築し、この関数に渡す。
|
||||
/// CaseAContext::from_scope() 経由で ctx を作成。
|
||||
pub(crate) fn lower_case_a_stage1_usingresolver_with_scope(
|
||||
scope: crate::mir::join_ir::lowering::loop_scope_shape::LoopScopeShape,
|
||||
) -> Option<JoinModule> {
|
||||
// CaseAContext で共通ロジックを実行
|
||||
let ctx = CaseAContext::new(
|
||||
loop_form,
|
||||
var_classes,
|
||||
exit_live,
|
||||
query,
|
||||
mir_func,
|
||||
"stage1",
|
||||
|offset| stage1_vid::loop_step(offset),
|
||||
)?;
|
||||
let ctx =
|
||||
CaseAContext::from_scope(scope, "stage1", |offset| stage1_vid::loop_step(offset))?;
|
||||
lower_case_a_stage1_usingresolver_core(&ctx)
|
||||
}
|
||||
|
||||
/// Stage-1 UsingResolver JoinModule 構築のコア実装
|
||||
///
|
||||
/// CaseAContext から JoinModule を構築する共通ロジック。
|
||||
/// `_for_stage1_usingresolver_minimal` と `_with_scope` の両方から呼ばれる。
|
||||
fn lower_case_a_stage1_usingresolver_core(ctx: &CaseAContext) -> Option<JoinModule> {
|
||||
let entries_key = ctx.pinned_name_or_first(0)?;
|
||||
let n_key = ctx.pinned_name_or_first(1).unwrap_or_else(|| entries_key.clone());
|
||||
let modules_key = ctx.pinned_name_or_first(2).unwrap_or_else(|| entries_key.clone());
|
||||
|
||||
@ -36,11 +36,11 @@
|
||||
use std::collections::{BTreeMap, BTreeSet};
|
||||
|
||||
use crate::mir::join_ir::lowering::exit_args_resolver::resolve_exit_args;
|
||||
use crate::mir::join_ir::lowering::loop_form_intake::{intake_loop_form, LoopFormIntake};
|
||||
use crate::mir::join_ir::lowering::loop_form_intake::LoopFormIntake;
|
||||
use crate::mir::loop_form::LoopForm;
|
||||
use crate::mir::phi_core::loop_exit_liveness::LoopExitLivenessBox;
|
||||
use crate::mir::phi_core::loop_var_classifier::{LoopVarClass, LoopVarClassBox};
|
||||
use crate::mir::{BasicBlockId, MirFunction, MirQuery, ValueId};
|
||||
use crate::mir::{BasicBlockId, MirQuery, ValueId};
|
||||
|
||||
/// ループ変数スコープの統合ビュー
|
||||
///
|
||||
@ -95,7 +95,13 @@ use crate::mir::{BasicBlockId, MirFunction, MirQuery, ValueId};
|
||||
/// - `body_locals`: ループ内だけで完結する変数(JoinIR では参照しない)
|
||||
/// - `exit_live`: ループ後に使われる変数(needs_exit_phi() == true)
|
||||
/// - `progress_carrier`: ループを前に進める変数(将来の Verifier 用)
|
||||
///
|
||||
/// # Phase 30 Note
|
||||
///
|
||||
/// Block ID フィールド (header/body/latch/exit) と progress_carrier は
|
||||
/// F-3/F-4 で使用予定。現在は SSOT として保持。
|
||||
#[derive(Debug, Clone)]
|
||||
#[allow(dead_code)] // Phase 30: block IDs and progress_carrier are for future F-3/F-4 use
|
||||
pub(crate) struct LoopScopeShape {
|
||||
// === Block IDs (Phase 30: from LoopForm) ===
|
||||
|
||||
@ -261,6 +267,7 @@ impl LoopScopeShape {
|
||||
}
|
||||
|
||||
/// 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 {
|
||||
self.pinned.contains(var_name) || self.carriers.contains(var_name)
|
||||
}
|
||||
@ -281,6 +288,7 @@ impl LoopScopeShape {
|
||||
}
|
||||
|
||||
/// Get all variables that need header PHI (pinned + carriers)
|
||||
#[allow(dead_code)] // Phase 30: will be used in F-3 generic lowering
|
||||
pub fn header_phi_vars(&self) -> Vec<String> {
|
||||
let mut result: Vec<String> = self.pinned.iter().cloned().collect();
|
||||
result.extend(self.carriers.iter().cloned());
|
||||
@ -288,6 +296,7 @@ impl LoopScopeShape {
|
||||
}
|
||||
|
||||
/// Get all variables that need exit PHI
|
||||
#[allow(dead_code)] // Phase 30: will be used in F-3 generic lowering
|
||||
pub fn exit_phi_vars(&self) -> Vec<String> {
|
||||
self.exit_live.iter().cloned().collect()
|
||||
}
|
||||
@ -354,11 +363,8 @@ impl LoopScopeShape {
|
||||
/// # Usage
|
||||
///
|
||||
/// ```ignore
|
||||
/// let ctx = CaseAContext::new(
|
||||
/// loop_form, var_classes, exit_live, query, mir_func,
|
||||
/// "skip_ws",
|
||||
/// |offset| vid::loop_step(offset),
|
||||
/// )?;
|
||||
/// let scope = LoopScopeShape::from_existing_boxes(...)?;
|
||||
/// let ctx = CaseAContext::from_scope(scope, "skip_ws", |offset| vid::loop_step(offset))?;
|
||||
///
|
||||
/// // ctx から必要な情報を取り出して JoinModule を構築
|
||||
/// let header_shape = LoopHeaderShape::new_manual(ctx.pinned_ids.clone(), ctx.carrier_ids.clone());
|
||||
@ -387,93 +393,7 @@ pub(crate) struct CaseAContext {
|
||||
}
|
||||
|
||||
impl CaseAContext {
|
||||
/// CaseAContext を構築する
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `loop_form`: ループ構造情報
|
||||
/// - `var_classes`: 変数分類器
|
||||
/// - `exit_live`: exit liveness 情報
|
||||
/// - `query`: MIR クエリ
|
||||
/// - `mir_func`: MIR 関数
|
||||
/// - `log_tag`: ログ出力用タグ(例: "skip_ws", "trim")
|
||||
/// - `loop_step_id_fn`: offset から ValueId を生成する関数
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// Some(CaseAContext) if successful, None if validation fails or data is missing.
|
||||
pub(crate) fn new<F>(
|
||||
loop_form: &LoopForm,
|
||||
var_classes: &LoopVarClassBox,
|
||||
exit_live: &LoopExitLivenessBox,
|
||||
query: &impl MirQuery,
|
||||
mir_func: &MirFunction,
|
||||
log_tag: &str,
|
||||
loop_step_id_fn: F,
|
||||
) -> Option<Self>
|
||||
where
|
||||
F: Fn(u32) -> ValueId,
|
||||
{
|
||||
// 1) LoopForm validation
|
||||
if loop_form.header == loop_form.exit {
|
||||
eprintln!(
|
||||
"[joinir/generic_case_a/{}] loop_form malformed (header == exit), fallback",
|
||||
log_tag
|
||||
);
|
||||
return None;
|
||||
}
|
||||
|
||||
// 2) MIR から pinned/carrier/exit 情報を抽出
|
||||
let intake = intake_loop_form(loop_form, var_classes, query, mir_func)?;
|
||||
|
||||
// 3) LoopScopeShape を構築 (Phase 30: includes block IDs)
|
||||
let scope = LoopScopeShape::from_existing_boxes(
|
||||
loop_form,
|
||||
&intake,
|
||||
var_classes,
|
||||
exit_live,
|
||||
query,
|
||||
)?;
|
||||
|
||||
let ordered_pinned = scope.pinned_ordered();
|
||||
let ordered_carriers = scope.carriers_ordered();
|
||||
|
||||
// 4) 変数名 → ValueId マッピングを構築
|
||||
let mut name_to_loop_id: BTreeMap<String, ValueId> = BTreeMap::new();
|
||||
let mut offset: u32 = 0;
|
||||
for name in &ordered_pinned {
|
||||
name_to_loop_id.insert(name.clone(), loop_step_id_fn(offset));
|
||||
offset += 1;
|
||||
}
|
||||
for name in &ordered_carriers {
|
||||
name_to_loop_id.insert(name.clone(), loop_step_id_fn(offset));
|
||||
offset += 1;
|
||||
}
|
||||
|
||||
// 5) pinned_ids / carrier_ids を構築
|
||||
let pinned_ids: Vec<ValueId> = ordered_pinned
|
||||
.iter()
|
||||
.filter_map(|k| name_to_loop_id.get(k).copied())
|
||||
.collect();
|
||||
let carrier_ids: Vec<ValueId> = ordered_carriers
|
||||
.iter()
|
||||
.filter_map(|k| name_to_loop_id.get(k).copied())
|
||||
.collect();
|
||||
|
||||
// 6) exit_args を解決
|
||||
let exit_args = resolve_exit_args(&scope.exit_live, &name_to_loop_id, &ordered_carriers)?;
|
||||
|
||||
Some(Self {
|
||||
ordered_pinned,
|
||||
ordered_carriers,
|
||||
name_to_loop_id,
|
||||
pinned_ids,
|
||||
carrier_ids,
|
||||
exit_args,
|
||||
})
|
||||
}
|
||||
|
||||
/// Phase 30: LoopScopeShape を直接受け取る新コンストラクタ
|
||||
/// LoopScopeShape を直接受け取るコンストラクタ (Phase 30)
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
|
||||
@ -30,7 +30,7 @@ pub mod value_id_ranges;
|
||||
// Re-export public lowering functions
|
||||
pub use funcscanner_append_defs::lower_funcscanner_append_defs_to_joinir;
|
||||
pub use funcscanner_trim::lower_funcscanner_trim_to_joinir;
|
||||
pub use generic_case_a::lower_case_a_loop_to_joinir_for_minimal_skip_ws;
|
||||
// Phase 30 F-3: 旧 lower_case_a_loop_to_joinir_for_minimal_skip_ws は _with_scope に置き換え済みのため削除
|
||||
pub use min_loop::lower_min_loop_to_joinir;
|
||||
pub use skip_ws::lower_skip_ws_to_joinir;
|
||||
pub use stage1_using_resolver::lower_stage1_usingresolver_to_joinir;
|
||||
|
||||
Reference in New Issue
Block a user