feat(phi): Phase 25.1 - BTreeMap移行 (21ファイル、80%決定性達成)

## 修正内容

### Core MIR/PHI (5ファイル)
- builder.rs: variable_map, value_types, value_origin_newbox
- context.rs: 3つのマップ
- loop_builder.rs: 3箇所
- loop_snapshot_manager.rs: snapshot マップ
- loop_snapshot_merge.rs: 2箇所

### MIR関連 (4ファイル)
- function.rs: FunctionMetadata.value_types
- resolver.rs: CalleeResolverBox
- guard.rs: CalleeGuardBox
- loop_common.rs: apply_increment_before_continue

### JSON Bridge (5ファイル)
- json_v0_bridge/lowering.rs
- json_v0_bridge/lowering/expr.rs
- json_v0_bridge/lowering/if_else.rs
- json_v0_bridge/lowering/merge.rs
- json_v0_bridge/lowering/try_catch.rs
- json_v0_bridge/mod.rs

### Printer & Providers (4ファイル)
- printer.rs, printer_helpers.rs
- host_providers/mir_builder.rs
- backend/mir_interpreter/handlers/extern_provider.rs

### Tests (3ファイル)
- phi_core/conservative.rs
- tests/json_program_loop.rs
- tests/mir_stage1_using_resolver_verify.rs (2テスト有効化)

## テスト結果
- mir_stage1_using_resolver_resolve_with_modules_map_verifies: 80%成功率
- 完全な決定性は未達成 (HashMap 86箇所、HashSet 63箇所が残存)

🐱 Generated with Claude Code
This commit is contained in:
nyash-codex
2025-11-22 05:33:40 +09:00
parent 6815065e72
commit 7812c3d4c1
38 changed files with 583 additions and 479 deletions

View File

@ -13,7 +13,7 @@ use crate::ast::{ASTNode, LiteralValue};
use crate::mir::builder::builder_calls::CallTarget;
use crate::mir::region::function_slot_registry::FunctionSlotRegistry;
use crate::mir::region::RegionId;
use std::collections::HashMap;
use std::collections::{BTreeMap, HashMap};
use std::collections::HashSet;
mod builder_calls;
mod call_resolution; // ChatGPT5 Pro: Type-safe call resolution utilities
@ -86,7 +86,8 @@ pub struct MirBuilder {
/// Variable name to ValueId mapping (for SSA conversion)
/// 注意: compilation_contextがSomeの場合は使用されません
pub(super) variable_map: HashMap<String, ValueId>,
/// Phase 25.1: HashMap → BTreeMapPHI生成の決定性確保
pub(super) variable_map: BTreeMap<String, ValueId>,
/// Pending phi functions to be inserted
#[allow(dead_code)]
@ -95,7 +96,8 @@ pub struct MirBuilder {
/// Origin tracking for simple optimizations (e.g., object.method after new)
/// Maps a ValueId to the class name if it was produced by NewBox of that class
/// 注意: compilation_contextがSomeの場合は使用されません
pub(super) value_origin_newbox: HashMap<ValueId, String>,
// Phase 25.1: HashMap → BTreeMap決定性確保
pub(super) value_origin_newbox: BTreeMap<ValueId, String>,
/// Names of user-defined boxes declared in the current module
pub(super) user_defined_boxes: HashSet<String>,
@ -113,7 +115,8 @@ pub struct MirBuilder {
/// Optional per-value type annotations (MIR-level): ValueId -> MirType
/// 注意: compilation_contextがSomeの場合は使用されません
pub(super) value_types: HashMap<ValueId, super::MirType>,
// Phase 25.1: HashMap → BTreeMap決定性確保
pub(super) value_types: BTreeMap<ValueId, super::MirType>,
/// Phase 26-A: ValueId型情報マップ型安全性強化
/// ValueId -> MirValueKind のマッピング
@ -241,15 +244,15 @@ impl MirBuilder {
value_gen: ValueIdGenerator::new(),
block_gen: BasicBlockIdGenerator::new(),
compilation_context: None, // 箱理論: デフォルトは従来モード
variable_map: HashMap::new(),
variable_map: BTreeMap::new(), // Phase 25.1: 決定性確保
pending_phis: Vec::new(),
value_origin_newbox: HashMap::new(),
value_origin_newbox: BTreeMap::new(), // Phase 25.1: 決定性確保
user_defined_boxes: HashSet::new(),
weak_fields_by_box: HashMap::new(),
property_getters_by_box: HashMap::new(),
field_origin_class: HashMap::new(),
field_origin_by_box: HashMap::new(),
value_types: HashMap::new(),
value_types: BTreeMap::new(), // Phase 25.1: 決定性確保
value_kinds: HashMap::new(), // Phase 26-A: ValueId型安全化
current_slot_registry: None,
type_registry: type_registry::TypeRegistry::new(),