Span trace utilities and runner source hint
This commit is contained in:
@ -811,6 +811,7 @@ impl<'a> LoopBuilder<'a> {
|
||||
// Phi命令は必ずブロックの先頭に配置。ただし同一dstの既存PHIがある場合は差し替える。
|
||||
let mut replaced = false;
|
||||
let mut idx = 0;
|
||||
let span = self.parent_builder.current_span;
|
||||
while idx < block.instructions.len() {
|
||||
match &mut block.instructions[idx] {
|
||||
MirInstruction::Phi {
|
||||
@ -818,6 +819,13 @@ impl<'a> LoopBuilder<'a> {
|
||||
inputs: ins,
|
||||
} if *d == dst => {
|
||||
*ins = inputs.clone();
|
||||
if block.instruction_spans.len() <= idx {
|
||||
// Backfill missing spans to preserve alignment after legacy inserts.
|
||||
while block.instruction_spans.len() <= idx {
|
||||
block.instruction_spans.push(crate::ast::Span::unknown());
|
||||
}
|
||||
}
|
||||
block.instruction_spans[idx] = span;
|
||||
replaced = true;
|
||||
break;
|
||||
}
|
||||
@ -833,6 +841,7 @@ impl<'a> LoopBuilder<'a> {
|
||||
inputs: inputs.clone(),
|
||||
};
|
||||
block.instructions.insert(0, phi_inst);
|
||||
block.instruction_spans.insert(0, span);
|
||||
}
|
||||
if dbg {
|
||||
eprintln!("[DEBUG] ✅ PHI instruction inserted at position 0");
|
||||
@ -895,7 +904,8 @@ impl<'a> LoopBuilder<'a> {
|
||||
// =============================================================
|
||||
// Variable Map Utilities — snapshots and rebinding
|
||||
// =============================================================
|
||||
fn get_current_variable_map(&self) -> BTreeMap<String, ValueId> { // Phase 25.1: BTreeMap化
|
||||
fn get_current_variable_map(&self) -> BTreeMap<String, ValueId> {
|
||||
// Phase 25.1: BTreeMap化
|
||||
self.parent_builder.variable_map.clone()
|
||||
}
|
||||
|
||||
@ -921,6 +931,8 @@ impl<'a> LoopBuilder<'a> {
|
||||
}
|
||||
|
||||
fn build_statement(&mut self, stmt: ASTNode) -> Result<ValueId, String> {
|
||||
// Preserve the originating span for loop-local control instructions (break/continue/phi).
|
||||
self.parent_builder.current_span = stmt.span();
|
||||
match stmt {
|
||||
// Ensure nested bare blocks inside loops are lowered with loop-aware semantics
|
||||
ASTNode::Program { statements, .. } => {
|
||||
@ -1210,15 +1222,15 @@ impl<'a> LoopBuilder<'a> {
|
||||
// Phase 26-F-3: ループ内if-mergeコンテキスト設定(ChatGPT設計)
|
||||
// pre_if_var_mapにある全変数をcarrier候補として扱う(保守的だが安全)
|
||||
// 理由: ループ内変数は全てキャリア候補の可能性があるため
|
||||
let carrier_names: std::collections::BTreeSet<String> =
|
||||
pre_if_var_map.keys()
|
||||
.filter(|name| !name.starts_with("__pin$")) // 一時変数除外
|
||||
.cloned()
|
||||
.collect();
|
||||
let carrier_names: std::collections::BTreeSet<String> = pre_if_var_map
|
||||
.keys()
|
||||
.filter(|name| !name.starts_with("__pin$")) // 一時変数除外
|
||||
.cloned()
|
||||
.collect();
|
||||
|
||||
phi_builder.set_if_context(
|
||||
true, // in_loop_body = true
|
||||
carrier_names
|
||||
true, // in_loop_body = true
|
||||
carrier_names,
|
||||
);
|
||||
|
||||
// Phase 26-F-2: IfBodyLocalMergeBox は phi_builder_box.rs 内で直接使用
|
||||
|
||||
Reference in New Issue
Block a user