3.1 KiB
3.1 KiB
MIR 25-Instruction Mapping Plan
Current State: 32 Instructions → Target: 25 Instructions
Tier-0: Universal Core (8 instructions)
- Const ✅ (already exists)
- BinOp ✅ (already exists)
- Compare ✅ (already exists)
- Branch ✅ (already exists)
- Jump ✅ (already exists)
- Phi ✅ (already exists)
- Call ✅ (already exists)
- Return ✅ (already exists)
Tier-1: Nyash Semantics (12 instructions)
- NewBox ✅ (already exists)
- BoxFieldLoad ← RENAME from Load/RefGet
- BoxFieldStore ← RENAME from Store/RefSet
- BoxCall ✅ (already exists)
- Safepoint ✅ (already exists as separate instruction)
- RefGet → RENAME to RefGet ✅
- RefSet → RENAME to RefSet ✅
- WeakNew ✅ (already exists)
- WeakLoad ✅ (already exists)
- WeakCheck ← NEW (check weak reference validity)
- Send ← NEW (Bus communication)
- Recv ← NEW (Bus communication)
Tier-2: Implementation Assistance (5 instructions)
- TailCall ← NEW (tail call optimization)
- Adopt ← NEW (ownership transfer)
- Release ← NEW (ownership release)
- MemCopy ← NEW (optimized memory operations)
- AtomicFence ← RENAME from BarrierRead/BarrierWrite
Instructions to Remove/Consolidate (7 instructions)
- UnaryOp → Merge into BinOp or eliminate
- Load → Consolidate into BoxFieldLoad
- Store → Consolidate into BoxFieldStore
- ArrayGet → Use BoxFieldLoad with array indexing
- ArraySet → Use BoxFieldStore with array indexing
- Cast → Eliminate or merge into BinOp
- Copy → Eliminate (optimization-specific)
- Debug → Remove from MIR (keep as separate system)
- Print → Use Call with print function
- Throw → Use Call with exception function
- Catch → Use Call with catch handler
- RefNew → Eliminate (use NewBox)
- TypeCheck → Use Compare with type introspection
- BarrierRead/BarrierWrite → Consolidate into AtomicFence
- FutureNew/FutureSet/Await → Use BoxCall with Future methods
Effect System Mapping
Current → New Effect Categories
- Pure: Const, BinOp, Compare, Phi, RefGet, WeakNew, WeakLoad, WeakCheck
- Mut: BoxFieldStore, RefSet, Adopt, Release, MemCopy
- Io: Send, Recv, Safepoint, AtomicFence
- Control: Branch, Jump, Return, TailCall
- Context-dependent: Call, BoxCall
Implementation Strategy
Phase 1: Core Instruction Consolidation
- Rename Load → BoxFieldLoad
- Rename Store → BoxFieldStore
- Remove eliminated instructions
- Add missing new instructions
Phase 2: Effect System Update
- Update effect classification to 4 categories
- Update all instruction effect mappings
- Implement effect-based optimization rules
Phase 3: Backend Updates
- Update Interpreter backend
- Update VM backend
- Update WASM backend
- Ensure all support exactly 25 instructions
Phase 4: Verification System
- Implement ownership forest verification
- Add strong cycle detection
- Add weak reference safety checks
- Implement RefSet ownership validation