refactor(mir): Phase 139-P3-B - RoutingDecision を enum 対応 + レガシー削除

- RoutingDecision の missing_caps を Vec<CapabilityTag> に変更(型安全化)
- error_tags は to_tag() メソッドで自動生成
- 全 callsite を enum variant に修正
- capability_tags モジュール(文字列定数群)を完全削除
- 全テスト PASS(型安全性向上を確認)
- フォーマット適用
This commit is contained in:
nyash-codex
2025-12-16 07:02:14 +09:00
parent 146f14a019
commit e404746612
106 changed files with 1475 additions and 1017 deletions

View File

@ -37,7 +37,6 @@ pub enum ShapeCapabilityKind {
/// Selfhost P3 if-sum family
SelfhostP3IfSum,
// Future: Other P2 patterns
// P2MidAtOfLoop,
// P2HeavyString,
@ -100,8 +99,14 @@ pub enum NormalizedDevShape {
type Detector = fn(&JoinModule) -> bool;
const SHAPE_DETECTORS: &[(NormalizedDevShape, Detector)] = &[
(NormalizedDevShape::Pattern1Mini, detectors::is_pattern1_mini),
(NormalizedDevShape::Pattern2Mini, detectors::is_pattern2_mini),
(
NormalizedDevShape::Pattern1Mini,
detectors::is_pattern1_mini,
),
(
NormalizedDevShape::Pattern2Mini,
detectors::is_pattern2_mini,
),
(
NormalizedDevShape::JsonparserSkipWsMini,
detectors::is_jsonparser_skip_ws_mini,
@ -552,18 +557,16 @@ mod detectors {
let has_select = loop_func.body.iter().any(|inst| match inst {
JoinInst::Select { .. } => true,
JoinInst::Compute(mir_inst) => matches!(
mir_inst,
crate::mir::join_ir::MirLikeInst::Select { .. }
),
JoinInst::Compute(mir_inst) => {
matches!(mir_inst, crate::mir::join_ir::MirLikeInst::Select { .. })
}
_ => false,
});
let has_boxcall = loop_func.body.iter().any(|inst| match inst {
JoinInst::Compute(mir_inst) => matches!(
mir_inst,
crate::mir::join_ir::MirLikeInst::BoxCall { .. }
),
JoinInst::Compute(mir_inst) => {
matches!(mir_inst, crate::mir::join_ir::MirLikeInst::BoxCall { .. })
}
_ => false,
});
@ -601,8 +604,7 @@ mod detectors {
.iter()
.any(|inst| matches!(inst, JoinInst::Call { k_next: None, .. }));
let param_set: std::collections::BTreeSet<_> =
loop_step.params.iter().copied().collect();
let param_set: std::collections::BTreeSet<_> = loop_step.params.iter().copied().collect();
let has_ge_compare_between_params = loop_step.body.iter().any(|inst| match inst {
JoinInst::Compute(mir_inst) => match mir_inst {
@ -617,10 +619,9 @@ mod detectors {
});
let has_boxcall = loop_step.body.iter().any(|inst| match inst {
JoinInst::Compute(mir_inst) => matches!(
mir_inst,
crate::mir::join_ir::MirLikeInst::BoxCall { .. }
),
JoinInst::Compute(mir_inst) => {
matches!(mir_inst, crate::mir::join_ir::MirLikeInst::BoxCall { .. })
}
_ => false,
});
@ -667,10 +668,9 @@ mod detectors {
// Phase 220: Select can be either JoinInst::Select or Compute(MirLikeInst::Select)
let has_select = loop_step.body.iter().any(|inst| match inst {
JoinInst::Select { .. } => true,
JoinInst::Compute(mir_inst) => matches!(
mir_inst,
crate::mir::join_ir::MirLikeInst::Select { .. }
),
JoinInst::Compute(mir_inst) => {
matches!(mir_inst, crate::mir::join_ir::MirLikeInst::Select { .. })
}
_ => false,
});
@ -896,7 +896,7 @@ mod detectors {
&& has_select
&& has_tail_call
&& reasonable_param_count
&& k_exit_jumps_count == 1 // Exactly one loop break (not early return)
&& k_exit_jumps_count == 1 // Exactly one loop break (not early return)
}
pub(crate) fn is_jsonparser_parse_array_continue_skip_ws(module: &JoinModule) -> bool {
@ -952,7 +952,7 @@ mod detectors {
&& has_select
&& has_tail_call
&& reasonable_param_count
&& k_exit_jumps_count >= 2 // At least 2: loop break + early return
&& k_exit_jumps_count >= 2 // At least 2: loop break + early return
}
/// Phase 90: Check if module matches Parse String Composite pattern
@ -993,8 +993,12 @@ mod detectors {
// Check if rhs is a const value 2 (indicating i+=2 for escape)
// We need to check if rhs points to a Const instruction with value 2
loop_step.body.iter().any(|other_inst| match other_inst {
JoinInst::Compute(crate::mir::join_ir::MirLikeInst::Const { dst, value }) => {
dst == rhs && matches!(value, crate::mir::join_ir::ConstValue::Integer(2))
JoinInst::Compute(crate::mir::join_ir::MirLikeInst::Const {
dst,
value,
}) => {
dst == rhs
&& matches!(value, crate::mir::join_ir::ConstValue::Integer(2))
}
_ => false,
})
@ -1171,7 +1175,9 @@ mod tests {
shapes
);
assert!(
!shapes.iter().any(|s| matches!(s, NormalizedDevShape::Pattern3IfSumMinimal)),
!shapes
.iter()
.any(|s| matches!(s, NormalizedDevShape::Pattern3IfSumMinimal)),
"selfhost_if_sum_p3 should not rely on canonical P3 minimal detection: {:?}",
shapes
);
@ -1286,7 +1292,9 @@ mod tests {
k_next: None,
dst: Some(ValueId(2)),
},
JoinInst::Ret { value: Some(ValueId(2)) },
JoinInst::Ret {
value: Some(ValueId(2)),
},
],
exit_cont: None,
};
@ -1348,7 +1356,9 @@ mod tests {
k_next: None,
dst: Some(ValueId(40)),
},
JoinInst::Ret { value: Some(ValueId(40)) },
JoinInst::Ret {
value: Some(ValueId(40)),
},
],
exit_cont: None,
};
@ -1358,7 +1368,9 @@ mod tests {
id: JoinFuncId::new(2),
name: "k_exit".to_string(),
params: vec![ValueId(0)],
body: vec![JoinInst::Ret { value: Some(ValueId(0)) }],
body: vec![JoinInst::Ret {
value: Some(ValueId(0)),
}],
exit_cont: None,
};