Root cause: toString/stringify/str were being rewritten to Global/Method calls with class inference, causing Main.toString/0 to be called for primitives. Fix (Box-First + Legacy Deletion): 1. ✅ MIR Builder - toString normalization (special.rs) - ALWAYS emit BoxCall with method_id=0 for toString/stringify/str - Do NOT rewrite to Global(Class.str/0) or Method calls - DELETED 70+ lines of complex class inference logic - Primitive guard with method name filter (known.rs) 2. ✅ JSON Serializer - method_id output (mir_json_emit.rs) - Include method_id field in BoxCall JSON for LLVM 3. ✅ LLVM Backend - universal slot #0 support - Extract method_id from JSON (instruction_lower.py) - Box primitives via nyash.box.from_i64 (boxcall.py) - Invoke toString via plugin system with method_id=0 - ⚠️ TODO: Add nyash.integer.tostring_h to kernel Test Results: ✅ VM: local x = 1; print(x.toString()) → "1" (PASS) ✅ VM: array_length test (boxed Integer) → PASS ⚠️ LLVM: Compiles successfully, needs kernel function SSOT: slot_registry - toString is ALWAYS universal slot #0 Legacy Deleted: - special.rs: Complex class inference rewrite (~70 lines) - special.rs: Unique suffix fallback for toString - special.rs: Main box special handling Files changed: - src/mir/builder/rewrite/special.rs (try_early_str_like_to_dst) - src/mir/builder/rewrite/known.rs (primitive guards x4) - src/runner/mir_json_emit.rs (method_id serialization x2) - src/llvm_py/builders/instruction_lower.py (method_id extraction) - src/llvm_py/instructions/boxcall.py (slot #0 handler) - docs/reference/language/quick-reference.md (toString SSOT) 🎊 Generated with Claude Code Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
3.6 KiB
3.6 KiB
Phase 287 P4: Quick 残failの根治(core回帰の修正 + テストの仕様合わせ)
目的
tools/smokes/v2/run.sh --profile quickを fail=0 で安定させる。- P3で「責務外」を integration に寄せたあとに残った core回帰(意味論バグ)を直す。
- REPL はまず
hakorune --replの 明示起動から開始する(仕様はdocs/reference/language/repl.mdをSSOT)。
優先度1: String mixed + の SSOT へ戻す(暗黙 stringify を入れない)
症状
"" + a.length() が unsupported binop Add on String("") and Integer(0) で落ちる。
この挙動自体は SSOT(Phase 275 C2 / types.md)では正しい。問題は「テスト/ドキュメントが旧挙動を期待している」こと。
仕様(SSOT)
docs/reference/language/types.mdの+(C2: String+String only)に従う。docs/reference/language/quick-reference.mdも SSOT に合わせて修正する(String mixed はTypeError)。
実装方針(構造的)
- 実装(VM/LLVM)に自動文字列化の分岐を追加しない(Phase 287 で仕様拡張をしない)。
- 連結したいテストは明示的に
x.toString()を使う(例:"len=" + a.length().toString())。
受け入れ(smokeで固定)
この整理により、少なくとも以下の失敗群がまとめて解消する可能性が高い(要再計測):
array_length_vmarray_oob_get_tag_vmindex_substring_vmmap_len_set_get_vmmap_values_sum_vmstring_size_alias
優先度2: JoinIR ループ非対応パターンの扱い(quick から外す)
症状
[joinir/freeze] Loop lowering failed: JoinIR does not support this pattern
方針
- これは「言語機能の最低ゲート」ではなく「JoinIRループ網羅/拡張」の範囲なので、Phase 287 では quick に残さない。
- 対象テストは integration へ移動し、必要なら
[SKIP:joinir](理由固定)にする。
優先度3: Top-level local(file mode禁止 / REPL許可)へテストを合わせる
仕様(決定)
- file mode は top-level 実行文禁止(宣言のみ)。top-level
localも禁止。 - REPL は
hakorune --replで明示起動し、暗黙localを許可する(docs/reference/language/repl.md)。
具体対応
run_nyash_vm -c 'local ...; ...'のように top-level 実行文を前提にしたテストは、quick からは外すか、次のいずれかに書き換える:function main(){ ... }に包む(entryはNYASH_ENTRY_ALLOW_TOPLEVEL_MAIN=1でOK)static box Main { main(){ ... } }に包む
- 「top-level local が壊れている」方向へ直すのは、REPL/file mode の仕様を汚しやすいので今はやらない(WIPブランチへ隔離済み)。
優先度4: 残りの個別(環境依存 / 揺れ)を quick のSSOTへ寄せる
filebox_basic.shのように host依存が避けられないものは[SKIP:env]で理由固定。async_await.sh/gc_mode_off.shは “環境依存” と断定しない。まずログを見て:- core回帰なら修正(quickに残す)
- 統合寄り/重いなら integration へ移す
作業手順(推奨)
--format jsonで fail をSSOT化(pathとdurationでソート)- まず優先度1(String+Integer)を修正 → quick を再実行
- JoinIR freeze のテストは integration へ移動(必要ならSKIP理由固定)
- top-level 実行文前提のテストは「mainに包む」か integration へ
- 残った fail を A/B/C(env/統合/コア)で片付け、quick fail=0 で締める