Files
hakorune/src/mir/builder/origin/infer.rs
2025-12-28 01:34:46 +09:00

34 lines
1.2 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 super::super::{MirBuilder, MirType, ValueId};
/// Annotate the origin of `me`/receiver with a Known class when分かる範囲のみ。
/// - 優先: current_static_box静的ボックスの文脈
/// - 次点: 現在の関数名のプレフィックス("Class.method/Arity"
/// - それ以外: 付与せず(挙動不変)
#[allow(dead_code)]
pub(crate) fn annotate_me_origin(builder: &mut MirBuilder, me_id: ValueId) {
let mut cls: Option<String> = None;
if let Some(c) = builder.comp_ctx.current_static_box.clone() {
if !c.is_empty() {
cls = Some(c);
}
}
if cls.is_none() {
if let Some(ref fun) = builder.scope_ctx.current_function {
if let Some(dot) = fun.signature.name.find('.') {
let c = fun.signature.name[..dot].to_string();
if !c.is_empty() {
cls = Some(c);
}
}
}
}
if let Some(c) = cls {
// Record both origin class and a Box type hint for downstream passes観測用
builder
.type_ctx
.value_origin_newbox
.insert(me_id, c.clone());
builder.type_ctx.value_types.insert(me_id, MirType::Box(c));
}
}