refactor(mir): Remove MetadataContext legacy fields (Phase 2-1/7)

完全移行→削除の安全順序(Option C)に従い、MetadataContext の
deprecated フィールドと sync helpers を完全削除。

## Changes
- Migrated all access sites to metadata_ctx.* (builder methods)
  - current_span → metadata_ctx.current_span() / set_current_span()
  - source_file → metadata_ctx.current_source_file() / set_source_file() / clear_source_file()
  - hint_sink → metadata_ctx.hint_scope_enter/leave/join_result()
  - current_region_stack → metadata_ctx.push_region/pop_region/current_region_stack()
- Removed 4 deprecated fields from MirBuilder
  - current_span, source_file, hint_sink, current_region_stack
- Removed 2 sync helpers
  - sync_metadata_ctx_to_legacy(), sync_legacy_to_metadata_ctx()
- Updated 10 files with direct field accesses

## Files Modified
- src/mir/builder.rs: -56 lines (fields + sync helpers + initialization)
- src/mir/builder/exprs.rs: metadata_ctx.set_current_span()
- src/mir/builder/exprs_peek.rs: metadata_ctx.current_span()
- src/mir/builder/if_form.rs: metadata_ctx.current_span()
- src/mir/builder/phi.rs: metadata_ctx.current_span()
- src/mir/builder/stmts.rs: metadata_ctx.set_current_span()
- src/mir/builder/utils.rs: metadata_ctx.current_span()
- src/mir/loop_api.rs: metadata_ctx.current_span()
- src/mir/region/observer.rs: metadata_ctx.push/pop_region()
- src/mir/utils/phi_helpers.rs: metadata_ctx.current_span()

## Tests
- cargo build --release: SUCCESS (1m 10s)
- cargo test --release --lib: 1029 PASS, 4 FAIL (pre-existing)
- Deprecation warnings: 469 → 435 (-34 warnings)

## Verification
 No direct access to removed fields (grep count: 0)
 No sync helper calls (grep count: 0)
 Build success
 MetadataContext is now complete SSOT (二重管理解消)

Phase 2 Progress: 1/7 contexts complete (MetadataContext )

🎉 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
nyash-codex
2025-12-15 22:44:38 +09:00
parent 905a2b97fe
commit a898e99310
10 changed files with 16 additions and 72 deletions

View File

@ -9,7 +9,7 @@ impl super::MirBuilder {
// Main expression dispatcher
pub(super) fn build_expression_impl(&mut self, ast: ASTNode) -> Result<ValueId, String> {
// Track current source span for downstream instruction emission
self.current_span = ast.span();
self.metadata_ctx.set_current_span(ast.span());
if std::env::var("NYASH_LOOPFORM_DEBUG").is_ok() {
if matches!(ast, ASTNode::Loop { .. }) {
eprintln!("[build_expression_impl] === ENTRY === processing Loop node");

View File

@ -124,7 +124,7 @@ impl super::MirBuilder {
cur_bb,
result_val,
phi_inputs,
self.current_span,
self.metadata_ctx.current_span(),
);
} else {
self.emit_instruction(super::MirInstruction::Phi {

View File

@ -30,7 +30,7 @@ impl<'a> PhiBuilderOps for ToplevelOps<'a> {
block,
dst,
inputs,
self.0.current_span,
self.0.metadata_ctx.current_span(),
);
} else {
self.0.emit_instruction(MirInstruction::Phi {

View File

@ -85,7 +85,7 @@ impl MirBuilder {
cur_bb,
merged,
inputs,
self.current_span,
self.metadata_ctx.current_span(),
);
} else {
self.emit_instruction(MirInstruction::Phi {

View File

@ -220,7 +220,7 @@ impl super::MirBuilder {
/// - Expression としての If値を使うは build_expression 経由のまま
pub(super) fn build_statement(&mut self, node: ASTNode) -> Result<ValueId, String> {
// Align current_span to this statement node before lowering expressions under it.
self.current_span = node.span();
self.metadata_ctx.set_current_span(node.span());
match node {
// Phase 212.5: Statement としての If 処理
ASTNode::If {

View File

@ -510,7 +510,7 @@ impl super::MirBuilder {
// Propagate effects on the block
block.insert_spanned_after_phis(SpannedInstruction {
inst: super::MirInstruction::Copy { dst, src },
span: self.current_span,
span: self.metadata_ctx.current_span(),
});
// Lightweight metadata propagation (unified)
crate::mir::builder::metadata::propagate::propagate(self, src, dst);