fix(builder): BoxCompilationContext clear()アプローチ確立

🎯 箱理論: swap累積バグを修正し、clear()で完全独立化を実現

## 問題
- swap実装は ctx に変数が累積され、次のメソッドで汚染される
- StageBArgsBox.resolve_src で ValueId(21) 未定義エラー

## 解決策
- swap → clear() に変更(開始時・終了時両方)
- context_active mode: clear() のみ(完全独立)
- legacy mode: saved_var_map で従来の挙動維持

## 成果
 StageBArgsBox.resolve_src - 成功!
 StageBBodyExtractorBox.build_body_src - 次の問題箇所(進展!)

## 実装
- src/mir/builder/builder_calls.rs:
  - 開始時: context_active なら clear()(swap削除)
  - 終了時: context_active なら clear()(swap back削除)
  - legacy mode: saved_var_map で復元

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
nyash-codex
2025-11-17 15:57:34 +09:00
parent 757b0fcfc9
commit c27f6466e8
3 changed files with 39 additions and 29 deletions

View File

@ -70,7 +70,7 @@ static box Stage1UsingResolverMini {
/// Verify MIR/SSA for ParserBox.parse_program2 in isolation by compiling a small wrapper.
#[test]
fn mir_parserbox_parse_program2_verifies() {
fn mir_parserbox_parse_program2_harness_parses_minimal_source() {
// Minimal wrapper that brings ParserBox into scope and calls parse_program2.
let src = r#"
using lang.compiler.parser.parser_box as ParserBox
@ -84,15 +84,16 @@ static box ParserBoxHarness {
}
"#;
let ast: ASTNode = NyashParser::parse_from_string(src).expect("parse ok");
// Stage3 構文キーワード `local` を含む最小ソースを ParserBoxHarness でパースする
let harness_ast: ASTNode = NyashParser::parse_from_string(src).expect("parse ok");
let mut mc = MirCompiler::with_options(false);
let cr = mc.compile(ast).expect("compile");
let cr = mc.compile(harness_ast).expect("compile");
let mut verifier = MirVerifier::new();
if let Err(errors) = verifier.verify_module(&cr.module) {
for e in &errors {
eprintln!("[mir-verify] {}", e);
}
panic!("MIR verification failed for ParserBoxHarness.parse_program2");
panic!("MIR verification failed for ParserBoxHarness");
}
}