mir: implement proper short-circuit lowering (&&/||) via branch+phi; vm: add NYASH_VM_TRACE exec/phi logs and reg_load diagnostics; vm-fallback: minimal Void guards (push/get_position/line/column), MapBox.birth no-op; smokes: filter builtin Array/Map plugin notices; docs: CURRENT_TASK updated

This commit is contained in:
Selfhosting Dev
2025-09-26 03:30:59 +09:00
parent 041cef875a
commit fd56b8049a
45 changed files with 3022 additions and 204 deletions

View File

@ -0,0 +1,33 @@
Title: MIR Builder — Declaration Indexing (TwoPhase) Design Note
Summary
- Purpose: eliminate ordersensitivity for forward references during AST→MIR lowering without changing language semantics.
- Approach: run a lightweight “Phase A: declaration indexing” over the AST to collect symbols, then perform normal lowering as “Phase B”.
Scope
- Internal compiler detail (builder). No changes to syntax/semantics/flags.
- Applies to: userdefined boxes (instance types) and static methods lookup for bare calls.
Why
- Previous behavior processed AST in appearance order. Forward references (e.g., new JsonParser() before its box declaration) required adhoc preindex_* helpers.
- Centralizing indexing avoids proliferation (preindex_user_boxes, preindex_static_methods, …) and keeps lowering simple.
Design
- Phase A (index_declarations):
- user_defined_boxes: collect nonstatic Box names to decide constructor behavior (skip birth() for user types).
- static_method_index: map method name → [(BoxName, arity)] to resolve bare calls in usingmerged sources.
- Phase B (lowering): unchanged logic uses the above indices.
Invariants
- No behavior change. Only ordering robustness improves.
- Indexing walks AST once (O(N)). Data kept in MirBuilder fields already present.
Implementation Notes
- Function: MirBuilder::index_declarations(&ASTNode)
- Called once at lower_root() entry. Existing adhoc preindex_* replaced by this single pass.
- Keep deltas small and localized to builder lifecycle.
Testing
- Existing smokes cover forward references (using/JSON). No new flags required.
- Acceptance: no stray unresolved calls due to order, no change in MIR output types for the same sources.