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

@ -15,13 +15,13 @@ use std::collections::HashMap;
#[cfg(feature = "normalized_dev")]
use std::panic::{catch_unwind, AssertUnwindSafe};
#[cfg(feature = "normalized_dev")]
pub mod fixtures;
#[cfg(feature = "normalized_dev")]
pub mod dev_env;
#[cfg(feature = "normalized_dev")]
pub mod dev_fixtures;
#[cfg(feature = "normalized_dev")]
pub mod fixtures;
#[cfg(feature = "normalized_dev")]
pub mod loop_step_inspector;
#[cfg(feature = "normalized_dev")]
pub mod shape_guard;
@ -97,7 +97,10 @@ pub enum JpOp {
BinOp(BinOpKind),
Unary(UnaryOp),
Compare(CompareOp),
BoxCall { box_name: String, method: String },
BoxCall {
box_name: String,
method: String,
},
/// 三項演算子cond ? then : else
Select,
}
@ -462,13 +465,11 @@ pub fn normalize_pattern2_minimal(structured: &JoinModule) -> NormalizedModule {
cond,
then_val,
else_val,
}) => {
body.push(JpInst::Let {
dst: *dst,
op: JpOp::Select,
args: vec![*cond, *then_val, *else_val],
})
}
}) => body.push(JpInst::Let {
dst: *dst,
op: JpOp::Select,
args: vec![*cond, *then_val, *else_val],
}),
JoinInst::Jump { cont, args, cond } => {
if let Some(cond_val) = cond {
body.push(JpInst::If {
@ -497,7 +498,9 @@ pub fn normalize_pattern2_minimal(structured: &JoinModule) -> NormalizedModule {
args: vec![*cond, *then_val, *else_val],
});
}
JoinInst::Call { func, args, k_next, .. } => {
JoinInst::Call {
func, args, k_next, ..
} => {
if k_next.is_none() {
body.push(JpInst::TailCallFn {
target: JpFuncId(func.0),
@ -620,9 +623,7 @@ pub fn normalize_pattern3_if_sum_json_minimal(
/// Phase 50: selfhost if-sum P3 を Normalized に載せるdev-only
#[cfg(feature = "normalized_dev")]
pub fn normalize_selfhost_if_sum_p3(
structured: &JoinModule,
) -> Result<NormalizedModule, String> {
pub fn normalize_selfhost_if_sum_p3(structured: &JoinModule) -> Result<NormalizedModule, String> {
normalize_pattern3_if_sum_shape(structured, NormalizedDevShape::SelfhostIfSumP3)
}
@ -769,14 +770,12 @@ pub fn normalized_pattern2_to_structured(norm: &NormalizedModule) -> JoinModule
op: *op,
operand: args.get(0).copied().unwrap_or(ValueId(0)),
})),
JpOp::Select => func
.body
.push(JoinInst::Compute(MirLikeInst::Select {
dst: *dst,
cond: args.get(0).copied().unwrap_or(ValueId(0)),
then_val: args.get(1).copied().unwrap_or(ValueId(0)),
else_val: args.get(2).copied().unwrap_or(ValueId(0)),
})),
JpOp::Select => func.body.push(JoinInst::Compute(MirLikeInst::Select {
dst: *dst,
cond: args.get(0).copied().unwrap_or(ValueId(0)),
then_val: args.get(1).copied().unwrap_or(ValueId(0)),
else_val: args.get(2).copied().unwrap_or(ValueId(0)),
})),
JpOp::Compare(op) => func.body.push(JoinInst::Compute(MirLikeInst::Compare {
dst: *dst,
op: *op,
@ -832,9 +831,7 @@ fn verify_normalized_pattern2(
max_env_fields: usize,
) -> Result<(), String> {
if module.phase != JoinIrPhase::Normalized {
return Err(
"[joinir/normalized-dev] pattern2: phase must be Normalized".to_string(),
);
return Err("[joinir/normalized-dev] pattern2: phase must be Normalized".to_string());
}
let mut layout_sizes: HashMap<u32, usize> = HashMap::new();
@ -871,10 +868,8 @@ fn verify_normalized_pattern2(
| JpInst::If { env, .. } => {
if let Some(expected) = expected_env_len {
if env.is_empty() {
return Err(
"[joinir/normalized-dev] pattern2: env must not be empty"
.to_string(),
);
return Err("[joinir/normalized-dev] pattern2: env must not be empty"
.to_string());
}
let _ = expected;
}
@ -885,9 +880,7 @@ fn verify_normalized_pattern2(
if let Some(last) = func.body.last() {
match last {
JpInst::TailCallFn { .. }
| JpInst::TailCallKont { .. }
| JpInst::If { .. } => {}
JpInst::TailCallFn { .. } | JpInst::TailCallKont { .. } | JpInst::If { .. } => {}
_ => {
return Err(format!(
"[joinir/normalized-dev] pattern2: function '{}' does not end with tail call/if",
@ -1069,7 +1062,9 @@ pub(crate) fn normalized_dev_roundtrip_structured(
let shapes = shape_guard::supported_shapes(module);
if shapes.is_empty() {
return Err("[joinir/normalized-dev] module shape is not supported by normalized_dev".into());
return Err(
"[joinir/normalized-dev] module shape is not supported by normalized_dev".into(),
);
}
let debug = dev_env::normalized_dev_logs_enabled() && crate::config::env::joinir_dev_enabled();
@ -1092,15 +1087,15 @@ pub(crate) fn normalized_dev_roundtrip_structured(
| NormalizedDevShape::JsonparserSkipWsReal
| NormalizedDevShape::JsonparserAtoiMini
| NormalizedDevShape::JsonparserAtoiReal
| NormalizedDevShape::JsonparserParseNumberReal => catch_unwind(AssertUnwindSafe(
|| {
| NormalizedDevShape::JsonparserParseNumberReal => {
catch_unwind(AssertUnwindSafe(|| {
let norm = normalize_pattern2_minimal(module);
normalized_pattern2_to_structured(&norm)
},
)),
}))
}
NormalizedDevShape::SelfhostTokenScanP2 => catch_unwind(AssertUnwindSafe(|| {
let norm =
normalize_selfhost_token_scan_p2(module).expect("selfhost P2 normalization failed");
let norm = normalize_selfhost_token_scan_p2(module)
.expect("selfhost P2 normalization failed");
normalized_pattern2_to_structured(&norm)
})),
NormalizedDevShape::SelfhostTokenScanP2Accum => catch_unwind(AssertUnwindSafe(|| {
@ -1110,8 +1105,8 @@ pub(crate) fn normalized_dev_roundtrip_structured(
})),
// Phase 47-A: P3 minimal (delegates to P2 for now, but uses proper guard)
NormalizedDevShape::Pattern3IfSumMinimal => catch_unwind(AssertUnwindSafe(|| {
let norm = normalize_pattern3_if_sum_minimal(module)
.expect("P3 normalization failed");
let norm =
normalize_pattern3_if_sum_minimal(module).expect("P3 normalization failed");
normalized_pattern2_to_structured(&norm)
})),
NormalizedDevShape::Pattern3IfSumMulti => catch_unwind(AssertUnwindSafe(|| {
@ -1125,8 +1120,8 @@ pub(crate) fn normalized_dev_roundtrip_structured(
normalized_pattern2_to_structured(&norm)
})),
NormalizedDevShape::SelfhostIfSumP3 => catch_unwind(AssertUnwindSafe(|| {
let norm = normalize_selfhost_if_sum_p3(module)
.expect("selfhost P3 normalization failed");
let norm =
normalize_selfhost_if_sum_p3(module).expect("selfhost P3 normalization failed");
normalized_pattern2_to_structured(&norm)
})),
NormalizedDevShape::SelfhostIfSumP3Ext => catch_unwind(AssertUnwindSafe(|| {
@ -1156,36 +1151,38 @@ pub(crate) fn normalized_dev_roundtrip_structured(
})),
// Phase 48-A: P4 minimal (delegates to P2 for now, but uses proper guard)
NormalizedDevShape::Pattern4ContinueMinimal => catch_unwind(AssertUnwindSafe(|| {
let norm = normalize_pattern4_continue_minimal(module)
.expect("P4 normalization failed");
let norm =
normalize_pattern4_continue_minimal(module).expect("P4 normalization failed");
normalized_pattern2_to_structured(&norm)
})),
NormalizedDevShape::JsonparserParseArrayContinueSkipWs => {
catch_unwind(AssertUnwindSafe(|| {
let norm =
normalize_jsonparser_parse_array_continue_skip_ws(module)
.expect("P4 array normalization failed");
let norm = normalize_jsonparser_parse_array_continue_skip_ws(module)
.expect("P4 array normalization failed");
normalized_pattern2_to_structured(&norm)
}))
}
NormalizedDevShape::JsonparserParseObjectContinueSkipWs => {
catch_unwind(AssertUnwindSafe(|| {
let norm =
normalize_jsonparser_parse_object_continue_skip_ws(module)
.expect("P4 object normalization failed");
let norm = normalize_jsonparser_parse_object_continue_skip_ws(module)
.expect("P4 object normalization failed");
normalized_pattern2_to_structured(&norm)
}))
}
// Phase 89: Continue + Early Return pattern (dev-only, delegates to P2 for now)
NormalizedDevShape::PatternContinueReturnMinimal => catch_unwind(AssertUnwindSafe(|| {
let norm = normalize_pattern2_minimal(module);
normalized_pattern2_to_structured(&norm)
})),
NormalizedDevShape::PatternContinueReturnMinimal => {
catch_unwind(AssertUnwindSafe(|| {
let norm = normalize_pattern2_minimal(module);
normalized_pattern2_to_structured(&norm)
}))
}
// Phase 90: Parse String Composite pattern (dev-only, delegates to P2 for now)
NormalizedDevShape::ParseStringCompositeMinimal => catch_unwind(AssertUnwindSafe(|| {
let norm = normalize_pattern2_minimal(module);
normalized_pattern2_to_structured(&norm)
})),
NormalizedDevShape::ParseStringCompositeMinimal => {
catch_unwind(AssertUnwindSafe(|| {
let norm = normalize_pattern2_minimal(module);
normalized_pattern2_to_structured(&norm)
}))
}
};
match attempt {