refactor(mir): Remove CompilationContext legacy fields (Phase 2-7/7) 🎉
Phase 2 完全完了!全 7 Context のレガシーフィールドを完全削除。 ## Changes - Migrated all access sites to comp_ctx.* (15 fields) - Removed 15 deprecated fields: * compilation_context * current_static_box * user_defined_boxes * reserved_value_ids * fn_body_ast * weak_fields_by_box * property_getters_by_box * field_origin_class * field_origin_by_box * static_method_index * method_tail_index * method_tail_index_source_len * type_registry * current_slot_registry * plugin_method_sigs - Removed initialization code (15 field inits) ## Phase 2 完了!🎉 - builder.rs: 1222 → 1127 lines (-95 lines net) - Deprecation warnings: 86 → 0 (完全排除) - 全 36 deprecated fields 削除完了 - 全 14 sync helpers 削除完了 - 7 Context 完全SSOT化 ## Tests - cargo build --release: SUCCESS - cargo test --release --lib: 1033/1033 PASS ✅ - Deprecation warnings: 0 ✅ Phase 2 Progress: 7/7 contexts complete (100%) ✅ - ✅ MetadataContext - ✅ CoreContext - ✅ TypeContext - ✅ ScopeContext - ✅ BindingContext - ✅ VariableContext - ✅ CompilationContext (this commit) 🎉 Phase 136 Context Box化: 完全完了! 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@ -87,12 +87,6 @@ pub struct MirBuilder {
|
||||
pub(super) core_ctx: core_context::CoreContext,
|
||||
|
||||
|
||||
/// [DEPRECATED] 箱理論: Static boxコンパイル時のコンテキスト分離
|
||||
/// Phase 136 Step 7/7: Moved to comp_ctx.compilation_context (backward compat wrapper)
|
||||
/// Some(ctx)の場合、variable_map/value_origin_newbox/value_typesはctxから取得
|
||||
/// Noneの場合、従来のフィールドを使用(後方互換性)
|
||||
#[deprecated(note = "Use comp_ctx.compilation_context instead")]
|
||||
pub(super) compilation_context: Option<context::BoxCompilationContext>,
|
||||
|
||||
/// Phase 136 follow-up: Type information context
|
||||
/// Consolidates value_types, value_kinds, value_origin_newbox for better organization.
|
||||
@ -131,79 +125,6 @@ pub struct MirBuilder {
|
||||
#[allow(dead_code)]
|
||||
pub(super) pending_phis: Vec<(BasicBlockId, ValueId, String)>,
|
||||
|
||||
/// [DEPRECATED] Names of user-defined boxes declared in the current module
|
||||
/// Phase 136 Step 7/7: Moved to comp_ctx.user_defined_boxes (backward compat wrapper)
|
||||
#[deprecated(note = "Use comp_ctx.user_defined_boxes instead")]
|
||||
pub(super) user_defined_boxes: HashSet<String>,
|
||||
|
||||
/// [DEPRECATED] Weak field registry: BoxName -> {weak field names}
|
||||
/// Phase 136 Step 7/7: Moved to comp_ctx.weak_fields_by_box (backward compat wrapper)
|
||||
#[deprecated(note = "Use comp_ctx.weak_fields_by_box instead")]
|
||||
pub(super) weak_fields_by_box: HashMap<String, HashSet<String>>,
|
||||
|
||||
/// [DEPRECATED] Unified members: BoxName -> {propName -> Kind}
|
||||
/// Phase 136 Step 7/7: Moved to comp_ctx.property_getters_by_box (backward compat wrapper)
|
||||
#[deprecated(note = "Use comp_ctx.property_getters_by_box instead")]
|
||||
pub(super) property_getters_by_box: HashMap<String, HashMap<String, PropertyKind>>,
|
||||
|
||||
/// [DEPRECATED] Remember class of object fields after assignments: (base_id, field) -> class_name
|
||||
/// Phase 136 Step 7/7: Moved to comp_ctx.field_origin_class (backward compat wrapper)
|
||||
#[deprecated(note = "Use comp_ctx.field_origin_class instead")]
|
||||
pub(super) field_origin_class: HashMap<(ValueId, String), String>,
|
||||
/// [DEPRECATED] Class-level field origin (cross-function heuristic): (BaseBoxName, field) -> FieldBoxName
|
||||
/// Phase 136 Step 7/7: Moved to comp_ctx.field_origin_by_box (backward compat wrapper)
|
||||
#[deprecated(note = "Use comp_ctx.field_origin_by_box instead")]
|
||||
pub(super) field_origin_by_box: HashMap<(String, String), String>,
|
||||
|
||||
/// [DEPRECATED] 関数スコープの SlotRegistry(観測専用)
|
||||
/// Phase 136 Step 7/7: Moved to comp_ctx.current_slot_registry (backward compat wrapper)
|
||||
/// - current_function と同じライフサイクルを持つよ。
|
||||
/// - 既存の variable_map/SSA には影響しない(メタデータのみ)。
|
||||
#[deprecated(note = "Use comp_ctx.current_slot_registry instead")]
|
||||
pub(super) current_slot_registry: Option<FunctionSlotRegistry>,
|
||||
|
||||
/// [DEPRECATED] 🎯 箱理論: 型情報管理の一元化(TypeRegistryBox)
|
||||
/// Phase 136 Step 7/7: Moved to comp_ctx.type_registry (backward compat wrapper)
|
||||
/// NYASH_USE_TYPE_REGISTRY=1 で有効化(段階的移行用)
|
||||
#[deprecated(note = "Use comp_ctx.type_registry instead")]
|
||||
pub(super) type_registry: type_registry::TypeRegistry,
|
||||
|
||||
/// [DEPRECATED] Plugin method return type signatures loaded from nyash_box.toml
|
||||
/// Phase 136 Step 7/7: Moved to comp_ctx.plugin_method_sigs (backward compat wrapper)
|
||||
#[deprecated(note = "Use comp_ctx.plugin_method_sigs instead")]
|
||||
plugin_method_sigs: HashMap<(String, String), super::MirType>,
|
||||
/// [DEPRECATED] Current static box name when lowering a static box body (e.g., "Main")
|
||||
/// Phase 136 Step 7/7: Moved to comp_ctx.current_static_box (backward compat wrapper)
|
||||
#[deprecated(note = "Use comp_ctx.current_static_box instead")]
|
||||
current_static_box: Option<String>,
|
||||
/// [DEPRECATED] Index of static methods seen during lowering: name -> [(BoxName, arity)]
|
||||
/// Phase 136 Step 7/7: Moved to comp_ctx.static_method_index (backward compat wrapper)
|
||||
#[deprecated(note = "Use comp_ctx.static_method_index instead")]
|
||||
pub(super) static_method_index: std::collections::HashMap<String, Vec<(String, usize)>>,
|
||||
|
||||
/// [DEPRECATED] Fast lookup: method+arity tail → candidate function names (e.g., ".str/0" → ["JsonNode.str/0", ...])
|
||||
/// Phase 136 Step 7/7: Moved to comp_ctx.method_tail_index (backward compat wrapper)
|
||||
#[deprecated(note = "Use comp_ctx.method_tail_index instead")]
|
||||
pub(super) method_tail_index: std::collections::HashMap<String, Vec<String>>,
|
||||
/// [DEPRECATED] Source size snapshot to detect when to rebuild the tail index
|
||||
/// Phase 136 Step 7/7: Moved to comp_ctx.method_tail_index_source_len (backward compat wrapper)
|
||||
#[deprecated(note = "Use comp_ctx.method_tail_index_source_len instead")]
|
||||
pub(super) method_tail_index_source_len: usize,
|
||||
|
||||
/// [DEPRECATED] Phase 200-C: Original function body AST for capture analysis
|
||||
/// Phase 136 Step 7/7: Moved to comp_ctx.fn_body_ast (backward compat wrapper)
|
||||
/// Stored temporarily during function lowering to support FunctionScopeCaptureAnalyzer.
|
||||
/// None when not lowering a function, or when fn_body is not available.
|
||||
#[deprecated(note = "Use comp_ctx.fn_body_ast instead")]
|
||||
pub(super) fn_body_ast: Option<Vec<ASTNode>>,
|
||||
|
||||
/// [DEPRECATED] Phase 201-A: Reserved ValueIds that must not be allocated
|
||||
/// Phase 136 Step 7/7: Moved to comp_ctx.reserved_value_ids (backward compat wrapper)
|
||||
/// These are PHI dst ValueIds created by LoopHeaderPhiBuilder.
|
||||
/// When next_value_id() encounters a reserved ID, it skips to the next.
|
||||
/// Cleared after JoinIR merge completes.
|
||||
#[deprecated(note = "Use comp_ctx.reserved_value_ids instead")]
|
||||
pub(super) reserved_value_ids: HashSet<ValueId>,
|
||||
|
||||
// Phase 2-5: binding_map removed - use binding_ctx.binding_map instead
|
||||
|
||||
@ -286,7 +207,6 @@ impl MirBuilder {
|
||||
// Phase 136 Step 2/7: Core context (new SSOT)
|
||||
core_ctx,
|
||||
|
||||
compilation_context: None, // 箱理論: デフォルトは従来モード
|
||||
type_ctx: type_context::TypeContext::new(), // Phase 136: Type context
|
||||
scope_ctx: scope_context::ScopeContext::new(), // Phase 136 Step 3/7: Scope context
|
||||
binding_ctx: binding_context::BindingContext::new(), // Phase 136 Step 4/7: Binding context
|
||||
@ -294,21 +214,6 @@ impl MirBuilder {
|
||||
metadata_ctx: metadata_context::MetadataContext::new(), // Phase 136 Step 6/7: Metadata context
|
||||
comp_ctx, // Phase 136 Step 7/7: Compilation context
|
||||
pending_phis: Vec::new(),
|
||||
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(),
|
||||
current_slot_registry: None,
|
||||
type_registry: type_registry::TypeRegistry::new(),
|
||||
plugin_method_sigs,
|
||||
current_static_box: None,
|
||||
static_method_index: std::collections::HashMap::new(),
|
||||
method_tail_index: std::collections::HashMap::new(),
|
||||
method_tail_index_source_len: 0,
|
||||
|
||||
fn_body_ast: None, // Phase 200-C: Initialize to None
|
||||
reserved_value_ids: HashSet::new(), // Phase 201-A: Initialize to empty
|
||||
|
||||
// Phase 2-5: binding_map initialization removed
|
||||
|
||||
@ -473,29 +378,29 @@ impl MirBuilder {
|
||||
// Method tail index (performance helper)
|
||||
// ----------------------
|
||||
fn rebuild_method_tail_index(&mut self) {
|
||||
self.method_tail_index.clear();
|
||||
self.comp_ctx.method_tail_index.clear();
|
||||
if let Some(ref module) = self.current_module {
|
||||
for name in module.functions.keys() {
|
||||
if let (Some(dot), Some(slash)) = (name.rfind('.'), name.rfind('/')) {
|
||||
if slash > dot {
|
||||
let tail = &name[dot..];
|
||||
self.method_tail_index
|
||||
self.comp_ctx.method_tail_index
|
||||
.entry(tail.to_string())
|
||||
.or_insert_with(Vec::new)
|
||||
.push(name.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
self.method_tail_index_source_len = module.functions.len();
|
||||
self.comp_ctx.method_tail_index_source_len = module.functions.len();
|
||||
} else {
|
||||
self.method_tail_index_source_len = 0;
|
||||
self.comp_ctx.method_tail_index_source_len = 0;
|
||||
}
|
||||
}
|
||||
|
||||
fn ensure_method_tail_index(&mut self) {
|
||||
let need_rebuild = match self.current_module {
|
||||
Some(ref refmod) => self.method_tail_index_source_len != refmod.functions.len(),
|
||||
None => self.method_tail_index_source_len != 0,
|
||||
Some(ref refmod) => self.comp_ctx.method_tail_index_source_len != refmod.functions.len(),
|
||||
None => self.comp_ctx.method_tail_index_source_len != 0,
|
||||
};
|
||||
if need_rebuild {
|
||||
self.rebuild_method_tail_index();
|
||||
@ -505,7 +410,7 @@ impl MirBuilder {
|
||||
pub(super) fn method_candidates(&mut self, method: &str, arity: usize) -> Vec<String> {
|
||||
self.ensure_method_tail_index();
|
||||
let tail = format!(".{}{}", method, format!("/{}", arity));
|
||||
self.method_tail_index
|
||||
self.comp_ctx.method_tail_index
|
||||
.get(&tail)
|
||||
.cloned()
|
||||
.unwrap_or_default()
|
||||
@ -513,7 +418,7 @@ impl MirBuilder {
|
||||
|
||||
pub(super) fn method_candidates_tail<S: AsRef<str>>(&mut self, tail: S) -> Vec<String> {
|
||||
self.ensure_method_tail_index();
|
||||
self.method_tail_index
|
||||
self.comp_ctx.method_tail_index
|
||||
.get(tail.as_ref())
|
||||
.cloned()
|
||||
.unwrap_or_default()
|
||||
@ -1023,7 +928,7 @@ impl MirBuilder {
|
||||
// - For user-defined boxes (no explicit constructor), do NOT emit BoxCall("birth").
|
||||
// VM will treat plain NewBox as constructed; dev verify warns if needed.
|
||||
// - For builtins/plugins, keep BoxCall("birth") fallback to preserve legacy init.
|
||||
let is_user_box = self.user_defined_boxes.contains(&class);
|
||||
let is_user_box = self.comp_ctx.user_defined_boxes.contains(&class);
|
||||
// Dev safety: allow disabling birth() injection for builtins to avoid
|
||||
// unified-call method dispatch issues while migrating. Off by default unless explicitly enabled.
|
||||
let allow_builtin_birth = std::env::var("NYASH_DEV_BIRTH_INJECT_BUILTINS")
|
||||
|
||||
@ -28,7 +28,7 @@ impl MirBuilder {
|
||||
eprintln!(
|
||||
"[builder] function-call name={} static_ctx={} in_fn={}",
|
||||
name,
|
||||
self.current_static_box.as_deref().unwrap_or(""),
|
||||
self.comp_ctx.current_static_box.as_deref().unwrap_or(""),
|
||||
cur_fun
|
||||
);
|
||||
}
|
||||
@ -507,7 +507,7 @@ impl MirBuilder {
|
||||
name: &str,
|
||||
arg_values: &[ValueId],
|
||||
) -> Result<Option<ValueId>, String> {
|
||||
if let Some(cands) = self.static_method_index.get(name) {
|
||||
if let Some(cands) = self.comp_ctx.static_method_index.get(name) {
|
||||
let mut matches: Vec<(String, usize)> = cands
|
||||
.iter()
|
||||
.cloned()
|
||||
|
||||
@ -26,16 +26,16 @@ impl MirBuilder {
|
||||
/// 🎯 箱理論: Step 1 - Lowering Context準備
|
||||
fn prepare_lowering_context(&mut self, func_name: &str) -> LoweringContext {
|
||||
// Static box context設定
|
||||
let saved_static_ctx = self.current_static_box.clone();
|
||||
let saved_static_ctx = self.comp_ctx.current_static_box.clone();
|
||||
if let Some(pos) = func_name.find('.') {
|
||||
let box_name = &func_name[..pos];
|
||||
if !box_name.is_empty() {
|
||||
self.current_static_box = Some(box_name.to_string());
|
||||
self.comp_ctx.current_static_box = Some(box_name.to_string());
|
||||
}
|
||||
}
|
||||
|
||||
// BoxCompilationContext vs saved_var_map モード判定
|
||||
let context_active = self.compilation_context.is_some();
|
||||
let context_active = self.comp_ctx.compilation_context.is_some();
|
||||
let saved_var_map = if !context_active {
|
||||
Some(std::mem::take(&mut self.variable_ctx.variable_map))
|
||||
} else {
|
||||
@ -43,7 +43,7 @@ impl MirBuilder {
|
||||
};
|
||||
|
||||
// 関数スコープ SlotRegistry は元の関数側から退避しておくよ。
|
||||
let saved_slot_registry = self.current_slot_registry.take();
|
||||
let saved_slot_registry = self.comp_ctx.current_slot_registry.take();
|
||||
|
||||
// BoxCompilationContext mode: clear()で完全独立化
|
||||
if context_active {
|
||||
@ -93,7 +93,7 @@ impl MirBuilder {
|
||||
self.scope_ctx.current_function = Some(function);
|
||||
self.current_block = Some(entry);
|
||||
// 新しい関数スコープ用の SlotRegistry を準備するよ(観測専用)
|
||||
self.current_slot_registry = Some(FunctionSlotRegistry::new());
|
||||
self.comp_ctx.current_slot_registry = Some(FunctionSlotRegistry::new());
|
||||
self.ensure_block_exists(entry)?;
|
||||
|
||||
// Region 観測レイヤ: static 関数用の FunctionRegion を積むよ。
|
||||
@ -157,7 +157,7 @@ impl MirBuilder {
|
||||
self.register_value_kind(pid, MirValueKind::Parameter(param_idx));
|
||||
}
|
||||
|
||||
if let Some(reg) = self.current_slot_registry.as_mut() {
|
||||
if let Some(reg) = self.comp_ctx.current_slot_registry.as_mut() {
|
||||
for (name, ty) in slot_regs {
|
||||
reg.ensure_slot(&name, ty);
|
||||
}
|
||||
@ -247,9 +247,9 @@ impl MirBuilder {
|
||||
}
|
||||
|
||||
// Static box context復元
|
||||
self.current_static_box = ctx.saved_static_ctx;
|
||||
self.comp_ctx.current_static_box = ctx.saved_static_ctx;
|
||||
// 関数スコープ SlotRegistry も元の関数に戻すよ。
|
||||
self.current_slot_registry = ctx.saved_slot_registry;
|
||||
self.comp_ctx.current_slot_registry = ctx.saved_slot_registry;
|
||||
}
|
||||
|
||||
/// 🎯 箱理論: Step 2b - 関数スケルトン作成(instance method版)
|
||||
@ -274,7 +274,7 @@ impl MirBuilder {
|
||||
self.scope_ctx.current_function = Some(function);
|
||||
self.current_block = Some(entry);
|
||||
// instance method 用の関数スコープ SlotRegistry もここで用意するよ。
|
||||
self.current_slot_registry = Some(FunctionSlotRegistry::new());
|
||||
self.comp_ctx.current_slot_registry = Some(FunctionSlotRegistry::new());
|
||||
self.ensure_block_exists(entry)?;
|
||||
|
||||
// Region 観測レイヤ: instance method 用の FunctionRegion も積んでおくよ。
|
||||
@ -328,7 +328,7 @@ impl MirBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(reg) = self.current_slot_registry.as_mut() {
|
||||
if let Some(reg) = self.comp_ctx.current_slot_registry.as_mut() {
|
||||
for (name, ty) in slot_regs {
|
||||
reg.ensure_slot(&name, ty);
|
||||
}
|
||||
@ -354,7 +354,7 @@ impl MirBuilder {
|
||||
body.len(),
|
||||
func_name
|
||||
);
|
||||
self.fn_body_ast = Some(body.clone());
|
||||
self.comp_ctx.fn_body_ast = Some(body.clone());
|
||||
|
||||
// Step 1: Context準備
|
||||
let mut ctx = self.prepare_lowering_context(&func_name);
|
||||
@ -383,7 +383,7 @@ impl MirBuilder {
|
||||
self.restore_lowering_context(ctx);
|
||||
|
||||
// Phase 200-C: Clear fn_body_ast after function lowering
|
||||
self.fn_body_ast = None;
|
||||
self.comp_ctx.fn_body_ast = None;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@ -397,7 +397,7 @@ impl MirBuilder {
|
||||
body: Vec<ASTNode>,
|
||||
) -> Result<(), String> {
|
||||
// Phase 200-C: Store fn_body for capture analysis
|
||||
self.fn_body_ast = Some(body.clone());
|
||||
self.comp_ctx.fn_body_ast = Some(body.clone());
|
||||
|
||||
// Step 1: Context準備(instance methodでは不要だがAPI統一のため)
|
||||
let mut ctx = LoweringContext {
|
||||
@ -406,7 +406,7 @@ impl MirBuilder {
|
||||
saved_static_ctx: None,
|
||||
saved_function: None,
|
||||
saved_block: None,
|
||||
saved_slot_registry: self.current_slot_registry.take(),
|
||||
saved_slot_registry: self.comp_ctx.current_slot_registry.take(),
|
||||
};
|
||||
|
||||
// Step 2b: 関数スケルトン作成(method版)
|
||||
@ -475,10 +475,10 @@ impl MirBuilder {
|
||||
if let Some(saved) = ctx.saved_var_map {
|
||||
self.variable_ctx.variable_map = saved;
|
||||
}
|
||||
self.current_slot_registry = ctx.saved_slot_registry;
|
||||
self.comp_ctx.current_slot_registry = ctx.saved_slot_registry;
|
||||
|
||||
// Phase 200-C: Clear fn_body_ast after function lowering
|
||||
self.fn_body_ast = None;
|
||||
self.comp_ctx.fn_body_ast = None;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -78,7 +78,7 @@ impl CallMaterializerBox {
|
||||
}
|
||||
|
||||
// 2) Unique static-method fallback: name+arity → Box.name/Arity
|
||||
if let Some(cands) = builder.static_method_index.get(name) {
|
||||
if let Some(cands) = builder.comp_ctx.static_method_index.get(name) {
|
||||
let mut matches: Vec<(String, usize)> = cands
|
||||
.iter()
|
||||
.cloned()
|
||||
|
||||
@ -154,7 +154,7 @@ impl UnifiedCallEmitterBox {
|
||||
let resolver = super::resolver::CalleeResolverBox::new(
|
||||
&builder.type_ctx.value_origin_newbox,
|
||||
&builder.type_ctx.value_types,
|
||||
Some(&builder.type_registry), // 🎯 TypeRegistry を渡す
|
||||
Some(&builder.comp_ctx.type_registry), // 🎯 TypeRegistry を渡す
|
||||
);
|
||||
let mut callee = match resolver.resolve(target.clone()) {
|
||||
Ok(c) => c,
|
||||
@ -279,7 +279,7 @@ impl UnifiedCallEmitterBox {
|
||||
let resolver = super::resolver::CalleeResolverBox::new(
|
||||
&builder.type_ctx.value_origin_newbox,
|
||||
&builder.type_ctx.value_types,
|
||||
Some(&builder.type_registry),
|
||||
Some(&builder.comp_ctx.type_registry),
|
||||
);
|
||||
resolver.validate_args(&callee, &args)?;
|
||||
|
||||
|
||||
@ -38,7 +38,7 @@ impl MirBuilder {
|
||||
) -> Result<crate::mir::definitions::call_unified::Callee, String> {
|
||||
super::method_resolution::resolve_call_target(
|
||||
name,
|
||||
&self.current_static_box,
|
||||
&self.comp_ctx.current_static_box,
|
||||
&self.variable_ctx.variable_map,
|
||||
)
|
||||
}
|
||||
|
||||
@ -295,11 +295,11 @@ pub(in crate::mir::builder) fn merge_joinir_mir_blocks(
|
||||
|
||||
// Phase 201-A: Set reserved IDs in MirBuilder so next_value_id() skips them
|
||||
// This protects against carrier corruption when break conditions emit Const instructions
|
||||
builder.reserved_value_ids = reserved_phi_dsts.clone();
|
||||
if debug && !builder.reserved_value_ids.is_empty() {
|
||||
builder.comp_ctx.reserved_value_ids = reserved_phi_dsts.clone();
|
||||
if debug && !builder.comp_ctx.reserved_value_ids.is_empty() {
|
||||
eprintln!(
|
||||
"[cf_loop/joinir] Phase 201-A: Set builder.reserved_value_ids = {:?}",
|
||||
builder.reserved_value_ids
|
||||
"[cf_loop/joinir] Phase 201-A: Set builder.comp_ctx.reserved_value_ids = {:?}",
|
||||
builder.comp_ctx.reserved_value_ids
|
||||
);
|
||||
}
|
||||
|
||||
@ -750,14 +750,14 @@ pub(in crate::mir::builder) fn merge_joinir_mir_blocks(
|
||||
|
||||
// Phase 201-A: Clear reserved ValueIds after merge completes
|
||||
// Future loops will set their own reserved IDs
|
||||
if !builder.reserved_value_ids.is_empty() {
|
||||
if !builder.comp_ctx.reserved_value_ids.is_empty() {
|
||||
if debug {
|
||||
eprintln!(
|
||||
"[cf_loop/joinir] Phase 201-A: Clearing reserved_value_ids (was {:?})",
|
||||
builder.reserved_value_ids
|
||||
builder.comp_ctx.reserved_value_ids
|
||||
);
|
||||
}
|
||||
builder.reserved_value_ids.clear();
|
||||
builder.comp_ctx.reserved_value_ids.clear();
|
||||
}
|
||||
|
||||
// Phase 246-EX-FIX: Handle loop variable expr_result separately from carrier expr_result
|
||||
|
||||
@ -127,7 +127,7 @@ impl MirBuilder {
|
||||
|
||||
// Phase 200-C: Pass fn_body_ast to LoopPatternContext if available
|
||||
// Clone fn_body_ast to avoid borrow checker issues
|
||||
let fn_body_clone = self.fn_body_ast.clone();
|
||||
let fn_body_clone = self.comp_ctx.fn_body_ast.clone();
|
||||
trace::trace().routing(
|
||||
"router",
|
||||
func_name,
|
||||
|
||||
@ -26,8 +26,8 @@ impl super::MirBuilder {
|
||||
}
|
||||
}
|
||||
// Within this lowering, treat `me` receiver as this static box
|
||||
let saved_static = self.current_static_box.clone();
|
||||
self.current_static_box = Some(box_name.clone());
|
||||
let saved_static = self.comp_ctx.current_static_box.clone();
|
||||
self.comp_ctx.current_static_box = Some(box_name.clone());
|
||||
// Look for the main() method
|
||||
let out = if let Some(main_method) = methods.get("main") {
|
||||
if let ASTNode::FunctionDeclaration { params, body, .. } = main_method {
|
||||
@ -111,7 +111,7 @@ impl super::MirBuilder {
|
||||
}
|
||||
self.variable_ctx.variable_map.insert(p.clone(), pid);
|
||||
// 関数スコープ SlotRegistry にも登録しておくよ(観測専用)
|
||||
if let Some(reg) = self.current_slot_registry.as_mut() {
|
||||
if let Some(reg) = self.comp_ctx.current_slot_registry.as_mut() {
|
||||
let ty = self.type_ctx.value_types.get(&pid).cloned();
|
||||
reg.ensure_slot(p, ty);
|
||||
}
|
||||
@ -121,13 +121,13 @@ impl super::MirBuilder {
|
||||
"[build_static_main_box] Storing fn_body_ast with {} nodes for inline main()",
|
||||
body.len()
|
||||
);
|
||||
self.fn_body_ast = Some(body.clone());
|
||||
self.comp_ctx.fn_body_ast = Some(body.clone());
|
||||
|
||||
// Lower statements in order to preserve def→use
|
||||
let lowered = self.cf_block(body.clone());
|
||||
|
||||
// Phase 200-C: Clear fn_body_ast after main() lowering
|
||||
self.fn_body_ast = None;
|
||||
self.comp_ctx.fn_body_ast = None;
|
||||
|
||||
self.variable_ctx.variable_map = saved_var_map;
|
||||
lowered
|
||||
@ -138,7 +138,7 @@ impl super::MirBuilder {
|
||||
Err("static box must contain a main() method".to_string())
|
||||
};
|
||||
// Restore static box context
|
||||
self.current_static_box = saved_static;
|
||||
self.comp_ctx.current_static_box = saved_static;
|
||||
out
|
||||
}
|
||||
|
||||
@ -164,7 +164,7 @@ impl super::MirBuilder {
|
||||
// Record weak fields for this box
|
||||
if !weak_fields.is_empty() {
|
||||
let set: HashSet<String> = weak_fields.into_iter().collect();
|
||||
self.weak_fields_by_box.insert(name.clone(), set);
|
||||
self.comp_ctx.weak_fields_by_box.insert(name.clone(), set);
|
||||
}
|
||||
|
||||
// Reserve method slots for user-defined instance methods (deterministic, starts at 4)
|
||||
@ -206,7 +206,7 @@ impl super::MirBuilder {
|
||||
if let Some((k, prop)) = kind_and_prop {
|
||||
use std::collections::HashMap;
|
||||
let entry: &mut HashMap<String, super::PropertyKind> = self
|
||||
.property_getters_by_box
|
||||
.comp_ctx.property_getters_by_box
|
||||
.entry(name.clone())
|
||||
.or_insert_with(HashMap::new);
|
||||
entry.insert(prop, k);
|
||||
|
||||
@ -207,7 +207,7 @@ impl super::MirBuilder {
|
||||
// Generic static box: lower all static methods into standalone MIR functions (BoxName.method/N)
|
||||
// Note: Metadata clearing is now handled by BoxCompilationContext (箱理論)
|
||||
// See lifecycle.rs for context creation and builder_calls.rs for context swap
|
||||
self.user_defined_boxes.insert(name.clone());
|
||||
self.comp_ctx.user_defined_boxes.insert(name.clone());
|
||||
for (method_name, method_ast) in methods.clone() {
|
||||
if let ASTNode::FunctionDeclaration { params, body, .. } = method_ast {
|
||||
let func_name = format!(
|
||||
@ -222,7 +222,7 @@ impl super::MirBuilder {
|
||||
body.clone(),
|
||||
)?;
|
||||
// Index static method for fallback resolution of bare calls
|
||||
self.static_method_index
|
||||
self.comp_ctx.static_method_index
|
||||
.entry(method_name.clone())
|
||||
.or_insert_with(Vec::new)
|
||||
.push((name.clone(), params.len()));
|
||||
@ -234,7 +234,7 @@ impl super::MirBuilder {
|
||||
}
|
||||
} else {
|
||||
// Instance box: register type and lower instance methods/ctors as functions
|
||||
self.user_defined_boxes.insert(name.clone());
|
||||
self.comp_ctx.user_defined_boxes.insert(name.clone());
|
||||
self.build_box_declaration(
|
||||
name.clone(),
|
||||
methods.clone(),
|
||||
@ -311,9 +311,9 @@ impl super::MirBuilder {
|
||||
self.type_ctx.value_types
|
||||
.insert(arr_id, super::MirType::Box("ArrayBox".to_string()));
|
||||
// TypeRegistry + trace for deterministic debug
|
||||
self.type_registry
|
||||
self.comp_ctx.type_registry
|
||||
.record_newbox(arr_id, "ArrayBox".to_string());
|
||||
self.type_registry
|
||||
self.comp_ctx.type_registry
|
||||
.record_type(arr_id, super::MirType::Box("ArrayBox".to_string()));
|
||||
type_trace::origin("newbox:ArrayLiteral", arr_id, "ArrayBox");
|
||||
type_trace::ty(
|
||||
@ -354,9 +354,9 @@ impl super::MirBuilder {
|
||||
.insert(map_id, "MapBox".to_string());
|
||||
self.type_ctx.value_types
|
||||
.insert(map_id, super::MirType::Box("MapBox".to_string()));
|
||||
self.type_registry
|
||||
self.comp_ctx.type_registry
|
||||
.record_newbox(map_id, "MapBox".to_string());
|
||||
self.type_registry
|
||||
self.comp_ctx.type_registry
|
||||
.record_type(map_id, super::MirType::Box("MapBox".to_string()));
|
||||
type_trace::origin("newbox:MapLiteral", map_id, "MapBox");
|
||||
type_trace::ty(
|
||||
|
||||
@ -17,7 +17,7 @@ impl super::MirBuilder {
|
||||
// Unified members: if object class is known and has a synthetic getter for `field`,
|
||||
// rewrite to method call `__get_<field>()`.
|
||||
if let Some(class_name) = self.type_ctx.value_origin_newbox.get(&object_value).cloned() {
|
||||
if let Some(map) = self.property_getters_by_box.get(&class_name) {
|
||||
if let Some(map) = self.comp_ctx.property_getters_by_box.get(&class_name) {
|
||||
if let Some(kind) = map.get(&field) {
|
||||
let mname = match kind {
|
||||
super::PropertyKind::Computed => format!("__get_{}", field),
|
||||
@ -53,7 +53,7 @@ impl super::MirBuilder {
|
||||
|
||||
// Propagate recorded origin class for this field if any (ValueId-scoped)
|
||||
if let Some(class_name) = self
|
||||
.field_origin_class
|
||||
.comp_ctx.field_origin_class
|
||||
.get(&(object_value, field.clone()))
|
||||
.cloned()
|
||||
{
|
||||
@ -61,7 +61,7 @@ impl super::MirBuilder {
|
||||
} else if let Some(base_cls) = self.type_ctx.value_origin_newbox.get(&object_value).cloned() {
|
||||
// Cross-function heuristic: use class-level field origin mapping
|
||||
if let Some(fcls) = self
|
||||
.field_origin_by_box
|
||||
.comp_ctx.field_origin_by_box
|
||||
.get(&(base_cls.clone(), field.clone()))
|
||||
.cloned()
|
||||
{
|
||||
@ -89,7 +89,7 @@ impl super::MirBuilder {
|
||||
{
|
||||
if let Ok(base_id) = self.build_expression(*inner_obj.clone()) {
|
||||
if let Some(cls) = self
|
||||
.field_origin_class
|
||||
.comp_ctx.field_origin_class
|
||||
.get(&(base_id, inner_field))
|
||||
.cloned()
|
||||
{
|
||||
@ -99,7 +99,7 @@ impl super::MirBuilder {
|
||||
}
|
||||
}
|
||||
if let Some(class_name) = inferred_class {
|
||||
if let Some(weak_set) = self.weak_fields_by_box.get(&class_name) {
|
||||
if let Some(weak_set) = self.comp_ctx.weak_fields_by_box.get(&class_name) {
|
||||
if weak_set.contains(&field) {
|
||||
let loaded = self.emit_weak_load(field_val)?;
|
||||
let _ = self.emit_barrier_read(loaded);
|
||||
@ -129,7 +129,7 @@ impl super::MirBuilder {
|
||||
|
||||
// If base is known and field is weak, create WeakRef before store
|
||||
if let Some(class_name) = self.type_ctx.value_origin_newbox.get(&object_value).cloned() {
|
||||
if let Some(weak_set) = self.weak_fields_by_box.get(&class_name) {
|
||||
if let Some(weak_set) = self.comp_ctx.weak_fields_by_box.get(&class_name) {
|
||||
if weak_set.contains(&field) {
|
||||
value_result = self.emit_weak_new(value_result)?;
|
||||
}
|
||||
@ -159,7 +159,7 @@ impl super::MirBuilder {
|
||||
|
||||
// Write barrier if weak field
|
||||
if let Some(class_name) = self.type_ctx.value_origin_newbox.get(&object_value).cloned() {
|
||||
if let Some(weak_set) = self.weak_fields_by_box.get(&class_name) {
|
||||
if let Some(weak_set) = self.comp_ctx.weak_fields_by_box.get(&class_name) {
|
||||
if weak_set.contains(&field) {
|
||||
let _ = self.emit_barrier_write(value_result);
|
||||
}
|
||||
@ -168,11 +168,11 @@ impl super::MirBuilder {
|
||||
|
||||
// Record origin class for this field value if known
|
||||
if let Some(val_cls) = self.type_ctx.value_origin_newbox.get(&value_result).cloned() {
|
||||
self.field_origin_class
|
||||
self.comp_ctx.field_origin_class
|
||||
.insert((object_value, field.clone()), val_cls.clone());
|
||||
// Also record class-level mapping if base object class is known
|
||||
if let Some(base_cls) = self.type_ctx.value_origin_newbox.get(&object_value).cloned() {
|
||||
self.field_origin_by_box
|
||||
self.comp_ctx.field_origin_by_box
|
||||
.insert((base_cls, field.clone()), val_cls);
|
||||
}
|
||||
}
|
||||
|
||||
@ -88,11 +88,11 @@ impl super::MirBuilder {
|
||||
..
|
||||
} => {
|
||||
if !*is_static {
|
||||
self.user_defined_boxes.insert(name.clone());
|
||||
self.comp_ctx.user_defined_boxes.insert(name.clone());
|
||||
} else {
|
||||
for (mname, mast) in methods {
|
||||
if let ASTNode::FunctionDeclaration { params, .. } = mast {
|
||||
self.static_method_index
|
||||
self.comp_ctx.static_method_index
|
||||
.entry(mname.clone())
|
||||
.or_insert_with(Vec::new)
|
||||
.push((name.clone(), params.len()));
|
||||
@ -124,7 +124,7 @@ impl super::MirBuilder {
|
||||
|
||||
// 関数スコープの SlotRegistry を初期化するよ(観測専用)。
|
||||
// main 関数用のスロット登録箱として使う想定だよ。
|
||||
self.current_slot_registry =
|
||||
self.comp_ctx.current_slot_registry =
|
||||
Some(crate::mir::region::function_slot_registry::FunctionSlotRegistry::new());
|
||||
|
||||
// Region 観測レイヤ: main 関数の FunctionRegion を 1 つ作っておくよ。
|
||||
@ -189,7 +189,7 @@ impl super::MirBuilder {
|
||||
// スコープを抜けると自動的にコンテキストが破棄される
|
||||
{
|
||||
let ctx = super::context::BoxCompilationContext::new();
|
||||
self.compilation_context = Some(ctx);
|
||||
self.comp_ctx.compilation_context = Some(ctx);
|
||||
|
||||
// Lower all static methods into standalone functions: BoxName.method/Arity
|
||||
for (mname, mast) in methods.iter() {
|
||||
@ -207,7 +207,7 @@ impl super::MirBuilder {
|
||||
params.clone(),
|
||||
body.clone(),
|
||||
)?;
|
||||
self.static_method_index
|
||||
self.comp_ctx.static_method_index
|
||||
.entry(mname.clone())
|
||||
.or_insert_with(Vec::new)
|
||||
.push((name.clone(), params.len()));
|
||||
@ -217,12 +217,12 @@ impl super::MirBuilder {
|
||||
|
||||
// 🎯 箱理論: コンテキストをクリア(スコープ終了で自動破棄)
|
||||
// これにより、次のstatic boxは汚染されていない状態から開始される
|
||||
self.compilation_context = None;
|
||||
self.comp_ctx.compilation_context = None;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Instance box: register type and lower instance methods/ctors as functions
|
||||
self.user_defined_boxes.insert(name.clone());
|
||||
self.comp_ctx.user_defined_boxes.insert(name.clone());
|
||||
self.build_box_declaration(
|
||||
name.clone(),
|
||||
methods.clone(),
|
||||
@ -602,7 +602,7 @@ impl super::MirBuilder {
|
||||
crate::mir::region::observer::pop_function_region(self);
|
||||
|
||||
// main 関数スコープの SlotRegistry を解放するよ。
|
||||
self.current_slot_registry = None;
|
||||
self.comp_ctx.current_slot_registry = None;
|
||||
|
||||
Ok(module)
|
||||
}
|
||||
|
||||
@ -16,7 +16,7 @@ pub fn propagate(builder: &mut MirBuilder, src: ValueId, dst: ValueId) {
|
||||
|
||||
if use_registry {
|
||||
// 🎯 新: TypeRegistry 経由(トレース可能)
|
||||
builder.type_registry.propagate(src, dst);
|
||||
builder.comp_ctx.type_registry.propagate(src, dst);
|
||||
} else {
|
||||
// 従来: 直接アクセス(後方互換性)
|
||||
if let Some(t) = builder.type_ctx.value_types.get(&src).cloned() {
|
||||
@ -40,7 +40,7 @@ pub fn propagate_with_override(builder: &mut MirBuilder, dst: ValueId, ty: MirTy
|
||||
let ty_clone = ty.clone();
|
||||
if use_registry {
|
||||
// 🎯 新: TypeRegistry 経由
|
||||
builder.type_registry.record_type(dst, ty);
|
||||
builder.comp_ctx.type_registry.record_type(dst, ty);
|
||||
} else {
|
||||
// 従来: 直接アクセス
|
||||
builder.type_ctx.value_types.insert(dst, ty);
|
||||
|
||||
@ -6,7 +6,7 @@ use super::super::{MirBuilder, MirType, ValueId};
|
||||
/// - それ以外: 付与せず(挙動不変)
|
||||
pub(crate) fn annotate_me_origin(builder: &mut MirBuilder, me_id: ValueId) {
|
||||
let mut cls: Option<String> = None;
|
||||
if let Some(c) = builder.current_static_box.clone() {
|
||||
if let Some(c) = builder.comp_ctx.current_static_box.clone() {
|
||||
if !c.is_empty() {
|
||||
cls = Some(c);
|
||||
}
|
||||
|
||||
@ -44,7 +44,7 @@ pub(crate) fn try_known_rewrite(
|
||||
return None;
|
||||
}
|
||||
// Only user-defined boxes (plugin/core boxesは対象外)
|
||||
if !builder.user_defined_boxes.contains(cls) {
|
||||
if !builder.comp_ctx.user_defined_boxes.contains(cls) {
|
||||
return None;
|
||||
}
|
||||
// Policy gates(従来互換)
|
||||
@ -110,7 +110,7 @@ pub(crate) fn try_known_rewrite_to_dst(
|
||||
if builder.type_ctx.value_origin_newbox.get(&object_value).is_none() {
|
||||
return None;
|
||||
}
|
||||
if !builder.user_defined_boxes.contains(cls) {
|
||||
if !builder.comp_ctx.user_defined_boxes.contains(cls) {
|
||||
return None;
|
||||
}
|
||||
let allow_userbox_rewrite =
|
||||
@ -181,7 +181,7 @@ pub(crate) fn try_unique_suffix_rewrite(
|
||||
let fname = cands.remove(0);
|
||||
// 🎯 Phase 21.7++ Phase 3: StaticMethodId SSOT 実装
|
||||
let id = crate::mir::naming::StaticMethodId::parse(&fname)?;
|
||||
if !builder.user_defined_boxes.contains(&id.box_name) {
|
||||
if !builder.comp_ctx.user_defined_boxes.contains(&id.box_name) {
|
||||
return None;
|
||||
}
|
||||
// unified
|
||||
@ -232,7 +232,7 @@ pub(crate) fn try_unique_suffix_rewrite_to_dst(
|
||||
let fname = cands.remove(0);
|
||||
// 🎯 Phase 21.7++ Phase 3: StaticMethodId SSOT 実装
|
||||
let id = crate::mir::naming::StaticMethodId::parse(&fname)?;
|
||||
if !builder.user_defined_boxes.contains(&id.box_name) {
|
||||
if !builder.comp_ctx.user_defined_boxes.contains(&id.box_name) {
|
||||
return None;
|
||||
}
|
||||
let _name_const = match crate::mir::builder::name_const::make_name_const_result(builder, &fname)
|
||||
|
||||
@ -340,7 +340,7 @@ impl super::MirBuilder {
|
||||
}
|
||||
self.declare_local_in_current_scope(var_name, var_id)?;
|
||||
// SlotRegistry にもローカル変数スロットを登録しておくよ(観測専用)
|
||||
if let Some(reg) = self.current_slot_registry.as_mut() {
|
||||
if let Some(reg) = self.comp_ctx.current_slot_registry.as_mut() {
|
||||
let ty = self.type_ctx.value_types.get(&var_id).cloned();
|
||||
reg.ensure_slot(&var_name, ty);
|
||||
}
|
||||
@ -430,7 +430,7 @@ impl super::MirBuilder {
|
||||
self.type_ctx.value_types
|
||||
.insert(future_id, MirType::Future(Box::new(MirType::Unknown)));
|
||||
self.variable_ctx.variable_map.insert(variable.clone(), future_id);
|
||||
if let Some(reg) = self.current_slot_registry.as_mut() {
|
||||
if let Some(reg) = self.comp_ctx.current_slot_registry.as_mut() {
|
||||
reg.ensure_slot(&variable, None);
|
||||
}
|
||||
return Ok(future_id);
|
||||
@ -449,7 +449,7 @@ impl super::MirBuilder {
|
||||
self.type_ctx.value_types
|
||||
.insert(future_id, MirType::Future(Box::new(inner)));
|
||||
self.variable_ctx.variable_map.insert(variable.clone(), future_id);
|
||||
if let Some(reg) = self.current_slot_registry.as_mut() {
|
||||
if let Some(reg) = self.comp_ctx.current_slot_registry.as_mut() {
|
||||
reg.ensure_slot(&variable, None);
|
||||
}
|
||||
Ok(future_id)
|
||||
@ -481,14 +481,14 @@ impl super::MirBuilder {
|
||||
if let Some(id) = self.variable_ctx.variable_map.get("me").cloned() {
|
||||
return Ok(id);
|
||||
}
|
||||
let me_tag = if let Some(ref cls) = self.current_static_box {
|
||||
let me_tag = if let Some(ref cls) = self.comp_ctx.current_static_box {
|
||||
cls.clone()
|
||||
} else {
|
||||
"__me__".to_string()
|
||||
};
|
||||
let me_value = crate::mir::builder::emission::constant::emit_string(self, me_tag);
|
||||
self.variable_ctx.variable_map.insert("me".to_string(), me_value);
|
||||
if let Some(reg) = self.current_slot_registry.as_mut() {
|
||||
if let Some(reg) = self.comp_ctx.current_slot_registry.as_mut() {
|
||||
reg.ensure_slot("me", None);
|
||||
}
|
||||
// P0: Known 化 — 分かる範囲で me の起源クラスを付与(挙動不変)。
|
||||
|
||||
@ -46,7 +46,7 @@ impl super::MirBuilder {
|
||||
};
|
||||
|
||||
// Phase 201-A: Skip reserved PHI dst ValueIds
|
||||
if !self.reserved_value_ids.contains(&candidate) {
|
||||
if !self.comp_ctx.reserved_value_ids.contains(&candidate) {
|
||||
return candidate;
|
||||
}
|
||||
// Reserved ID - try next one (loop continues)
|
||||
@ -327,7 +327,7 @@ impl super::MirBuilder {
|
||||
}
|
||||
}
|
||||
if let Some(bt) = recv_box {
|
||||
if let Some(mt) = self.plugin_method_sigs.get(&(bt.clone(), method.clone())) {
|
||||
if let Some(mt) = self.comp_ctx.plugin_method_sigs.get(&(bt.clone(), method.clone())) {
|
||||
self.type_ctx.value_types.insert(d, mt.clone());
|
||||
} else {
|
||||
// Phase 84-4-B: ビルトイン Box のメソッド戻り値型推論
|
||||
|
||||
@ -32,7 +32,7 @@ pub fn observe_control_form(builder: &mut MirBuilder, form: &ControlForm) {
|
||||
|
||||
// いまのところ compilation_context が Some のケースは観測対象外にしておく。
|
||||
// (BoxCompilationContext 内の variable_map は別経路で管理されているため)
|
||||
if builder.compilation_context.is_some() {
|
||||
if builder.comp_ctx.compilation_context.is_some() {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -60,7 +60,7 @@ pub fn observe_control_form(builder: &mut MirBuilder, form: &ControlForm) {
|
||||
|
||||
// 変数スロットは SlotRegistry があればそれを優先し、なければ
|
||||
// variable_map と value_types から best-effort で推定するよ。
|
||||
let slots: Vec<SlotMetadata> = if let Some(reg) = builder.current_slot_registry.as_mut() {
|
||||
let slots: Vec<SlotMetadata> = if let Some(reg) = builder.comp_ctx.current_slot_registry.as_mut() {
|
||||
classify_slots_from_registry(reg)
|
||||
} else {
|
||||
classify_slots_from_variable_map(builder)
|
||||
@ -89,7 +89,7 @@ pub fn observe_function_region(builder: &mut MirBuilder) {
|
||||
return;
|
||||
}
|
||||
|
||||
if builder.compilation_context.is_some() {
|
||||
if builder.comp_ctx.compilation_context.is_some() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user