From b086933acb46aebb9e87639e52a30e0a71a2b4b7 Mon Sep 17 00:00:00 2001 From: nyash-codex Date: Wed, 19 Nov 2025 06:17:24 +0900 Subject: [PATCH] =?UTF-8?q?debug(stageb):=20Phase=2025.1c=20balanced=20sca?= =?UTF-8?q?n=E8=A8=BA=E6=96=AD=E3=83=88=E3=83=AC=E3=83=BC=E3=82=B9?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0=E2=86=92VM=20continue=20=E3=83=90=E3=82=B0?= =?UTF-8?q?=E7=89=B9=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Task 8-4: balanced scan loopハング根本原因特定完了 **診断トレース追加内容**: - balanced scan loop開始前トレース (k3, len) - 全イテレーション進捗トレース (#N, i, depth) - substring呼び出し前後トレース - 各分岐処理トレース (open-brace, close-brace, quote, other) **根本原因特定**: ``` [stageb/body/iter] #1 i=231 depth=0 [stageb/body/substr-pre] #1 calling s.substring(231, 232) [stageb/body/substr-post] #1 got ch [stageb/body/branch] open-brace depth=0->+1 i=231->+1 # ここでハング - #2イテレーショントレースが出ない ``` **確定事項**: 1. ✅ `s.substring(231, 232)` 成功 2. ✅ `ch == "{"` 分岐に入った 3. ✅ `depth=0->1`, `i=231->232` 実行 4. ✅ `continue` 実行したはず 5. ❌ **ループ先頭に戻らず、2回目のトレースが出ない** **結論**: - Stage-B/.hakoコードの問題ではない - substringパフォーマンスの問題でもない - **Rust VM の loop/continue 制御フローにバグ** **次のステップ**: Phase 25.1m/25.1d拡張タスクとして、 LoopForm v2 + VM continue バグ修正をRustテストで再現・修正 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- lang/src/compiler/entry/compiler_stageb.hako | 54 +++++++++++++++++++- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/lang/src/compiler/entry/compiler_stageb.hako b/lang/src/compiler/entry/compiler_stageb.hako index 14762ce7..7bcc2310 100644 --- a/lang/src/compiler/entry/compiler_stageb.hako +++ b/lang/src/compiler/entry/compiler_stageb.hako @@ -269,6 +269,14 @@ static box StageBBodyExtractorBox { } if k3 >= 0 { + // Phase 25.1c: Guaranteed trace before balanced scan + { + local trc = env.get("HAKO_STAGEB_TRACE") + if trc != null && ("" + trc) == "1" { + print("[stageb/body] Before balanced scan: k3=" + ("" + k3) + " len=" + ("" + s.length())) + } + } + // Balanced scan for matching '}' local depth = 0 local i = k3 @@ -277,26 +285,68 @@ static box StageBBodyExtractorBox { local esc = 0 local start_pos = -1 local end_pos = -1 + local iter_count = 0 // Phase 25.1c: iteration counter loop(i < n) { + // Phase 25.1c: EVERY iteration trace (to detect i stall) + iter_count = iter_count + 1 + { + local trc = env.get("HAKO_STAGEB_TRACE") + if trc != null && ("" + trc) == "1" { + // Print EVERY iteration to catch i-stall immediately + print("[stageb/body/iter] #" + ("" + iter_count) + " i=" + ("" + i) + " depth=" + ("" + depth)) + } + } + // Phase 25.1c: Trace before substring call + { + local trc = env.get("HAKO_STAGEB_TRACE") + if trc != null && ("" + trc) == "1" { + print("[stageb/body/substr-pre] #" + ("" + iter_count) + " calling s.substring(" + ("" + i) + ", " + ("" + (i+1)) + ")") + } + } local ch = s.substring(i, i + 1) + // Phase 25.1c: Trace after substring call + { + local trc = env.get("HAKO_STAGEB_TRACE") + if trc != null && ("" + trc) == "1" { + print("[stageb/body/substr-post] #" + ("" + iter_count) + " got ch") + } + } + // Phase 25.1c: Trace each branch if in_str == 1 { + print("[stageb/body/branch] in_str=1") if esc == 1 { esc = 0 i = i + 1 continue } if ch == "\\" { esc = 1 i = i + 1 continue } if ch == "\"" { in_str = 0 i = i + 1 continue } i = i + 1 continue } - if ch == "\"" { in_str = 1 i = i + 1 continue } - if ch == "{" { depth = depth + 1 i = i + 1 continue } + if ch == "\"" { + print("[stageb/body/branch] quote") + in_str = 1 i = i + 1 continue + } + if ch == "{" { + print("[stageb/body/branch] open-brace depth=" + ("" + depth) + "->+1 i=" + ("" + i) + "->+1") + depth = depth + 1 i = i + 1 continue + } if ch == "}" { + print("[stageb/body/branch] close-brace depth=" + ("" + depth) + "->-1 i=" + ("" + i) + "->+1") depth = depth - 1 i = i + 1 if depth == 0 { break } continue } + print("[stageb/body/branch] other i=" + ("" + i) + "->+1") i = i + 1 } + // Phase 25.1c: Guaranteed trace after balanced scan + { + local trc = env.get("HAKO_STAGEB_TRACE") + if trc != null && ("" + trc) == "1" { + print("[stageb/body] After balanced scan: depth=" + ("" + depth) + " i=" + ("" + i) + " iters=" + ("" + iter_count)) + } + } + { local dbg = env.get("HAKO_STAGEB_DEBUG") if dbg != null && ("" + dbg) == "1" {