Phase 21.6 solidification: chain green (return/binop/loop/call); add Phase 21.7 normalization plan (methodize static boxes). Update CURRENT_TASK.md and docs.
This commit is contained in:
@ -6,16 +6,48 @@ Acceptance (all must be green on this host)
|
||||
- VM: MIR(JSON) for minimal loop returns 10
|
||||
- ny‑llvmc(crate) EXE: returns 10
|
||||
|
||||
Canaries to run
|
||||
- bash tools/dev/stageb_loop_json_canary.sh
|
||||
- bash tools/dev/phase216_chain_canary.sh
|
||||
- bash tools/dev/phase216_chain_canary_return.sh
|
||||
- bash tools/dev/phase216_chain_canary_binop.sh
|
||||
- bash tools/dev/phase216_chain_canary_loop.sh
|
||||
- bash tools/dev/phase216_chain_canary_call.sh (Phase 21.6 extension)
|
||||
|
||||
Guardrails
|
||||
- No default behavior changes; all aids behind env toggles.
|
||||
- Logs quiet; tags/dev traces are opt‑in.
|
||||
- No llvmlite in default chain; crate backend is main line.
|
||||
|
||||
Canaries to run
|
||||
- bash tools/dev/stageb_loop_json_canary.sh
|
||||
- bash tools/dev/phase216_chain_canary.sh
|
||||
|
||||
Rollback
|
||||
- Parser fallback in parse_loop is conservative; remove after VM/gpos fix lands.
|
||||
- Keep canaries; they protect against regressions.
|
||||
|
||||
## Phase 21.6 Call Support Extension
|
||||
|
||||
**Toggles**:
|
||||
- `HAKO_STAGEB_FUNC_SCAN=1`: Enable function definition scanning in Stage-B
|
||||
- `HAKO_MIR_BUILDER_FUNCS=1`: Enable function definition lowering in MirBuilder (unused - Rust delegate used)
|
||||
|
||||
**Implementation**:
|
||||
1. Stage-B function scanner extracts `method <name>(params){ body }` definitions
|
||||
2. Stage-B injects `defs` array into Program(JSON v0)
|
||||
3. Rust delegate (src/runner/json_v0_bridge/) processes `defs` and generates MIR functions
|
||||
4. Function names are qualified as `Box.method` (e.g., `Main.add`)
|
||||
|
||||
**Current Status**:
|
||||
- ✅ Stage-B scanning implemented (compiler_stageb.hako)
|
||||
- ✅ Rust delegate defs processing implemented (ast.rs, lowering.rs)
|
||||
- ✅ MIR functions generated with correct signatures and bodies
|
||||
- ⚠️ Call resolution incomplete: calls still use dynamic string lookup ("add") instead of static Main.add reference
|
||||
|
||||
**Next Steps for Call Completion**:
|
||||
- Need to resolve Call("add") → Call(Main.add) at lowering time
|
||||
- Implement call target resolution in json_v0_bridge/lowering.rs
|
||||
- Update Call instruction to use function reference instead of string
|
||||
- Alternative: use MirCall with Callee::Function for local calls
|
||||
|
||||
**撤去条件 (Removal Criteria)**:
|
||||
- After Phase 22 introduces proper local function scoping with Callee typed calls
|
||||
- Or when unified with broader namespace/using system Phase 15.5+
|
||||
|
||||
|
||||
@ -0,0 +1,20 @@
|
||||
Phase 21.7 — Normalization Checklist (Methodization)
|
||||
|
||||
Targets (must be green)
|
||||
- Naming: all user functions canonicalized as Box.method/N
|
||||
- Arity: params.len == call.args.len (or explicit mapping when defs absent)
|
||||
- Methodization (dev toggle): Global("Box.method") → Method(receiver=static singleton)
|
||||
- VM: Method calls execute via ensure_static_box_instance for static boxes
|
||||
- LLVM: mir_call(Method) lowering produces correct IR; rc parity preserved
|
||||
|
||||
Canaries
|
||||
- tools/dev/phase216_chain_canary_call.sh — remains PASS when OFF, PASS when ON
|
||||
- Add: tools/dev/phase217_methodize_canary.sh (dev) — asserts method callee usage in MIR or IR tags
|
||||
|
||||
Toggles
|
||||
- HAKO_MIR_BUILDER_METHODIZE=1 (new)
|
||||
- HAKO_STAGEB_FUNC_SCAN=1 / HAKO_MIR_BUILDER_FUNCS=1 / HAKO_MIR_BUILDER_CALL_RESOLVE=1 (existing)
|
||||
|
||||
Rollback
|
||||
- Disable HAKO_MIR_BUILDER_METHODIZE; remove methodization rewrite; keep Global path active.
|
||||
|
||||
@ -0,0 +1,42 @@
|
||||
Phase 21.7 — Normalization & Unification (Methodize Static Boxes)
|
||||
|
||||
Goal
|
||||
- Unify user-defined function calls onto a single, consistent representation.
|
||||
- Move from ad-hoc Global("Box.method") calls toward Method calls with an explicit (singleton) receiver when appropriate.
|
||||
- Keep defaults stable; introduce dev toggles and canaries; then promote to default after green.
|
||||
|
||||
Scope
|
||||
- Parser/Stage‑B: keep emitting Program(JSON v0). No schema changes required for MVP.
|
||||
- MirBuilder: add methodization (dev toggle) that:
|
||||
- Emits method functions as-is (defs) and/or provides a mapping to Method calls
|
||||
- Rewrites Global("Box.method") to Method {receiver=static singleton, box_name, method}
|
||||
- Preserves arity and naming as Box.method/N
|
||||
- VM: handle Method calls uniformly (receiver resolved via ensure_static_box_instance for static boxes).
|
||||
- LLVM: rely on mir_call(Method) lowering (already supported) and provide the static receiver where needed.
|
||||
|
||||
Toggles
|
||||
- HAKO_MIR_BUILDER_METHODIZE=1 — enable methodization (rewrite Global→Method with static singleton receiver)
|
||||
- HAKO_STAGEB_FUNC_SCAN=1 — Stage‑B defs scan (already available)
|
||||
- HAKO_MIR_BUILDER_FUNCS=1 — defs→MIR 関数化(既存)
|
||||
- HAKO_MIR_BUILDER_CALL_RESOLVE=1 — Global 名解決(既存)
|
||||
|
||||
Design Rules
|
||||
- Naming: canonical "Box.method/N". Arity N must equal params.len (or callsite args len if defs unknown).
|
||||
- Receiver: for static boxes, provide implicit singleton receiver. For instance boxes, preserve existing Method path.
|
||||
- Effects: preserve EffectMask semantics; do not broaden side effects.
|
||||
- Fail‑Fast: when rewrite is ambiguous (multiple candidates), keep original form and WARN under dev toggle; never change defaults silently.
|
||||
|
||||
Acceptance
|
||||
- Canaries:
|
||||
- call (global style) passes when methodization ON (rc unchanged)
|
||||
- Existing return/binop/loop/call (global) canaries remain green when OFF
|
||||
- A dedicated methodization canary asserts presence of callee.type=="Method" in MIR(JSON v1) or correct v0 lowering
|
||||
|
||||
Rollout Plan
|
||||
1) Ship behind HAKO_MIR_BUILDER_METHODIZE=1 with canaries
|
||||
2) Validate on representative apps (selfhost‑first path)
|
||||
3) Promote to default ON only after green for a cycle; keep rollback instructions
|
||||
|
||||
Rollback
|
||||
- Disable HAKO_MIR_BUILDER_METHODIZE. Revert to Global("Box.method") resolution path (current 21.6 behavior).
|
||||
|
||||
Reference in New Issue
Block a user