chore: Phase 25.1 完了 - LoopForm v2/Stage1 CLI/環境変数削減 + Phase 26-D からの変更
Phase 25.1 完了成果: - ✅ LoopForm v2 テスト・ドキュメント・コメント完備 - 4ケース(A/B/C/D)完全テストカバレッジ - 最小再現ケース作成(SSAバグ調査用) - SSOT文書作成(loopform_ssot.md) - 全ソースに [LoopForm] コメントタグ追加 - ✅ Stage-1 CLI デバッグ環境構築 - stage1_cli.hako 実装 - stage1_bridge.rs ブリッジ実装 - デバッグツール作成(stage1_debug.sh/stage1_minimal.sh) - アーキテクチャ改善提案文書 - ✅ 環境変数削減計画策定 - 25変数の完全調査・分類 - 6段階削減ロードマップ(25→5、80%削減) - 即時削除可能変数特定(NYASH_CONFIG/NYASH_DEBUG) Phase 26-D からの累積変更: - PHI実装改善(ExitPhiBuilder/HeaderPhiBuilder等) - MIRビルダーリファクタリング - 型伝播・最適化パス改善 - その他約300ファイルの累積変更 🎯 技術的成果: - SSAバグ根本原因特定(条件分岐内loop変数変更) - Region+next_iパターン適用完了(UsingCollectorBox等) - LoopFormパターン文書化・テスト化完了 - セルフホスティング基盤強化 Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: ChatGPT <noreply@openai.com> Co-Authored-By: Task Assistant <task@anthropic.com>
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
/*!
|
||||
* Control Flow Utilities - 制御フロー処理の共通ユーティリティ
|
||||
*
|
||||
*
|
||||
* PHI incoming修正とブロック終端検出の汎用関数群
|
||||
* フェーズS(即効止血)からフェーズL(根本解決)まで共通利用
|
||||
*/
|
||||
@ -8,9 +8,9 @@
|
||||
use super::super::{BasicBlockId, MirBuilder};
|
||||
|
||||
/// **外部関数**: 現在のブロックが終端済みかチェック
|
||||
///
|
||||
///
|
||||
/// loop_builder.rsで3箇所重複していた処理を統一
|
||||
///
|
||||
///
|
||||
/// # 使用例
|
||||
/// ```rust
|
||||
/// if is_current_block_terminated(builder)? {
|
||||
@ -18,9 +18,10 @@ use super::super::{BasicBlockId, MirBuilder};
|
||||
/// }
|
||||
/// ```
|
||||
pub fn is_current_block_terminated(builder: &MirBuilder) -> Result<bool, String> {
|
||||
let cur_id = builder.current_block
|
||||
let cur_id = builder
|
||||
.current_block
|
||||
.ok_or_else(|| "No current block".to_string())?;
|
||||
|
||||
|
||||
if let Some(ref function) = builder.current_function {
|
||||
if let Some(bb) = function.get_block(cur_id) {
|
||||
Ok(bb.is_terminated())
|
||||
@ -33,14 +34,14 @@ pub fn is_current_block_terminated(builder: &MirBuilder) -> Result<bool, String>
|
||||
}
|
||||
|
||||
/// **外部関数**: 実到達ブロックを捕捉してJump発行
|
||||
///
|
||||
///
|
||||
/// 最強モード指摘の「実到達predecessor捕捉」を汎用化
|
||||
/// break/continue後の到達不能ブロックは除外
|
||||
///
|
||||
///
|
||||
/// # 戻り値
|
||||
/// - `Some(predecessor_id)`: Jump発行済み、PHI incomingに使用可能
|
||||
/// - `None`: 既に終端済み、PHI incomingから除外すべき
|
||||
///
|
||||
///
|
||||
/// # 使用例
|
||||
/// ```rust
|
||||
/// if let Some(pred_id) = capture_actual_predecessor_and_jump(builder, merge_bb)? {
|
||||
@ -51,16 +52,17 @@ pub fn capture_actual_predecessor_and_jump(
|
||||
builder: &mut MirBuilder,
|
||||
target_block: BasicBlockId,
|
||||
) -> Result<Option<BasicBlockId>, String> {
|
||||
let cur_id = builder.current_block
|
||||
let cur_id = builder
|
||||
.current_block
|
||||
.ok_or_else(|| "No current block".to_string())?;
|
||||
|
||||
|
||||
let need_jump = !is_current_block_terminated(builder)?;
|
||||
|
||||
|
||||
if need_jump {
|
||||
// Jump発行前に実到達ブロックID捕捉(重要!)
|
||||
// 既存control_flowモジュールと同じパターンを使用
|
||||
builder.emit_instruction(super::super::MirInstruction::Jump {
|
||||
target: target_block
|
||||
builder.emit_instruction(super::super::MirInstruction::Jump {
|
||||
target: target_block,
|
||||
})?;
|
||||
Ok(Some(cur_id))
|
||||
} else {
|
||||
@ -70,10 +72,10 @@ pub fn capture_actual_predecessor_and_jump(
|
||||
}
|
||||
|
||||
/// **外部関数**: 条件付きPHI incoming収集
|
||||
///
|
||||
///
|
||||
/// 到達可能な場合のみincomingをリストに追加
|
||||
/// フェーズM、フェーズLでの型安全性向上にも対応
|
||||
///
|
||||
///
|
||||
/// # 使用例
|
||||
/// ```rust
|
||||
/// let mut incomings = Vec::new();
|
||||
@ -92,10 +94,10 @@ pub fn collect_phi_incoming_if_reachable(
|
||||
}
|
||||
|
||||
/// **外部関数**: 終端チェック付きステートメント実行
|
||||
///
|
||||
///
|
||||
/// build_statement後の終端チェックを自動化
|
||||
/// フェーズSでの「終端ガード徹底」を支援
|
||||
///
|
||||
///
|
||||
/// # 戻り値
|
||||
/// - `Ok(true)`: 正常実行、継続可能
|
||||
/// - `Ok(false)`: 終端済み、ループ脱出すべき
|
||||
@ -105,7 +107,7 @@ pub fn execute_statement_with_termination_check(
|
||||
statement: crate::ast::ASTNode,
|
||||
) -> Result<bool, String> {
|
||||
let _result = builder.build_expression(statement)?;
|
||||
|
||||
|
||||
// 終端チェック(統一処理)
|
||||
let terminated = is_current_block_terminated(builder)?;
|
||||
Ok(!terminated)
|
||||
@ -114,9 +116,9 @@ pub fn execute_statement_with_termination_check(
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
|
||||
// ユニットテスト(将来追加)
|
||||
// - 終端検出の正確性
|
||||
// - 実到達ブロック捕捉の正確性
|
||||
// - PHI incoming除外の正確性
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
/*!
|
||||
* MIR Utilities - Phase 15 段階的根治戦略の共通ユーティリティ
|
||||
*
|
||||
*
|
||||
* フェーズS: 即効止血
|
||||
* フェーズM: PHI一本化
|
||||
* フェーズL: 根本解決
|
||||
*
|
||||
*
|
||||
* 全フェーズで使用する汎用関数を提供
|
||||
*/
|
||||
|
||||
@ -13,10 +13,8 @@ pub mod phi_helpers;
|
||||
|
||||
// 外部公開API
|
||||
pub use control_flow::{
|
||||
is_current_block_terminated,
|
||||
capture_actual_predecessor_and_jump,
|
||||
collect_phi_incoming_if_reachable,
|
||||
execute_statement_with_termination_check,
|
||||
capture_actual_predecessor_and_jump, collect_phi_incoming_if_reachable,
|
||||
execute_statement_with_termination_check, is_current_block_terminated,
|
||||
};
|
||||
|
||||
// PHI挿入ヘルパー(MirBuilderのextension methodsとして実装)
|
||||
|
||||
@ -25,8 +25,8 @@
|
||||
* ```
|
||||
*/
|
||||
|
||||
use crate::mir::{BasicBlockId, MirInstruction, ValueId};
|
||||
use crate::mir::builder::MirBuilder;
|
||||
use crate::mir::{BasicBlockId, MirInstruction, ValueId};
|
||||
|
||||
/// PHI挿入ヘルパー - MirBuilderへのextension methods
|
||||
impl MirBuilder {
|
||||
@ -64,9 +64,9 @@ impl MirBuilder {
|
||||
// This prevents PHI dst ValueIds from colliding with function-local IDs allocated later.
|
||||
// Same pattern as pin_to_slot() and the loop builder fix in e2d061d1.
|
||||
let phi_val = if let Some(ref mut f) = self.current_function {
|
||||
f.next_value_id() // Function context: use local ID allocator
|
||||
f.next_value_id() // Function context: use local ID allocator
|
||||
} else {
|
||||
self.value_gen.next() // Module context: use global ID allocator
|
||||
self.value_gen.next() // Module context: use global ID allocator
|
||||
};
|
||||
|
||||
// 統一された挿入ロジック(既存パターンと完全互換)
|
||||
@ -75,7 +75,10 @@ impl MirBuilder {
|
||||
crate::mir::ssot::cf_common::insert_phi_at_head(func, cur_bb, phi_val, inputs);
|
||||
} else {
|
||||
// フォールバック: 直接emit(主にテストや特殊ケース用)
|
||||
self.emit_instruction(MirInstruction::Phi { dst: phi_val, inputs })?;
|
||||
self.emit_instruction(MirInstruction::Phi {
|
||||
dst: phi_val,
|
||||
inputs,
|
||||
})?;
|
||||
}
|
||||
|
||||
Ok(phi_val)
|
||||
@ -152,7 +155,11 @@ impl MirBuilder {
|
||||
/// }
|
||||
/// ```
|
||||
#[inline]
|
||||
pub fn insert_phi_single(&mut self, pred: BasicBlockId, value: ValueId) -> Result<ValueId, String> {
|
||||
pub fn insert_phi_single(
|
||||
&mut self,
|
||||
pred: BasicBlockId,
|
||||
value: ValueId,
|
||||
) -> Result<ValueId, String> {
|
||||
self.insert_phi(vec![(pred, value)])
|
||||
}
|
||||
|
||||
@ -205,7 +212,10 @@ impl MirBuilder {
|
||||
updated_value: ValueId,
|
||||
) -> Result<ValueId, String> {
|
||||
// ループヘッダーPHIは論理的に[entry, backedge]の順序が自然
|
||||
self.insert_phi(vec![(entry_pred, init_value), (backedge_pred, updated_value)])
|
||||
self.insert_phi(vec![
|
||||
(entry_pred, init_value),
|
||||
(backedge_pred, updated_value),
|
||||
])
|
||||
}
|
||||
|
||||
/// **短絡評価用PHI挿入** - AND/ORの合流点用
|
||||
|
||||
Reference in New Issue
Block a user