fix(joinir): Use BTreeMap for MirModule.functions deterministic iteration
HashMap iteration order is non-deterministic due to HashDoS protection. This caused merge_joinir_mir_blocks to sometimes process functions in wrong order, leading to incorrect block remapping. Changed: - MirModule.functions: HashMap → BTreeMap - MirInterpreter.functions: HashMap → BTreeMap - IfLoweringDryRunner.scan_module: HashMap → BTreeMap parameter 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
* Print/Debug (best-effort), Barrier/Safepoint (no-op).
|
||||
*/
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::collections::{BTreeMap, HashMap};
|
||||
|
||||
use crate::box_trait::NyashBox;
|
||||
|
||||
@ -31,7 +31,7 @@ pub struct MirInterpreter {
|
||||
pub(super) mem: HashMap<ValueId, VMValue>,
|
||||
// Object field storage keyed by stable object identity (Arc ptr addr fallback)
|
||||
pub(super) obj_fields: HashMap<u64, HashMap<String, VMValue>>,
|
||||
pub(super) functions: HashMap<String, MirFunction>,
|
||||
pub(super) functions: BTreeMap<String, MirFunction>,
|
||||
pub(super) cur_fn: Option<String>,
|
||||
// Trace context (dev-only; enabled with NYASH_VM_TRACE=1)
|
||||
pub(super) last_block: Option<BasicBlockId>,
|
||||
@ -54,7 +54,7 @@ impl MirInterpreter {
|
||||
regs: HashMap::new(),
|
||||
mem: HashMap::new(),
|
||||
obj_fields: HashMap::new(),
|
||||
functions: HashMap::new(),
|
||||
functions: BTreeMap::new(),
|
||||
cur_fn: None,
|
||||
last_block: None,
|
||||
last_inst: None,
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
use super::{BasicBlock, BasicBlockId, EffectMask, MirInstruction, MirType, ValueId};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::collections::{BTreeMap, HashMap, HashSet};
|
||||
use std::fmt;
|
||||
|
||||
/// Function signature for MIR functions
|
||||
@ -381,8 +381,8 @@ pub struct MirModule {
|
||||
/// Module name
|
||||
pub name: String,
|
||||
|
||||
/// Functions in this module
|
||||
pub functions: HashMap<String, MirFunction>,
|
||||
/// Functions in this module (BTreeMap for deterministic iteration order)
|
||||
pub functions: BTreeMap<String, MirFunction>,
|
||||
|
||||
/// Global constants/statics
|
||||
pub globals: HashMap<String, super::ConstValue>,
|
||||
@ -416,7 +416,7 @@ impl MirModule {
|
||||
pub fn new(name: String) -> Self {
|
||||
Self {
|
||||
name,
|
||||
functions: HashMap::new(),
|
||||
functions: BTreeMap::new(),
|
||||
globals: HashMap::new(),
|
||||
metadata: ModuleMetadata::default(),
|
||||
}
|
||||
|
||||
@ -11,7 +11,7 @@
|
||||
|
||||
use crate::mir::join_ir::JoinInst;
|
||||
use crate::mir::{MirFunction, MirInstruction};
|
||||
use std::collections::HashMap;
|
||||
use std::collections::BTreeMap;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
/// If lowering dry-run スキャナー
|
||||
@ -42,7 +42,7 @@ impl IfLoweringDryRunner {
|
||||
/// - 各 Branch ブロックで try_lower_if_to_joinir() 試行
|
||||
/// - パフォーマンス計測(マイクロ秒レベル)
|
||||
/// - 統計情報収集(Select/IfMerge分類)
|
||||
pub fn scan_module(&self, functions: &HashMap<String, MirFunction>) -> DryRunStats {
|
||||
pub fn scan_module(&self, functions: &BTreeMap<String, MirFunction>) -> DryRunStats {
|
||||
let mut total_branches = 0;
|
||||
let mut lowered_count = 0;
|
||||
let mut select_count = 0;
|
||||
|
||||
Reference in New Issue
Block a user