feat(mir): Phase 136 Step 7/7 - CompilationContext extraction
**Step 7/7 Complete**: Extract compilation-related fields into CompilationContext **抽出したフィールド** (15個): - compilation_context: Box compilation context - current_static_box: Current static box name - user_defined_boxes: User-defined box registry - reserved_value_ids: Reserved ValueIds for PHI - fn_body_ast: Function body AST for capture analysis - weak_fields_by_box: Weak field registry - property_getters_by_box: Property getter registry - field_origin_class: Field origin tracking - field_origin_by_box: Class-level field origin - static_method_index: Static method index - method_tail_index: Method tail index (fast lookup) - method_tail_index_source_len: Source size snapshot - type_registry: Type registry (TypeRegistryBox) - current_slot_registry: Function scope SlotRegistry - plugin_method_sigs: Plugin method signatures **新規ファイル**: - src/mir/builder/compilation_context.rs (435 lines) - CompilationContext struct with 15 fields - Helper methods for all compilation operations - Comprehensive tests (13 test cases) **MirBuilder 統合**: - Added comp_ctx: CompilationContext field - Marked 15 legacy fields as #[deprecated] - CompilationContext::with_plugin_sigs() initialization **テスト結果**: - ✅ cargo build --release (469 warnings - deprecated) - ✅ cargo test --release --lib (1029/1033 PASS) - ✅ phase135_trim_mir_verify.sh (PASS) **影響範囲**: - 12 files use comp_ctx fields (87 total usages) - 36 deprecated fields in builder.rs (ready for Phase 2 cleanup) **Phase 136 Status**: ✅ 7/7 Context Boxes Complete! - TypeContext, CoreContext, ScopeContext (Steps 1-3) - BindingContext, VariableContext, MetadataContext (Steps 4-6) - CompilationContext (Step 7) - NOW COMPLETE **Next Phase**: Legacy field deletion (Phase 2) - Remove #[deprecated] fields from builder.rs - Migrate all code to ctx accessors - Reduce deprecation warnings from 469 → 0 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@ -19,6 +19,7 @@ mod builder_calls;
|
||||
mod call_resolution; // ChatGPT5 Pro: Type-safe call resolution utilities
|
||||
mod calls; // Call system modules (refactored from builder_calls)
|
||||
mod binding_context; // Phase 136 follow-up (Step 4/7): BindingContext extraction
|
||||
mod compilation_context; // Phase 136 follow-up (Step 7/7): CompilationContext extraction
|
||||
mod context; // BoxCompilationContext - 箱理論による静的Boxコンパイル時のコンテキスト分離
|
||||
mod core_context; // Phase 136 follow-up (Step 2/7): CoreContext extraction
|
||||
mod metadata_context; // Phase 136 follow-up (Step 6/7): MetadataContext extraction
|
||||
@ -100,9 +101,11 @@ pub struct MirBuilder {
|
||||
#[deprecated(note = "Use core_ctx.block_gen instead")]
|
||||
pub(super) block_gen: BasicBlockIdGenerator,
|
||||
|
||||
/// 箱理論: Static boxコンパイル時のコンテキスト分離
|
||||
/// [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
|
||||
@ -131,6 +134,13 @@ pub struct MirBuilder {
|
||||
/// Direct field access for backward compatibility (migration in progress).
|
||||
pub(super) metadata_ctx: metadata_context::MetadataContext,
|
||||
|
||||
/// Phase 136 follow-up (Step 7/7): Compilation context
|
||||
/// Consolidates 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, type_registry, current_slot_registry, plugin_method_sigs.
|
||||
/// Direct field access for backward compatibility (migration in progress).
|
||||
pub(super) comp_ctx: compilation_context::CompilationContext,
|
||||
|
||||
/// [DEPRECATED] Variable name to ValueId mapping (for SSA conversion)
|
||||
/// Phase 136 Step 5/7: Moved to variable_ctx.variable_map (backward compat wrapper)
|
||||
/// 注意: compilation_contextがSomeの場合は使用されません
|
||||
@ -155,18 +165,28 @@ pub struct MirBuilder {
|
||||
#[deprecated(note = "Use type_ctx.value_origin_newbox instead")]
|
||||
pub(super) value_origin_newbox: BTreeMap<ValueId, String>,
|
||||
|
||||
/// Names of user-defined boxes declared in the current module
|
||||
/// [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>,
|
||||
|
||||
/// Weak field registry: BoxName -> {weak field names}
|
||||
/// [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>>,
|
||||
|
||||
/// Unified members: BoxName -> {propName -> Kind}
|
||||
/// [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>>,
|
||||
|
||||
/// Remember class of object fields after assignments: (base_id, field) -> class_name
|
||||
/// [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>,
|
||||
/// Class-level field origin (cross-function heuristic): (BaseBoxName, field) -> FieldBoxName
|
||||
/// [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] Optional per-value type annotations (MIR-level): ValueId -> MirType
|
||||
@ -184,20 +204,30 @@ pub struct MirBuilder {
|
||||
#[deprecated(note = "Use type_ctx.value_kinds instead")]
|
||||
pub(super) value_kinds: HashMap<ValueId, super::MirValueKind>,
|
||||
|
||||
/// 関数スコープの SlotRegistry(観測専用)
|
||||
/// [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>,
|
||||
|
||||
/// 🎯 箱理論: 型情報管理の一元化(TypeRegistryBox)
|
||||
/// [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,
|
||||
|
||||
/// Plugin method return type signatures loaded from nyash_box.toml
|
||||
/// [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>,
|
||||
/// Current static box name when lowering a static box body (e.g., "Main")
|
||||
/// [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>,
|
||||
/// Index of static methods seen during lowering: name -> [(BoxName, arity)]
|
||||
/// [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] Function parameter names (for LoopForm PHI construction)
|
||||
@ -205,9 +235,13 @@ pub struct MirBuilder {
|
||||
#[deprecated(note = "Use scope_ctx.function_param_names instead")]
|
||||
pub(super) function_param_names: HashSet<String>,
|
||||
|
||||
/// Fast lookup: method+arity tail → candidate function names (e.g., ".str/0" → ["JsonNode.str/0", ...])
|
||||
/// [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>>,
|
||||
/// Source size snapshot to detect when to rebuild the tail index
|
||||
/// [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] Region 観測用のスタックだよ(FunctionRegion がルート)。
|
||||
@ -216,15 +250,19 @@ pub struct MirBuilder {
|
||||
#[deprecated(note = "Use metadata_ctx.current_region_stack instead")]
|
||||
pub(super) current_region_stack: Vec<RegionId>,
|
||||
|
||||
/// Phase 200-C: Original function body AST for capture analysis
|
||||
/// [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>>,
|
||||
|
||||
/// Phase 201-A: Reserved ValueIds that must not be allocated
|
||||
/// [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>,
|
||||
|
||||
/// [DEPRECATED] Phase 74: BindingId allocation counter (parallel to ValueId)
|
||||
@ -344,6 +382,9 @@ impl MirBuilder {
|
||||
let plugin_method_sigs = plugin_sigs::load_plugin_method_sigs();
|
||||
let core_ctx = core_context::CoreContext::new();
|
||||
|
||||
// Phase 136 Step 7/7: Compilation context (new SSOT)
|
||||
let comp_ctx = compilation_context::CompilationContext::with_plugin_sigs(plugin_method_sigs.clone());
|
||||
|
||||
// フェーズM: no_phi_mode初期化削除
|
||||
#[allow(deprecated)]
|
||||
Self {
|
||||
@ -364,6 +405,7 @@ impl MirBuilder {
|
||||
binding_ctx: binding_context::BindingContext::new(), // Phase 136 Step 4/7: Binding context
|
||||
variable_ctx: variable_context::VariableContext::new(), // Phase 136 Step 5/7: Variable context
|
||||
metadata_ctx: metadata_context::MetadataContext::new(), // Phase 136 Step 6/7: Metadata context
|
||||
comp_ctx, // Phase 136 Step 7/7: Compilation context
|
||||
variable_map: BTreeMap::new(), // Phase 25.1: 決定性確保 (backward compat)
|
||||
lexical_scope_stack: Vec::new(),
|
||||
pending_phis: Vec::new(),
|
||||
|
||||
Reference in New Issue
Block a user