Builder: reserve slots for user-defined instance methods (start at 4)\n- Deterministic per-type slot assignment via sorted names\n- Enables method_id emission for user boxes when type known\n- Docs updated

This commit is contained in:
Moe Charm
2025-08-26 22:35:19 +09:00
parent 2960a9b2f8
commit d46176de49
2 changed files with 18 additions and 1 deletions

View File

@ -18,6 +18,7 @@ Last Updated: 2025-08-26
- MIR Builder
- When receiver type can be inferred, emit `BoxCall { method_id }` (slot ID) instead of name.
- Add late-bind fallback path for unresolved sites (keeps current behavior).
- Reserve user-defined instance methods slots deterministically (start at 4; universal [0..3]).
- Debug scaffolding
- Add `MIRDebugInfo` container types (empty by default) for ID→name mapping (off by default).
- Docs
@ -46,4 +47,3 @@ Last Updated: 2025-08-26
## Roll-forward
- Proceed to 9.79b.2 (VM vtable/thunk + mono-PIC).

View File

@ -9,6 +9,7 @@ use super::{
FunctionSignature, ValueId, ConstValue, BinaryOp, UnaryOp, CompareOp,
MirType, EffectMask, Effect, BasicBlockIdGenerator, ValueIdGenerator
};
use super::slot_registry::{get_or_assign_type_id, reserve_method_slot};
use super::slot_registry::resolve_slot_by_type_name;
use crate::ast::{ASTNode, LiteralValue, BinaryOperator};
use std::collections::HashMap;
@ -1424,6 +1425,22 @@ impl MirBuilder {
self.weak_fields_by_box.insert(name.clone(), set);
}
// Reserve method slots for user-defined instance methods (deterministic, starts at 4)
let mut instance_methods: Vec<String> = Vec::new();
for (mname, mast) in &methods {
if let ASTNode::FunctionDeclaration { is_static, .. } = mast {
if !*is_static { instance_methods.push(mname.clone()); }
}
}
instance_methods.sort();
if !instance_methods.is_empty() {
let tyid = get_or_assign_type_id(&name);
for (i, m) in instance_methods.iter().enumerate() {
let slot = 4u16.saturating_add(i as u16);
reserve_method_slot(tyid, m, slot);
}
}
// Process methods - now methods is a HashMap
for (method_name, method_ast) in methods {
if let ASTNode::FunctionDeclaration { .. } = method_ast {