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,20 +15,20 @@ use crate::mir::region::function_slot_registry::FunctionSlotRegistry;
use crate::mir::region::RegionId;
use std::collections::HashSet;
use std::collections::{BTreeMap, HashMap};
mod binding_context; // Phase 136 follow-up (Step 4/7): BindingContext extraction
mod builder_calls;
mod call_resolution; // ChatGPT5 Pro: Type-safe call resolution utilities
mod calls; // Call system modules (refactored from builder_calls)
mod binding_context; // Phase 136 follow-up (Step 4/7): BindingContext extraction
mod compilation_context; // Phase 136 follow-up (Step 7/7): CompilationContext extraction
mod context; // BoxCompilationContext - 箱理論による静的Boxコンパイル時のコンテキスト分離
mod core_context; // Phase 136 follow-up (Step 2/7): CoreContext extraction
mod metadata_context; // Phase 136 follow-up (Step 6/7): MetadataContext extraction
mod variable_context; // Phase 136 follow-up (Step 5/7): VariableContext extraction
mod decls; // declarations lowering split
mod exprs; // expression lowering split
mod exprs_call;
mod method_call_handlers; // Method call handler separation (Phase 3) // call(expr)
// include lowering removed (using is handled in runner)
mod metadata_context; // Phase 136 follow-up (Step 6/7): MetadataContext extraction
mod method_call_handlers;
mod variable_context; // Phase 136 follow-up (Step 5/7): VariableContext extraction // Method call handler separation (Phase 3) // call(expr)
// include lowering removed (using is handled in runner)
mod control_flow; // thin wrappers to centralize control-flow entrypoints
mod exprs_lambda; // lambda lowering
mod exprs_peek; // peek expression
@ -55,9 +55,9 @@ mod receiver; // ReceiverMaterializationBoxMethod recv の pin+LocalSSA 集
mod rewrite; // P1: Known rewrite & special consolidation
mod router; // RouterPolicyBoxUnified vs BoxCall
mod schedule; // BlockScheduleBox物理順序: PHI→materialize→body
mod scope_context; // Phase 136 follow-up (Step 3/7): ScopeContext extraction
mod ssa; // LocalSSA helpers (in-block materialization)
mod stmts;
mod scope_context; // Phase 136 follow-up (Step 3/7): ScopeContext extraction
mod type_context; // Phase 136 follow-up: TypeContext extraction
mod type_facts; // Phase 136 follow-up: Type inference facts box
pub(crate) mod type_registry;
@ -86,8 +86,6 @@ pub struct MirBuilder {
/// Direct field access for backward compatibility (migration in progress).
pub(super) core_ctx: core_context::CoreContext,
/// Phase 136 follow-up: Type information context
/// Consolidates value_types, value_kinds, value_origin_newbox for better organization.
/// Direct field access for backward compatibility (migration in progress).
@ -125,7 +123,6 @@ pub struct MirBuilder {
#[allow(dead_code)]
pub(super) pending_phis: Vec<(BasicBlockId, ValueId, String)>,
// Phase 2-5: binding_map removed - use binding_ctx.binding_map instead
// include guards removed
@ -153,7 +150,6 @@ pub struct MirBuilder {
// ----------------------
// Debug scope context (dev only; zero-cost when unused)
// ----------------------
/// Local SSA cache: ensure per-block materialization for critical operands (e.g., recv)
/// Key: (bb, original ValueId, kind) -> local ValueId
/// kind: 0=recv, 1+ reserved for future (args etc.)
@ -196,7 +192,8 @@ impl MirBuilder {
let core_ctx = core_context::CoreContext::new();
// Phase 136 Step 7/7: Compilation context (new SSOT)
let comp_ctx = compilation_context::CompilationContext::with_plugin_sigs(plugin_method_sigs.clone());
let comp_ctx =
compilation_context::CompilationContext::with_plugin_sigs(plugin_method_sigs.clone());
// フェーズM: no_phi_mode初期化削除
#[allow(deprecated)]
@ -384,7 +381,8 @@ impl MirBuilder {
if let (Some(dot), Some(slash)) = (name.rfind('.'), name.rfind('/')) {
if slash > dot {
let tail = &name[dot..];
self.comp_ctx.method_tail_index
self.comp_ctx
.method_tail_index
.entry(tail.to_string())
.or_insert_with(Vec::new)
.push(name.clone());
@ -399,7 +397,9 @@ impl MirBuilder {
fn ensure_method_tail_index(&mut self) {
let need_rebuild = match self.current_module {
Some(ref refmod) => self.comp_ctx.method_tail_index_source_len != refmod.functions.len(),
Some(ref refmod) => {
self.comp_ctx.method_tail_index_source_len != refmod.functions.len()
}
None => self.comp_ctx.method_tail_index_source_len != 0,
};
if need_rebuild {
@ -410,7 +410,8 @@ impl MirBuilder {
pub(super) fn method_candidates(&mut self, method: &str, arity: usize) -> Vec<String> {
self.ensure_method_tail_index();
let tail = format!(".{}{}", method, format!("/{}", arity));
self.comp_ctx.method_tail_index
self.comp_ctx
.method_tail_index
.get(&tail)
.cloned()
.unwrap_or_default()
@ -418,7 +419,8 @@ impl MirBuilder {
pub(super) fn method_candidates_tail<S: AsRef<str>>(&mut self, tail: S) -> Vec<String> {
self.ensure_method_tail_index();
self.comp_ctx.method_tail_index
self.comp_ctx
.method_tail_index
.get(tail.as_ref())
.cloned()
.unwrap_or_default()
@ -527,7 +529,9 @@ impl MirBuilder {
if !suggest.is_empty() {
msg.push_str("\nHint: symbol appears in using module(s): ");
msg.push_str(&suggest.join(", "));
msg.push_str("\nConsider adding 'using <module> [as Alias]' or check nyash.toml [using].");
msg.push_str(
"\nConsider adding 'using <module> [as Alias]' or check nyash.toml [using].",
);
}
msg
@ -567,7 +571,9 @@ impl MirBuilder {
// Result: VM would try to read undefined ValueIds (e.g., ValueId(270) at bb303).
if !var_name.starts_with("__pin$") {
// In SSA form, each assignment creates a new value
self.variable_ctx.variable_map.insert(var_name.clone(), value_id);
self.variable_ctx
.variable_map
.insert(var_name.clone(), value_id);
}
Ok(value_id)
@ -582,7 +588,8 @@ impl MirBuilder {
// Precompute debug metadata to avoid borrow conflicts later
let _dbg_fn_name = self
.scope_ctx.current_function
.scope_ctx
.current_function
.as_ref()
.map(|f| f.signature.name.clone());
let _dbg_region_id = self.debug_current_region_id();
@ -694,7 +701,8 @@ impl MirBuilder {
}) = callee
{
let names: Vec<String> = self
.variable_ctx.variable_map
.variable_ctx
.variable_map
.iter()
.filter(|(_, &vid)| vid == *r)
.map(|(k, _)| k.clone())
@ -760,7 +768,10 @@ impl MirBuilder {
);
}
// Phase 136 Step 6/7: Use metadata_ctx for span
block.add_instruction_with_span(instruction.clone(), self.metadata_ctx.current_span());
block.add_instruction_with_span(
instruction.clone(),
self.metadata_ctx.current_span(),
);
// Drop the mutable borrow of `block` before updating other blocks
}
// Update predecessor sets for branch/jump immediately so that
@ -854,7 +865,8 @@ impl MirBuilder {
effects: EffectMask::PURE,
})?;
// 型注釈(最小)
self.type_ctx.value_types
self.type_ctx
.value_types
.insert(dst, super::MirType::Box(class.clone()));
return Ok(dst);
}
@ -872,7 +884,9 @@ impl MirBuilder {
dst,
value: ConstValue::Integer(n),
})?;
self.type_ctx.value_types.insert(dst, super::MirType::Integer);
self.type_ctx
.value_types
.insert(dst, super::MirType::Integer);
return Ok(dst);
}
}
@ -897,7 +911,8 @@ impl MirBuilder {
})?;
// Phase 15.5: Unified box type handling
// All boxes (including former core boxes) are treated uniformly as Box types
self.type_ctx.value_types
self.type_ctx
.value_types
.insert(dst, super::MirType::Box(class.clone()));
// Record origin for optimization: dst was created by NewBox of class
@ -954,7 +969,9 @@ impl MirBuilder {
/// Check if the current basic block is terminated
fn is_current_block_terminated(&self) -> bool {
if let (Some(block_id), Some(ref function)) = (self.current_block, &self.scope_ctx.current_function) {
if let (Some(block_id), Some(ref function)) =
(self.current_block, &self.scope_ctx.current_function)
{
if let Some(block) = function.get_block(block_id) {
return block.is_terminated();
}
@ -1018,13 +1035,17 @@ use crate::mir::loop_pattern_detection::BindingMapProvider;
impl BindingMapProvider for MirBuilder {
#[cfg(feature = "normalized_dev")]
fn get_binding_map(&self) -> Option<&std::collections::BTreeMap<String, crate::mir::BindingId>> {
fn get_binding_map(
&self,
) -> Option<&std::collections::BTreeMap<String, crate::mir::BindingId>> {
// Phase 136 Step 4/7: Use binding_ctx (SSOT)
Some(self.binding_ctx.binding_map())
}
#[cfg(not(feature = "normalized_dev"))]
fn get_binding_map(&self) -> Option<&std::collections::BTreeMap<String, crate::mir::BindingId>> {
fn get_binding_map(
&self,
) -> Option<&std::collections::BTreeMap<String, crate::mir::BindingId>> {
None
}
}