JoinIR/SSA/Stage-3: sync CURRENT_TASK and dev env

This commit is contained in:
nyash-codex
2025-12-01 11:10:46 +09:00
parent a3d5bacc55
commit 8633224061
52 changed files with 974 additions and 256 deletions

View File

@ -58,10 +58,7 @@ impl LoopScopeShape {
Some(result)
}
fn build_from_intake(
loop_form: &LoopForm,
intake: &LoopFormIntake,
) -> Option<Self> {
fn build_from_intake(loop_form: &LoopForm, intake: &LoopFormIntake) -> Option<Self> {
let layout = block_layout(loop_form);
if std::env::var("NYASH_LOOPSCOPE_DEBUG").is_ok() {
@ -80,13 +77,8 @@ impl LoopScopeShape {
let carriers: BTreeSet<String> = intake.carrier_ordered.iter().cloned().collect();
let variable_definitions = collect_variable_definitions(intake, &layout);
let (body_locals, exit_live) = classify_body_and_exit(
intake,
&pinned,
&carriers,
&variable_definitions,
&layout,
);
let (body_locals, exit_live) =
classify_body_and_exit(intake, &pinned, &carriers, &variable_definitions, &layout);
let progress_carrier = carriers.iter().next().cloned();
@ -150,10 +142,7 @@ fn collect_variable_definitions(
for (bb, snap) in &intake.exit_snapshots {
for var_name in snap.keys() {
var_defs
.entry(var_name.clone())
.or_default()
.insert(*bb);
var_defs.entry(var_name.clone()).or_default().insert(*bb);
}
}

View File

@ -18,14 +18,16 @@ pub enum LoopVarClass {
impl LoopVarClass {
#[cfg(test)]
pub fn needs_exit_phi(self) -> bool {
matches!(self, LoopVarClass::Pinned | LoopVarClass::Carrier | LoopVarClass::BodyLocalExit)
matches!(
self,
LoopVarClass::Pinned | LoopVarClass::Carrier | LoopVarClass::BodyLocalExit
)
}
#[cfg(test)]
pub fn needs_header_phi(self) -> bool {
matches!(self, LoopVarClass::Pinned | LoopVarClass::Carrier)
}
}
/// ループ変数スコープの統合ビュー

View File

@ -151,9 +151,7 @@ mod tests {
pinned: vec!["s".to_string()].into_iter().collect(),
carriers: vec!["i".to_string()].into_iter().collect(),
body_locals: BTreeSet::new(),
exit_live: vec!["s".to_string(), "i".to_string()]
.into_iter()
.collect(),
exit_live: vec!["s".to_string(), "i".to_string()].into_iter().collect(),
progress_carrier: Some("i".to_string()),
variable_definitions: BTreeMap::new(),
}

View File

@ -1,6 +1,6 @@
use super::shape::LoopVarClass;
use super::*;
use crate::mir::join_ir::lowering::loop_form_intake::LoopFormIntake;
use super::shape::LoopVarClass;
use crate::mir::{BasicBlockId, MirQuery, ValueId};
use std::collections::{BTreeMap, BTreeSet};
@ -362,9 +362,13 @@ fn test_is_available_in_all_phase48_5_future() {
);
variable_definitions.insert(
"i".to_string(),
vec![BasicBlockId::new(2), BasicBlockId::new(3), BasicBlockId::new(4)]
.into_iter()
.collect(),
vec![
BasicBlockId::new(2),
BasicBlockId::new(3),
BasicBlockId::new(4),
]
.into_iter()
.collect(),
);
let scope = LoopScopeShape {
@ -391,7 +395,11 @@ fn test_is_available_in_all_phase48_5_future() {
// i は block 2, 3, 4 で定義 → すべて要求しても true
assert!(scope.is_available_in_all(
"i",
&[BasicBlockId::new(2), BasicBlockId::new(3), BasicBlockId::new(4)]
&[
BasicBlockId::new(2),
BasicBlockId::new(3),
BasicBlockId::new(4)
]
));
// unknown は variable_definitions にない → false
@ -469,7 +477,11 @@ fn test_variable_definitions_partial_availability() {
// s は全 exit で利用可能
assert!(scope.is_available_in_all(
"s",
&[BasicBlockId::new(20), BasicBlockId::new(21), BasicBlockId::new(22)]
&[
BasicBlockId::new(20),
BasicBlockId::new(21),
BasicBlockId::new(22)
]
));
// y は exit1 でのみ利用可能