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>
72 lines
2.3 KiB
Rust
72 lines
2.3 KiB
Rust
//! Small loop utilities for MirBuilder
|
|
use super::{BasicBlockId, MirBuilder};
|
|
|
|
/// Push loop context (header/exit) onto the MirBuilder stacks.
|
|
pub(crate) fn push_loop_context(
|
|
builder: &mut super::MirBuilder,
|
|
header: BasicBlockId,
|
|
exit: BasicBlockId,
|
|
) {
|
|
builder.loop_header_stack.push(header);
|
|
builder.loop_exit_stack.push(exit);
|
|
}
|
|
|
|
/// Pop loop context (header/exit) from the MirBuilder stacks.
|
|
pub(crate) fn pop_loop_context(builder: &mut super::MirBuilder) {
|
|
let _ = builder.loop_header_stack.pop();
|
|
let _ = builder.loop_exit_stack.pop();
|
|
}
|
|
|
|
/// Peek current loop header block id
|
|
#[allow(dead_code)]
|
|
#[allow(dead_code)]
|
|
pub(crate) fn current_header(builder: &super::MirBuilder) -> Option<BasicBlockId> {
|
|
builder.loop_header_stack.last().copied()
|
|
}
|
|
|
|
/// Peek current loop exit block id
|
|
pub(crate) fn current_exit(builder: &super::MirBuilder) -> Option<BasicBlockId> {
|
|
builder.loop_exit_stack.last().copied()
|
|
}
|
|
|
|
/// Returns true if the builder is currently inside at least one loop context.
|
|
#[allow(dead_code)]
|
|
#[allow(dead_code)]
|
|
pub(crate) fn in_loop(builder: &super::MirBuilder) -> bool {
|
|
!builder.loop_header_stack.is_empty()
|
|
}
|
|
|
|
/// Current loop nesting depth (0 means not in a loop).
|
|
#[allow(dead_code)]
|
|
#[allow(dead_code)]
|
|
pub(crate) fn depth(builder: &super::MirBuilder) -> usize {
|
|
builder.loop_header_stack.len()
|
|
}
|
|
|
|
/// Add predecessor edge metadata to a basic block.
|
|
/// 📦 Hotfix 6: Auto-create block if it doesn't exist yet
|
|
/// This ensures add_predecessor() works even before start_new_block() is called.
|
|
pub(crate) fn add_predecessor(
|
|
builder: &mut MirBuilder,
|
|
block: BasicBlockId,
|
|
pred: BasicBlockId,
|
|
) -> Result<(), String> {
|
|
if let Some(ref mut function) = builder.current_function {
|
|
// 📦 Hotfix 6: Ensure block exists (same as start_new_block logic)
|
|
// Create block if not present, without changing current_block
|
|
if !function.blocks.contains_key(&block) {
|
|
function.add_block(super::BasicBlock::new(block));
|
|
}
|
|
|
|
if let Some(bb) = function.get_block_mut(block) {
|
|
bb.add_predecessor(pred);
|
|
return Ok(());
|
|
}
|
|
return Err(format!(
|
|
"Block {} not found (impossible after auto-create)",
|
|
block
|
|
));
|
|
}
|
|
Err("No current function".to_string())
|
|
}
|