Files
hakorune/src/mir/builder/receiver.rs
nyash-codex e404746612 refactor(mir): Phase 139-P3-B - RoutingDecision を enum 対応 + レガシー削除
- RoutingDecision の missing_caps を Vec<CapabilityTag> に変更(型安全化)
- error_tags は to_tag() メソッドで自動生成
- 全 callsite を enum variant に修正
- capability_tags モジュール(文字列定数群)を完全削除
- 全テスト PASS(型安全性向上を確認)
- フォーマット適用
2025-12-16 07:02:14 +09:00

61 lines
2.1 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

use crate::mir::builder::MirBuilder;
use crate::mir::definitions::call_unified::Callee;
/// ReceiverMaterializationBox centralizes Method receiver pinning + LocalSSA materialization.
///
/// Contract:
/// - If callee is a Method and has a receiver:
/// - Pin the receiver into a named slot (`__pin$*@recv`) so it participates in PHI/loop merges.
/// - Ensure the receiver has an in-block definition via LocalSSA (Copy in the current block).
/// - Args の LocalSSA は別レイヤssa::localで扱う。
pub fn finalize_method_receiver(builder: &mut MirBuilder, callee: &mut Callee) {
if let Callee::Method {
box_name,
method,
receiver: Some(r),
certainty,
box_kind,
} = callee.clone()
{
// Pin to a named slot so start_new_block や LoopBuilder が slot 経由で追跡できる
let r_pinned = builder.pin_to_slot(r, "@recv").unwrap_or(r);
// Optional dev trace for receiver aliases
if std::env::var("NYASH_BUILDER_TRACE_RECV").ok().as_deref() == Some("1") {
let current_fn = builder
.scope_ctx
.current_function
.as_ref()
.map(|f| f.signature.name.clone())
.unwrap_or_else(|| "<none>".to_string());
let bb = builder.current_block;
let names: Vec<String> = builder
.variable_ctx
.variable_map
.iter()
.filter(|(_, &vid)| vid == r)
.map(|(k, _)| k.clone())
.collect();
eprintln!(
"[builder/recv-trace] fn={} bb={:?} method={}.{} recv=%{} aliases={:?}",
current_fn,
bb,
box_name.clone(),
method,
r.0,
names
);
}
// LocalSSA: ensure an in-block definition in the current block
let r_local = crate::mir::builder::ssa::local::recv(builder, r_pinned);
*callee = Callee::Method {
box_name,
method,
receiver: Some(r_local),
certainty,
box_kind,
};
}
}