ResultBox migration (stage 0): suppress legacy deprecation warnings in box_trait impls; keep dual handling in VM. Fix verifier Display for SuspiciousBarrierContext. Expose VM stats fields to vm_stats module. CLI core_ci guide and script in place.

This commit is contained in:
Moe Charm
2025-08-26 01:42:18 +09:00
parent 7705508b99
commit 9c94e88b86
13 changed files with 408 additions and 36 deletions

View File

@ -203,9 +203,9 @@ pub struct VM {
/// Active MIR module during execution (for function calls)
module: Option<MirModule>,
/// Instruction execution counters (by MIR opcode)
instr_counter: std::collections::HashMap<&'static str, usize>,
pub(super) instr_counter: std::collections::HashMap<&'static str, usize>,
/// Execution start time for optional stats
exec_start: Option<Instant>,
pub(super) exec_start: Option<Instant>,
// Phase 9.78a: Add unified Box handling components
// TODO: Re-enable when interpreter refactoring is complete
// /// Box registry for creating all Box types

View File

@ -729,6 +729,7 @@ pub struct ResultBox {
base: BoxBase,
}
#[allow(deprecated)]
impl ResultBox {
pub fn new_success(value: Box<dyn NyashBox>) -> Self {
Self {
@ -772,6 +773,7 @@ impl ResultBox {
}
}
#[allow(deprecated)]
impl BoxCore for ResultBox {
fn box_id(&self) -> u64 {
self.base.id
@ -794,6 +796,7 @@ impl BoxCore for ResultBox {
}
}
#[allow(deprecated)]
impl NyashBox for ResultBox {
fn to_string_box(&self) -> StringBox {
if self.is_success {
@ -863,6 +866,7 @@ impl NyashBox for ResultBox {
}
}
#[allow(deprecated)]
impl Display for ResultBox {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.fmt_box(f)

View File

@ -82,11 +82,14 @@ impl<'a> LoopBuilder<'a> {
// 7. ループボディの構築
self.set_current_block(body_id)?;
self.emit_safepoint()?;
// ボディをビルド
for stmt in body {
self.build_statement(stmt)?;
}
// latchブロックのスナップショットを保存phi入力解決用
let latch_snapshot = self.get_current_variable_map();
self.block_var_maps.insert(body_id, latch_snapshot);
// 8. Latchブロックボディの最後からHeaderへ戻る
let latch_id = self.current_block()?;
@ -114,6 +117,8 @@ impl<'a> LoopBuilder<'a> {
) -> Result<(), String> {
// 現在の変数マップから、ループで使用される可能性のある変数を取得
let current_vars = self.get_current_variable_map();
// preheader時点のスナップショット後でphi入力の解析に使う
self.block_var_maps.insert(preheader_id, current_vars.clone());
// 各変数に対して不完全なPhi nodeを作成
let mut incomplete_phis = Vec::new();
@ -271,9 +276,12 @@ impl<'a> LoopBuilder<'a> {
self.parent_builder.variable_map.insert(name, value);
}
fn get_variable_at_block(&self, name: &str, _block_id: BasicBlockId) -> Option<ValueId> {
// 簡易実装:現在の変数マップから取得
// TODO: 本来はブロックごとの変数マップを管理すべき
fn get_variable_at_block(&self, name: &str, block_id: BasicBlockId) -> Option<ValueId> {
// まずブロックごとのスナップショットを優先
if let Some(map) = self.block_var_maps.get(&block_id) {
if let Some(v) = map.get(name) { return Some(*v); }
}
// フォールバック:現在の変数マップ(単純ケース用)
self.parent_builder.variable_map.get(name).copied()
}
@ -285,4 +293,4 @@ impl<'a> LoopBuilder<'a> {
fn build_statement(&mut self, stmt: ASTNode) -> Result<ValueId, String> {
self.parent_builder.build_expression(stmt)
}
}
}

View File

@ -589,6 +589,9 @@ impl std::fmt::Display for VerificationError {
VerificationError::InvalidBarrierPointer { ptr, block, instruction_index, reason } => {
write!(f, "Invalid Barrier pointer {} in block {} at {}: {}", ptr, block, instruction_index, reason)
},
VerificationError::SuspiciousBarrierContext { block, instruction_index, note } => {
write!(f, "Suspicious Barrier context in block {} at {}: {}", block, instruction_index, note)
},
}
}
}