Legacy deletion: Remove unused early rewrite functions that were replaced
by BoxCall(slot #0) normalization in Phase 287 P4.
Deleted functions (143 lines):
1. try_early_str_like() - 120 lines
- Complex class inference logic
- Global(Class.str/0) rewrite
- Unique suffix fallback with JsonNode priority
- Replaced by: try_early_str_like_to_dst() using BoxCall(slot #0)
2. try_special_equals() - 22 lines
- Known rewrite + unique suffix for equals
- Replaced by: try_special_equals_to_dst()
These functions were marked #[allow(dead_code)] and had no callers.
Test Results:
✅ VM: local x = 1; print(x.toString()) → "1" (still works)
✅ Build: Success (0 errors)
SSOT: toString normalization via BoxCall(slot #0) is the only path now.
Files changed:
- src/mir/builder/rewrite/special.rs (-143 lines)
🎊 Generated with Claude Code
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
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>
Critical fix: Guards only checked MirType::{Integer,Float,Bool,String}
but missed MirType::Box("IntegerBox") etc. This caused .length().toString()
to be rewritten to Global(Main.toString/0).
Root cause: .length() returns boxed Integer (MirType::Box("IntegerBox"))
not primitive Integer (MirType::Integer), so guards didn't catch it.
Fix: Extended is_primitive check to include boxed primitive types:
MirType::Box(name) if name in ["IntegerBox", "FloatBox", "BoolBox", "StringBox"]
Modified functions in known.rs (all 4):
1. try_known_rewrite (line 61-65)
2. try_known_rewrite_to_dst (line 156-160)
3. try_unique_suffix_rewrite (line 256-260)
4. try_unique_suffix_rewrite_to_dst (line 332-336)
MIR verification:
- All toString() calls now use Method(IntegerBox.toString) ✅
- No more Global("Main.toString/0") calls ✅
Remaining issue (separate bug):
- VM fails with "Unknown method 'toString' on Integer"
- MIR is correct, problem is in VM Method call resolution
- Needs separate investigation
🎉 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Critical fix: Previous guards blocked ALL primitive method calls, not just
toString/stringify/str. This would have broken length(), substring(), etc.
Root cause: Guards in known.rs checked primitive type but NOT method name,
so ANY method call on Integer/Float/Bool/String was blocked.
Fix: Added method name check to all 4 guard locations:
if method == "toString" || method == "stringify" || method == "str" {
// Only then check primitive type
}
Modified functions in known.rs:
1. try_known_rewrite (line 58-71)
2. try_known_rewrite_to_dst (line 151-164)
3. try_unique_suffix_rewrite (line 249-262)
4. try_unique_suffix_rewrite_to_dst (line 323-336)
Verification:
- toString() still works: "1" output ✅
- MIR still uses boxcall (no Global call) ✅
- Other primitive methods (length/substring) NOT affected ✅
Credit: User caught this critical issue before it caused problems!
🎉 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Root cause: x.toString() (x=Integer local var) was incorrectly rewritten to
Global(Main.toString/0) instead of using universal slot toString[#0].
The bug had two layers:
1. Early rewrite guards in special.rs correctly blocked it
2. BUT known.rs rewrite functions recursively called emit_unified_call with
Global("Main.toString/0"), bypassing the primitive type checks
Fix (Box-First Conservative Guards):
- Added primitive type guard (Integer/Float/Bool/String) to ALL 4 rewrite
functions in known.rs:
1. try_known_rewrite (line 56-69)
2. try_known_rewrite_to_dst (line 131-144)
3. try_unique_suffix_rewrite (line 243-256)
4. try_unique_suffix_rewrite_to_dst (line 283-296)
- Added debug trace in unified_emitter.rs to track CallTarget flow
Test case verification:
static box Main { main() { local x = 1; print(x.toString()) } }
Expected: "1" (via universal slot toString[#0])
Before: "Main()" (Global(Main.toString/0) misrewrite)
After: "1" (boxcall via Method slot #0) ✅
MIR verification:
Before: Global("Main.toString/0") in main function
After: boxcall instruction (universal slot) ✅
Files changed:
- src/mir/builder/rewrite/known.rs: 4 functions + primitive guard
- src/mir/builder/rewrite/special.rs: debug trace
- src/mir/builder/calls/unified_emitter.rs: debug trace
SSOT: docs/reference/language/types.md - toString() is universal slot #0🎉 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Phase 25.1b: Complete SSA fix - eliminate all global ValueId usage in function contexts.
Root cause: ~75 locations throughout MIR builder were using global value
generator (self.value_gen.next()) instead of function-local allocator
(f.next_value_id()), causing SSA verification failures and runtime
"use of undefined value" errors.
Solution:
- Added next_value_id() helper that automatically chooses correct allocator
- Fixed 19 files with ~75 occurrences of ValueId allocation
- All function-context allocations now use function-local IDs
Files modified:
- src/mir/builder/utils.rs: Added next_value_id() helper, fixed 8 locations
- src/mir/builder/builder_calls.rs: 17 fixes
- src/mir/builder/ops.rs: 8 fixes
- src/mir/builder/stmts.rs: 7 fixes
- src/mir/builder/emission/constant.rs: 6 fixes
- src/mir/builder/rewrite/*.rs: 10 fixes
- + 13 other files
Verification:
- cargo build --release: SUCCESS
- Simple tests with NYASH_VM_VERIFY_MIR=1: Zero undefined errors
- Multi-parameter static methods: All working
Known remaining: ValueId(22) in Stage-B (separate issue to investigate)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
- Unify standard method calls to emit_unified_call; route via RouterPolicy and apply rewrite::{special,known} at a single entry.\n- Stabilize emit-time invariants: LocalSSA finalize + BlockSchedule PHI→Copy→Call ordering; metadata propagation on copies.\n- Known rewrite default ON (userbox only, strict guards) with opt-out flag NYASH_REWRITE_KNOWN_DEFAULT=0.\n- Expand TypeAnnotation whitelist (is_digit_char/is_hex_digit_char/is_alpha_char/Map.has).\n- Docs: unified-method-resolution design note; Quick Reference normalization note; selfhosting/quickstart.\n- Tools: add tools/selfhost_smoke.sh (dev-only).\n- Keep behavior unchanged for Unknown/core/user-instance via BoxCall fallback; all tests green (quick/integration).
- Fix condition_fn resolution: Value call path + dev safety + stub injection
- VM bridge: handle Method::birth via BoxCall; ArrayBox push/get/length/set direct bridge
- Receiver safety: pin receiver in method_call_handlers to avoid undefined use across blocks
- Local vars: materialize on declaration (use init ValueId; void for uninit)
- Prefer legacy BoxCall for Array/Map/String/user boxes in emit_box_or_plugin_call (stability-first)
- Test runner: update LLVM hint to llvmlite harness (remove LLVM_SYS_180_PREFIX guidance)
- Docs/roadmap: update CURRENT_TASK with unified default-ON + guards
Note: NYASH_DEV_BIRTH_INJECT_BUILTINS=1 can re-enable builtin birth() injection during migration.