refactor(plan): Phase 273 P3+ - Legacy code removal
Phase 273 P3+ 完成: レガシーコード削除 + 未使用 import 整理 Removed Legacy Items: 1. emit_scan_with_init_edgecfg() - Pattern6 固有の emission 関数 - File deleted: src/mir/builder/emission/loop_scan_with_init.rs (~144 lines) - Replaced by: generalized Frag API (Phase 273 P2) 2. CoreCarrierInfo struct - Legacy carrier representation - Removed from: src/mir/builder/control_flow/plan/mod.rs (~15 lines) - Replaced by: CorePhiInfo (generalized PHI representation) 3. verify_carrier() function - CoreCarrierInfo validator - Removed from: src/mir/builder/control_flow/plan/verifier.rs (~15 lines) - Replaced by: generalized PHI verification (V7-V9) Code Cleanup: - cargo fix applied: unused imports removed (~30 files) - Verifier invariants updated: V1→V2-V9 (carrier→PHI model) - Module declaration cleanup in emission/mod.rs Impact: - Total lines removed: ~174 lines (net reduction) - Pattern-agnostic architecture strengthened - All legacy Pattern6 references eliminated Tests: - ✅ VM tests PASS (phase254/256/258) - ✅ LLVM tests PASS (phase256/258) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@ -13,7 +13,6 @@ use std::collections::BTreeMap;
|
||||
use crate::mir::basic_block::{BasicBlockId, EdgeArgs};
|
||||
use crate::mir::control_form::LoopId;
|
||||
use crate::mir::value_id::ValueId;
|
||||
use crate::mir::join_ir::lowering::inline_boundary::JumpArgsLayout;
|
||||
use super::frag::Frag;
|
||||
use super::exit_kind::ExitKind;
|
||||
use super::edge_stub::EdgeStub; // Phase 265 P2: wires/exits 分離で必要
|
||||
|
||||
@ -34,7 +34,7 @@ pub(crate) use compose::{seq, if_, loop_, cleanup};
|
||||
|
||||
// 検証関数
|
||||
pub use verify::verify_frag_invariants;
|
||||
pub use verify::verify_frag_invariants_strict; // Phase 266: strict 版追加
|
||||
// Phase 266: strict 版追加
|
||||
|
||||
// Phase 267 P0: wires + branches → MIR terminator 変換
|
||||
pub use emit::{emit_wires, emit_frag};
|
||||
pub use emit::emit_frag;
|
||||
|
||||
@ -6,7 +6,5 @@
|
||||
pub mod api;
|
||||
|
||||
// 公開型(安定)
|
||||
pub use api::{ExitKind, EdgeStub, Frag, verify_frag_invariants};
|
||||
|
||||
// 合成関数(Phase 264: crate内のみ公開)
|
||||
pub(crate) use api::{seq, if_, loop_, cleanup};
|
||||
|
||||
@ -18,8 +18,7 @@ use crate::mir::builder::joinir_id_remapper::JoinIrIdRemapper;
|
||||
use crate::mir::join_ir::lowering::error_tags;
|
||||
use crate::mir::join_ir::lowering::inline_boundary::JoinInlineBoundary;
|
||||
// Phase 256 P1.7: Removed join_func_name import - no longer needed
|
||||
use crate::mir::types::ConstValue;
|
||||
use crate::mir::{BasicBlock, BasicBlockId, MirFunction, MirInstruction, MirModule, MirType, ValueId};
|
||||
use crate::mir::{BasicBlock, BasicBlockId, MirInstruction, MirModule, ValueId};
|
||||
use std::collections::BTreeMap; // Phase 222.5-E: HashMap → BTreeMap for determinism
|
||||
use std::collections::BTreeSet;
|
||||
|
||||
|
||||
@ -39,5 +39,5 @@ pub(super) mod terminator; // Phase 260 P0.1 Step 5: Terminator remapping extrac
|
||||
pub(super) mod type_propagation; // Phase 260 P0.1 Step 4: Type propagation extracted ✅
|
||||
|
||||
// Re-export public API
|
||||
pub(super) use helpers::is_skippable_continuation; // Phase 260 P0.1 Step 3: From helpers ✅
|
||||
// Phase 260 P0.1 Step 3: From helpers ✅
|
||||
pub(super) use super::instruction_rewriter::merge_and_rewrite; // Still in parent (TODO: extract)
|
||||
|
||||
@ -36,7 +36,6 @@ use super::pattern2_steps::gather_facts_step_box::GatherFactsStepBox;
|
||||
use super::pattern2_steps::merge_step_box::MergeStepBox;
|
||||
use super::pattern2_steps::normalize_body_step_box::NormalizeBodyStepBox;
|
||||
use super::pattern2_steps::post_loop_early_return_step_box::PostLoopEarlyReturnStepBox;
|
||||
use super::pattern2_steps::promote_step_box::PromoteStepBox;
|
||||
|
||||
pub(crate) struct Pattern2LoweringOrchestrator;
|
||||
|
||||
|
||||
@ -4,7 +4,6 @@
|
||||
|
||||
use crate::ast::ASTNode;
|
||||
use crate::mir::builder::MirBuilder;
|
||||
use crate::mir::ValueId;
|
||||
|
||||
use super::super::pattern2_inputs_facts_box::{Pattern2DebugLog, Pattern2Inputs};
|
||||
use crate::mir::join_ir::lowering::inline_boundary::JoinInlineBoundary;
|
||||
|
||||
@ -10,7 +10,7 @@
|
||||
use crate::ast::ASTNode;
|
||||
use crate::mir::builder::MirBuilder;
|
||||
|
||||
use super::super::pattern2::api::{try_promote, PromoteDecision, PromoteStepResult};
|
||||
use super::super::pattern2::api::{try_promote, PromoteDecision};
|
||||
use super::super::pattern2_inputs_facts_box::Pattern2Inputs;
|
||||
|
||||
pub(crate) struct PromoteStepBox;
|
||||
|
||||
@ -33,11 +33,8 @@
|
||||
//! - MethodCall allowed_in_condition() = false, but allowed_in_init() = true
|
||||
//! - Need to hoist MethodCall to init phase
|
||||
|
||||
use super::super::trace;
|
||||
use super::common::var; // Phase 255 P2: Use shared var() helper
|
||||
use crate::ast::{ASTNode, BinaryOperator, LiteralValue};
|
||||
use crate::mir::builder::MirBuilder;
|
||||
use crate::mir::ValueId;
|
||||
// Phase 255 P2: Use shared var() helper
|
||||
use crate::ast::ASTNode;
|
||||
|
||||
// Phase 273 P1: Import DomainPlan types (Plan renamed to DomainPlan)
|
||||
use crate::mir::builder::control_flow::plan::{DomainPlan, ScanDirection as PlanScanDirection, ScanWithInitPlan};
|
||||
|
||||
@ -34,7 +34,6 @@
|
||||
//! - Pattern 8: Returns boolean (true/false)
|
||||
|
||||
use super::super::trace;
|
||||
use super::common::var;
|
||||
use crate::ast::{ASTNode, BinaryOperator, LiteralValue, UnaryOperator};
|
||||
use crate::mir::builder::MirBuilder;
|
||||
use crate::mir::ValueId;
|
||||
|
||||
@ -192,21 +192,7 @@ pub(in crate::mir::builder) struct CoreLoopPlan {
|
||||
pub final_values: Vec<(String, ValueId)>,
|
||||
}
|
||||
|
||||
/// Phase 273 P1: Loop carrier (PHI variable)
|
||||
#[derive(Debug, Clone)]
|
||||
pub(in crate::mir::builder) struct CoreCarrierInfo {
|
||||
/// Variable name (for variable_map update)
|
||||
pub name: String,
|
||||
|
||||
/// Initial value (from preheader)
|
||||
pub init_value: ValueId,
|
||||
|
||||
/// Step value (from step block, back-edge)
|
||||
pub step_value: ValueId,
|
||||
|
||||
/// PHI destination (loop variable inside loop)
|
||||
pub phi_dst: ValueId,
|
||||
}
|
||||
// Phase 273 P3: CoreCarrierInfo removed (replaced by CorePhiInfo)
|
||||
|
||||
/// Phase 273 P1: Conditional plan
|
||||
#[derive(Debug, Clone)]
|
||||
|
||||
@ -12,7 +12,7 @@
|
||||
//! Lowerer processes CorePlan without any pattern knowledge.
|
||||
|
||||
use super::{
|
||||
CoreCarrierInfo, CoreEffectPlan, CoreLoopPlan, CorePhiInfo, CorePlan, DomainPlan,
|
||||
CoreEffectPlan, CoreLoopPlan, CorePhiInfo, CorePlan, DomainPlan,
|
||||
ScanWithInitPlan, SplitScanPlan,
|
||||
};
|
||||
use crate::mir::builder::control_flow::joinir::patterns::router::LoopPatternContext;
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
//! Phase 273 P1: PlanVerifier - CorePlan 不変条件検証 (fail-fast)
|
||||
//! Phase 273 P3: PlanVerifier - CorePlan 不変条件検証 (fail-fast)
|
||||
//!
|
||||
//! # Responsibilities
|
||||
//!
|
||||
@ -6,16 +6,20 @@
|
||||
//! - Fail fast on close-but-unsupported patterns
|
||||
//! - Prevent silent miscompilation
|
||||
//!
|
||||
//! # Invariants (V1-V6)
|
||||
//! # Invariants (V2-V9)
|
||||
//!
|
||||
//! - V1: Carrier completeness (name/init_value/step_value present)
|
||||
//! - V2: Condition validity (valid ValueId)
|
||||
//! - V3: Exit validity (Return in function, Break/Continue in loop)
|
||||
//! - V4: Seq non-empty
|
||||
//! - V5: If completeness (then_plans non-empty)
|
||||
//! - V6: ValueId validity (all ValueIds pre-generated)
|
||||
//! - V7: PHI non-empty (loops require at least one carrier)
|
||||
//! - V8: Frag entry matches header_bb
|
||||
//! - V9: block_effects contains header_bb
|
||||
//!
|
||||
//! Phase 273 P3: V1 (Carrier completeness) removed with CoreCarrierInfo
|
||||
|
||||
use super::{CoreCarrierInfo, CoreEffectPlan, CoreExitPlan, CoreIfPlan, CoreLoopPlan, CorePlan};
|
||||
use super::{CoreEffectPlan, CoreExitPlan, CoreIfPlan, CoreLoopPlan, CorePlan};
|
||||
use crate::mir::ValueId;
|
||||
|
||||
/// Phase 273 P1: PlanVerifier - CorePlan 不変条件検証 (fail-fast)
|
||||
@ -132,21 +136,7 @@ impl PlanVerifier {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// V1: Carrier completeness
|
||||
fn verify_carrier(carrier: &CoreCarrierInfo, depth: usize, index: usize) -> Result<(), String> {
|
||||
if carrier.name.is_empty() {
|
||||
return Err(format!(
|
||||
"[V1] Carrier[{}] at depth {} has empty name",
|
||||
index, depth
|
||||
));
|
||||
}
|
||||
|
||||
Self::verify_value_id_basic(carrier.init_value, depth, &format!("carrier[{}].init_value", index))?;
|
||||
Self::verify_value_id_basic(carrier.step_value, depth, &format!("carrier[{}].step_value", index))?;
|
||||
Self::verify_value_id_basic(carrier.phi_dst, depth, &format!("carrier[{}].phi_dst", index))?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
// Phase 273 P3: verify_carrier() removed (CoreCarrierInfo replaced by CorePhiInfo)
|
||||
|
||||
/// V5: If completeness
|
||||
fn verify_if(if_plan: &CoreIfPlan, depth: usize, in_loop: bool) -> Result<(), String> {
|
||||
|
||||
@ -1,143 +0,0 @@
|
||||
//! Phase 272 P0.1: Pattern6 Scan with Init - Emission Entrypoint
|
||||
//!
|
||||
//! ## Purpose
|
||||
//! Thin entrypoint for Pattern6 Frag construction and MIR terminator emission.
|
||||
//! This module only handles terminator wiring via EdgeCFG Frag API.
|
||||
//! Block allocation and value computation (len, substring, match check) are done by Pattern6.
|
||||
//!
|
||||
//! ## Pattern Structure
|
||||
//! ```nyash
|
||||
//! index_of(s, ch) {
|
||||
//! local i = 0
|
||||
//! loop(i < s.length()) {
|
||||
//! if s.substring(i, i + 1) == ch {
|
||||
//! return i
|
||||
//! }
|
||||
//! i = i + 1
|
||||
//! }
|
||||
//! return -1
|
||||
//! }
|
||||
//! ```
|
||||
//!
|
||||
//! ## P0 Scope
|
||||
//! - Forward scan only (step = 1)
|
||||
//! - Fixed needle (ch)
|
||||
//! - No ret_not_found_bb (after_bb handles AST return -1)
|
||||
//!
|
||||
//! ## Critical SSOT
|
||||
//! 1. Return in wires (not exits) - emit_frag() generates terminators from wires/branches only
|
||||
//! 2. after_bb has no terminator - let subsequent AST lowering handle "return -1"
|
||||
//! 3. Frag assembly is direct field access (no with_* API)
|
||||
//! 4. BranchStub/EdgeStub field names match current implementation
|
||||
//! 5. Return Void (loop as statement, not expression)
|
||||
|
||||
use crate::mir::builder::MirBuilder;
|
||||
use crate::mir::builder::control_flow::edgecfg::api::{
|
||||
BranchStub, EdgeStub, ExitKind, Frag, emit_frag,
|
||||
};
|
||||
use crate::mir::basic_block::{BasicBlockId, EdgeArgs};
|
||||
use crate::mir::join_ir::lowering::inline_boundary::JumpArgsLayout;
|
||||
use crate::mir::ValueId;
|
||||
|
||||
/// Emit Scan with Init EdgeCFG Fragment
|
||||
///
|
||||
/// ## Arguments
|
||||
/// - `b`: MirBuilder (for emit_frag access to current_function)
|
||||
/// - `header_bb`: Loop condition check block (i < s.length())
|
||||
/// - `body_bb`: Substring + match check + early return branch
|
||||
/// - `step_bb`: Increment i and jump back to header
|
||||
/// - `after_bb`: Normal loop exit (no terminator - subsequent AST lowering handles "return -1")
|
||||
/// - `ret_found_bb`: Early exit Return(i) block
|
||||
/// - `cond_loop`: ValueId for (i < s.length())
|
||||
/// - `cond_match`: ValueId for (ch == needle)
|
||||
/// - `i_found`: ValueId for loop variable i (return value for found case)
|
||||
///
|
||||
/// ## Frag Structure
|
||||
/// - **branches**:
|
||||
/// 1. header: cond_loop true→body, false→after
|
||||
/// 2. body: cond_match true→ret_found, false→step
|
||||
/// - **wires**:
|
||||
/// - step → header (Normal Jump)
|
||||
/// - ret_found_bb → Return(i) - **IN WIRES, NOT EXITS**
|
||||
/// - **exits**: empty (no upward propagation in P0)
|
||||
///
|
||||
/// ## Returns
|
||||
/// `Ok(())` - Frag emitted successfully
|
||||
/// `Err` - emit_frag failed or current_function is None
|
||||
pub(in crate::mir::builder) fn emit_scan_with_init_edgecfg(
|
||||
b: &mut MirBuilder,
|
||||
header_bb: BasicBlockId,
|
||||
body_bb: BasicBlockId,
|
||||
step_bb: BasicBlockId,
|
||||
after_bb: BasicBlockId,
|
||||
ret_found_bb: BasicBlockId,
|
||||
cond_loop: ValueId,
|
||||
cond_match: ValueId,
|
||||
i_found: ValueId,
|
||||
) -> Result<(), String> {
|
||||
// EdgeArgs::empty() helper
|
||||
let empty_args = EdgeArgs {
|
||||
layout: JumpArgsLayout::CarriersOnly,
|
||||
values: vec![],
|
||||
};
|
||||
|
||||
// Return(i) arguments (contains found index)
|
||||
let ret_found_args = EdgeArgs {
|
||||
layout: JumpArgsLayout::CarriersOnly,
|
||||
values: vec![i_found],
|
||||
};
|
||||
|
||||
// branches (BranchStub) - current field names
|
||||
let branches = vec![
|
||||
BranchStub {
|
||||
from: header_bb,
|
||||
cond: cond_loop,
|
||||
then_target: body_bb,
|
||||
then_args: empty_args.clone(),
|
||||
else_target: after_bb,
|
||||
else_args: empty_args.clone(),
|
||||
},
|
||||
BranchStub {
|
||||
from: body_bb,
|
||||
cond: cond_match,
|
||||
then_target: ret_found_bb,
|
||||
then_args: empty_args.clone(),
|
||||
else_target: step_bb,
|
||||
else_args: empty_args.clone(),
|
||||
},
|
||||
];
|
||||
|
||||
// wires (EdgeStub) - current field names
|
||||
let wires = vec![
|
||||
// step_bb → header_bb Jump (Normal)
|
||||
EdgeStub {
|
||||
from: step_bb,
|
||||
kind: ExitKind::Normal,
|
||||
target: Some(header_bb),
|
||||
args: empty_args,
|
||||
},
|
||||
// ret_found_bb Return(i) - THIS GOES IN WIRES!
|
||||
EdgeStub {
|
||||
from: ret_found_bb,
|
||||
kind: ExitKind::Return,
|
||||
target: None,
|
||||
args: ret_found_args,
|
||||
},
|
||||
// P0: No ret_not_found wire - after_bb handles AST return -1
|
||||
];
|
||||
|
||||
// Frag assembly (direct field access - no with_* API exists)
|
||||
let mut frag = Frag::new(header_bb);
|
||||
frag.branches = branches;
|
||||
frag.wires = wires;
|
||||
// exits is empty (no upward propagation in P0)
|
||||
|
||||
// emit_frag generates MIR terminators
|
||||
if let Some(ref mut func) = b.scope_ctx.current_function {
|
||||
emit_frag(func, &frag)?;
|
||||
} else {
|
||||
return Err("[emit_scan_with_init_edgecfg] current_function is None".to_string());
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@ -4,13 +4,13 @@
|
||||
//! - branch.rs: Branch/Jump 発行の薄い関数
|
||||
//! - phi.rs: PHI挿入の薄いラッパー(builder context extraction)
|
||||
//! - loop_predicate_scan.rs: Pattern8 bool predicate scan EdgeCFG Frag (Phase 269 P1)
|
||||
//! - loop_scan_with_init.rs: Pattern6 scan with init EdgeCFG Frag (Phase 272 P0.1)
|
||||
//! - loop_split_scan.rs: Pattern7 split scan EdgeCFG Frag (Phase 272 P0.2)
|
||||
//!
|
||||
//! Phase 273 P3: loop_scan_with_init.rs removed (replaced by generalized Frag API)
|
||||
|
||||
pub mod branch;
|
||||
pub mod compare;
|
||||
pub mod constant;
|
||||
pub(in crate::mir::builder) mod phi; // Phase 272 P0.2 Refactoring
|
||||
pub(in crate::mir::builder) mod loop_predicate_scan; // Phase 269 P1
|
||||
pub(in crate::mir::builder) mod loop_scan_with_init; // Phase 272 P0.1
|
||||
pub(in crate::mir::builder) mod loop_split_scan; // Phase 272 P0.2
|
||||
|
||||
@ -44,7 +44,6 @@ use crate::mir::join_ir::lowering::generic_type_resolver::GenericTypeResolver;
|
||||
// Phase 83: P3-D 既知メソッド戻り値型推論箱
|
||||
use crate::mir::join_ir::lowering::method_return_hint::MethodReturnHintBox;
|
||||
// Phase 84-2: Copy命令型伝播箱(ChatGPT Pro設計)
|
||||
use crate::mir::phi_core::copy_type_propagator::CopyTypePropagator;
|
||||
// Phase 84-3: PHI + Copy グラフ型推論箱(ChatGPT Pro設計)
|
||||
use crate::mir::phi_core::phi_type_resolver::PhiTypeResolver;
|
||||
|
||||
|
||||
@ -28,7 +28,6 @@ use std::collections::BTreeSet;
|
||||
#[cfg(feature = "normalized_dev")]
|
||||
use crate::mir::BindingId; // Phase 76+78: BindingId for promoted carriers
|
||||
|
||||
use crate::mir::join_ir::JoinFuncId;
|
||||
|
||||
/// Phase 227: CarrierRole - Distinguishes loop state carriers from condition-only carriers
|
||||
///
|
||||
|
||||
@ -44,7 +44,6 @@
|
||||
//! ```
|
||||
|
||||
use super::carrier_info::{CarrierRole, ExitReconnectMode};
|
||||
use crate::mir::join_ir::JoinFuncId;
|
||||
use crate::mir::ValueId;
|
||||
use std::collections::BTreeSet;
|
||||
|
||||
|
||||
@ -89,10 +89,9 @@
|
||||
//! jump_args_layout = CarriersOnly
|
||||
//! ```
|
||||
|
||||
use crate::ast::Span;
|
||||
use crate::mir::join_ir::{JoinContId, JoinFuncId};
|
||||
use crate::mir::join_ir::lowering::inline_boundary::JumpArgsLayout;
|
||||
use crate::mir::{BasicBlock, BasicBlockId, EffectMask, MirFunction, MirInstruction, ValueId};
|
||||
use crate::mir::{BasicBlock, BasicBlockId, MirFunction, MirInstruction, ValueId};
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use super::super::{join_func_name, JoinIrVmBridgeError};
|
||||
|
||||
@ -6,9 +6,7 @@
|
||||
//! - 関数署名の管理
|
||||
|
||||
use crate::mir::join_ir::{JoinFuncId, JoinFunction, JoinModule};
|
||||
use crate::mir::phi_core::copy_type_propagator::CopyTypePropagator;
|
||||
use crate::mir::phi_core::phi_type_resolver::PhiTypeResolver;
|
||||
use crate::mir::{BasicBlockId, EffectMask, FunctionSignature, MirFunction, MirInstruction, MirModule, MirType};
|
||||
use crate::mir::{BasicBlockId, EffectMask, FunctionSignature, MirFunction, MirModule, MirType};
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use super::join_func_name;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
use crate::mir::function::MirFunction;
|
||||
use crate::mir::verification::utils;
|
||||
use crate::mir::verification_types::VerificationError;
|
||||
use crate::mir::{BasicBlockId, MirInstruction, ValueId};
|
||||
use crate::mir::{BasicBlockId, ValueId};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
/// Verify CFG references and reachability
|
||||
|
||||
Reference in New Issue
Block a user