Phase 21.2 Complete: VM Adapter正規実装 + devブリッジ完全撤去
## 🎉 Phase 21.2完全達成 ### ✅ 実装完了 - VM static box 永続化(singleton infrastructure) - devブリッジ完全撤去(adapter_dev.rs削除、by-name dispatch削除) - .hako正規実装(MirCallV1Handler, AbiAdapterRegistry等) - text-merge経路完全動作 - 全phase2120 adapter reps PASS(7テスト) ### 🐛 バグ修正 1. strip_local_decl修正 - トップレベルのみlocal削除、メソッド内は保持 - src/runner/modes/common_util/hako.rs:29 2. static box フィールド永続化 - MirInterpreter singleton storage実装 - me parameter binding修正(1:1マッピング) - getField/setField string→singleton解決 - src/backend/mir_interpreter/{mod,exec,handlers/boxes_object_fields}.rs 3. Map.len alias rc=0修正 - [map/missing]パターン検出でnull扱い(4箇所) - lang/src/vm/boxes/mir_call_v1_handler.hako:91-93,131-133,151-153,199-201 ### 📁 主要変更ファイル #### Rust(VM Runtime) - src/backend/mir_interpreter/mod.rs - static box singleton storage - src/backend/mir_interpreter/exec.rs - parameter binding fix - src/backend/mir_interpreter/handlers/boxes_object_fields.rs - singleton resolution - src/backend/mir_interpreter/handlers/calls.rs - dev bridge removal - src/backend/mir_interpreter/utils/mod.rs - adapter_dev module removal - src/backend/mir_interpreter/utils/adapter_dev.rs - DELETED (7555 bytes) - src/runner/modes/vm.rs - static box declaration collection - src/runner/modes/common_util/hako.rs - strip_local_decl fix - src/instance_v2.rs - Clone implementation #### Hako (.hako実装) - lang/src/vm/boxes/mir_call_v1_handler.hako - [map/missing] detection - lang/src/vm/boxes/abi_adapter_registry.hako - NEW (adapter registry) - lang/src/vm/helpers/method_alias_policy.hako - method alias support #### テスト - tools/smokes/v2/profiles/quick/core/phase2120/s3_vm_adapter_*.sh - 7 new tests ### 🎯 テスト結果 ``` ✅ s3_vm_adapter_array_len_canary_vm.sh ✅ s3_vm_adapter_array_len_per_recv_canary_vm.sh ✅ s3_vm_adapter_array_length_alias_canary_vm.sh ✅ s3_vm_adapter_array_size_alias_canary_vm.sh ✅ s3_vm_adapter_map_len_alias_state_canary_vm.sh ✅ s3_vm_adapter_map_length_alias_state_canary_vm.sh ✅ s3_vm_adapter_map_size_struct_canary_vm.sh ``` 環境フラグ: HAKO_ABI_ADAPTER=1 HAKO_ABI_ADAPTER_DEV=0 ### 🏆 設計品質 - ✅ ハードコード禁止(AGENTS.md 5.1)完全準拠 - ✅ 構造的・一般化設計(特定Box名のif分岐なし) - ✅ 後方互換性保持(既存コード破壊ゼロ) - ✅ text-merge経路(.hako依存関係正しくマージ) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -33,6 +33,10 @@ pub struct MirInterpreter {
|
||||
// Trace context (dev-only; enabled with NYASH_VM_TRACE=1)
|
||||
pub(super) last_block: Option<BasicBlockId>,
|
||||
pub(super) last_inst: Option<MirInstruction>,
|
||||
// Static box singleton instances (persistent across method calls)
|
||||
pub(super) static_boxes: HashMap<String, crate::instance_v2::InstanceBox>,
|
||||
// Static box declarations (metadata for creating instances)
|
||||
pub(super) static_box_decls: HashMap<String, crate::core::model::BoxDeclaration>,
|
||||
}
|
||||
|
||||
impl MirInterpreter {
|
||||
@ -45,9 +49,60 @@ impl MirInterpreter {
|
||||
cur_fn: None,
|
||||
last_block: None,
|
||||
last_inst: None,
|
||||
static_boxes: HashMap::new(),
|
||||
static_box_decls: HashMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Register static box declarations (called from vm.rs during setup)
|
||||
pub fn register_static_box_decl(&mut self, name: String, decl: crate::core::model::BoxDeclaration) {
|
||||
self.static_box_decls.insert(name, decl);
|
||||
}
|
||||
|
||||
/// Ensure static box singleton instance exists, create if not
|
||||
/// Returns mutable reference to the singleton instance
|
||||
fn ensure_static_box_instance(&mut self, box_name: &str) -> Result<&mut crate::instance_v2::InstanceBox, VMError> {
|
||||
// Check if instance already exists
|
||||
if !self.static_boxes.contains_key(box_name) {
|
||||
// Get declaration
|
||||
let decl = self.static_box_decls.get(box_name)
|
||||
.ok_or_else(|| VMError::InvalidInstruction(
|
||||
format!("static box declaration not found: {}", box_name)
|
||||
))?
|
||||
.clone();
|
||||
|
||||
// Create instance from declaration
|
||||
let instance = crate::instance_v2::InstanceBox::from_declaration(
|
||||
box_name.to_string(),
|
||||
decl.fields.clone(),
|
||||
decl.methods.clone(),
|
||||
);
|
||||
|
||||
self.static_boxes.insert(box_name.to_string(), instance);
|
||||
|
||||
if std::env::var("NYASH_VM_STATIC_TRACE").ok().as_deref() == Some("1") {
|
||||
eprintln!("[vm-static] created singleton instance for static box: {}", box_name);
|
||||
}
|
||||
}
|
||||
|
||||
// Return mutable reference
|
||||
self.static_boxes.get_mut(box_name)
|
||||
.ok_or_else(|| VMError::InvalidInstruction(
|
||||
format!("static box instance not found after creation: {}", box_name)
|
||||
))
|
||||
}
|
||||
|
||||
/// Check if a function name represents a static box method
|
||||
/// Format: "BoxName.method/Arity"
|
||||
fn is_static_box_method(&self, func_name: &str) -> Option<String> {
|
||||
if let Some((box_name, _rest)) = func_name.split_once('.') {
|
||||
if self.static_box_decls.contains_key(box_name) {
|
||||
return Some(box_name.to_string());
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
/// Execute module entry (main) and return boxed result
|
||||
pub fn execute_module(&mut self, module: &MirModule) -> Result<Box<dyn NyashBox>, VMError> {
|
||||
// Snapshot functions for call resolution
|
||||
|
||||
Reference in New Issue
Block a user