Normalize passes keep spans and clean warnings

This commit is contained in:
nyash-codex
2025-11-24 15:02:51 +09:00
parent 466e636af6
commit da1a5558e5
40 changed files with 547 additions and 362 deletions

View File

@ -3,6 +3,7 @@ use super::merge::new_block;
use super::ternary;
use super::BridgeEnv;
use crate::mir::{BasicBlockId, ConstValue, EffectMask, MirFunction, MirInstruction, ValueId};
use crate::ast::Span;
use std::collections::BTreeMap;
use super::super::ast::ExprV0;
@ -290,7 +291,13 @@ pub(super) fn lower_expr_with_scope<S: VarScope>(
} else {
inputs.push((fall_bb, rval));
}
crate::mir::ssot::cf_common::insert_phi_at_head(f, merge_bb, out, inputs);
crate::mir::ssot::cf_common::insert_phi_at_head_spanned(
f,
merge_bb,
out,
inputs,
Span::unknown(),
);
Ok((out, merge_bb))
}
ExprV0::Call { name, args } => {

View File

@ -23,10 +23,10 @@
use super::super::ast::ExprV0;
use super::super::ast::StmtV0;
use super::{lower_stmt_list_with_vars, new_block, BridgeEnv, LoopContext};
use crate::mir::phi_core::loop_snapshot_merge::LoopSnapshotMergeBox;
use crate::mir::phi_core::loopform_builder::{LoopFormBuilder, LoopFormOps};
use crate::mir::phi_core::phi_input_collector::PhiInputCollector;
use crate::mir::{BasicBlockId, MirFunction, MirInstruction, ValueId};
use crate::ast::Span;
use std::collections::BTreeMap;
/// LoopForm v2 用の JSON bridge 実装。
@ -143,7 +143,13 @@ impl LoopFormOps for LoopFormJsonOps<'_> {
dst: ValueId,
inputs: Vec<(BasicBlockId, ValueId)>,
) -> Result<(), String> {
crate::mir::ssot::cf_common::insert_phi_at_head(self.f, self.current_block, dst, inputs);
crate::mir::ssot::cf_common::insert_phi_at_head_spanned(
self.f,
self.current_block,
dst,
inputs,
Span::unknown(),
);
Ok(())
}
@ -363,11 +369,12 @@ pub(super) fn lower_loop_stmt(
// 異なる値を持つ場合は PHI ノードを continue_merge_bb に生成
let final_inputs = collector.finalize();
let phi_id = ops.f.next_value_id();
crate::mir::ssot::cf_common::insert_phi_at_head(
crate::mir::ssot::cf_common::insert_phi_at_head_spanned(
ops.f,
continue_merge_bb,
phi_id,
final_inputs,
Span::unknown(),
);
phi_id
};

View File

@ -5,6 +5,7 @@ use super::expr::{lower_expr_with_scope, VarScope};
use super::merge::new_block;
use super::BridgeEnv;
use crate::mir::{BasicBlockId, CompareOp, ConstValue, MirFunction, MirInstruction, ValueId};
use crate::ast::Span;
pub(super) fn lower_match_expr_with_scope<S: VarScope>(
env: &BridgeEnv,
@ -85,6 +86,12 @@ pub(super) fn lower_match_expr_with_scope<S: VarScope>(
let out = f.next_value_id();
// フェーズM.2: PHI統一処理no_phi分岐削除
let inputs = phi_inputs;
crate::mir::ssot::cf_common::insert_phi_at_head(f, merge_bb, out, inputs);
crate::mir::ssot::cf_common::insert_phi_at_head_spanned(
f,
merge_bb,
out,
inputs,
Span::unknown(),
);
Ok((out, merge_bb))
}

View File

@ -1,4 +1,5 @@
use crate::mir::{BasicBlock, BasicBlockId, MirFunction, MirInstruction, ValueId};
use crate::ast::Span;
fn next_block_id(f: &MirFunction) -> BasicBlockId {
let mut mx = 0u32;
@ -41,11 +42,12 @@ pub(super) fn merge_values(
bb.add_instruction_before_terminator(MirInstruction::Copy { dst, src: val_b });
}
} else {
crate::mir::ssot::cf_common::insert_phi_at_head(
crate::mir::ssot::cf_common::insert_phi_at_head_spanned(
f,
merge_bb,
dst,
vec![(pred_a, val_a), (pred_b, val_b)],
Span::unknown(),
);
}
dst

View File

@ -7,6 +7,7 @@ use super::super::ast::ExprV0;
use super::merge::new_block;
use super::BridgeEnv;
use crate::mir::{BasicBlockId, MirFunction, ValueId};
use crate::ast::Span;
use super::expr::{lower_expr_with_scope, VarScope};
@ -40,6 +41,12 @@ pub(super) fn lower_ternary_expr_with_scope<S: VarScope>(
let out = f.next_value_id();
// フェーズM.2: PHI統一処理no_phi分岐削除
let inputs = vec![(tend, tval), (eend, eval)];
crate::mir::ssot::cf_common::insert_phi_at_head(f, merge_bb, out, inputs);
crate::mir::ssot::cf_common::insert_phi_at_head_spanned(
f,
merge_bb,
out,
inputs,
Span::unknown(),
);
Ok((out, merge_bb))
}

View File

@ -1,6 +1,7 @@
use super::super::ast::{CatchV0, StmtV0};
use super::{lower_stmt_list_with_vars, new_block, BridgeEnv, LoopContext};
use crate::mir::{BasicBlockId, MirFunction, MirInstruction, ValueId};
use crate::ast::Span;
use std::collections::BTreeMap;
pub(super) fn lower_try_stmt(
@ -102,8 +103,12 @@ pub(super) fn lower_try_stmt(
if let Some(_bb) = f.get_block_mut(catch_bb) {
let mut inputs = incoming_exc.clone();
inputs.sort_by_key(|(bbid, _)| bbid.0);
crate::mir::ssot::cf_common::insert_phi_at_head(
f, catch_bb, phi_dst, inputs,
crate::mir::ssot::cf_common::insert_phi_at_head_spanned(
f,
catch_bb,
phi_dst,
inputs,
Span::unknown(),
);
}
catch_vars.insert(param.clone(), phi_dst);
@ -170,7 +175,13 @@ pub(super) fn lower_try_stmt(
}
if let Some(_bb) = f.get_block_mut(finally_block) {
for (dst, inputs) in phi_entries {
crate::mir::ssot::cf_common::insert_phi_at_head(f, finally_block, dst, inputs);
crate::mir::ssot::cf_common::insert_phi_at_head_spanned(
f,
finally_block,
dst,
inputs,
Span::unknown(),
);
}
}
let mut finally_vars = merged_vars.clone();
@ -226,7 +237,13 @@ pub(super) fn lower_try_stmt(
}
if let Some(_bb) = f.get_block_mut(exit_bb) {
for (dst, inputs) in phi_entries {
crate::mir::ssot::cf_common::insert_phi_at_head(f, exit_bb, dst, inputs);
crate::mir::ssot::cf_common::insert_phi_at_head_spanned(
f,
exit_bb,
dst,
inputs,
Span::unknown(),
);
}
}
*vars = merged_vars;
@ -326,7 +343,13 @@ pub(super) fn lower_try_stmt(
// フェーズM.2: PHI統一処理no_phi分岐削除
if let Some(_bb) = f.get_block_mut(finally_block) {
for (dst, inputs) in phi_entries {
crate::mir::ssot::cf_common::insert_phi_at_head(f, finally_block, dst, inputs);
crate::mir::ssot::cf_common::insert_phi_at_head_spanned(
f,
finally_block,
dst,
inputs,
Span::unknown(),
);
}
}
let mut finally_vars = merged_vars.clone();
@ -377,7 +400,13 @@ pub(super) fn lower_try_stmt(
// フェーズM.2: PHI統一処理no_phi分岐削除
if let Some(_bb) = f.get_block_mut(exit_bb) {
for (dst, inputs) in phi_entries {
crate::mir::ssot::cf_common::insert_phi_at_head(f, exit_bb, dst, inputs);
crate::mir::ssot::cf_common::insert_phi_at_head_spanned(
f,
exit_bb,
dst,
inputs,
Span::unknown(),
);
}
}
*vars = merged_vars;

View File

@ -101,14 +101,12 @@ fn print_source_snippet(filename: &str, src: &str, line: usize, col: Option<usiz
if line <= lines.len() {
let text = lines[line - 1];
let mut underline = String::new();
let mut idx = 0usize;
for (i, ch) in text.chars().enumerate() {
if i + 1 >= col {
break;
}
// Preserve tabs visually; spaces elsewhere
underline.push(if ch == '\t' { '\t' } else { ' ' });
idx = i;
}
let pad = " "; // align under " LNNNNN |"
eprintln!(" {}{}^", pad, underline);

View File

@ -178,6 +178,7 @@ impl<'a> PreludeManagerBox<'a> {
});
current_line += main_lines;
}
let _ = current_line;
if trace {
crate::runner::trace::log(format!(

View File

@ -999,6 +999,7 @@ pub fn merge_prelude_text(
});
current_line += main_lines;
}
let _ = current_line;
if trace {
crate::runner::trace::log(format!(

View File

@ -21,7 +21,7 @@ mod modules;
use super::NyashRunner;
use crate::cli::CliGroups;
use std::{path::Path, process};
use std::path::Path;
impl NyashRunner {
/// If enabled, run the Stage-1 CLI stub as a child process and return its exit code.