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")
|
||||
|
||||
Reference in New Issue
Block a user