3.9 KiB
Nyash Refactor Roadmap (Pre–Self-Hosting)
This document lists large modules, proposes safe splits/commonization, and outlines the MIR13 cleanup plan.
Large Modules to Split
Targets are chosen by size and cohesion. Splits are incremental and build-preserving; move code in small steps and re-export in mod.rs.
-
src/mir/verification.rs(~965 loc)- Split into:
mir/verification/{mod.rs,basic.rs,types.rs,control_flow.rs,ownership.rs}. - First move leaf helpers and pass-specific checks; keep public API and
pub useto avoid churn.
- Split into:
-
src/mir/builder.rs(~930 loc)- Split into:
mir/builder/{mod.rs,exprs.rs,stmts.rs,decls.rs,control_flow.rs}. - Extract expression/statement builders first. Keep tests (if any) colocated.
- Split into:
-
src/mir/instruction.rs(~896 loc)- Near-term: introduce
mir/instruction/{mod.rs,core.rs,ops.rs,calls.rs}without changing the enum surface. - Medium-term: migrate to MIR13 (see below) and delete legacy variants.
- Near-term: introduce
-
src/mir/optimizer.rs(~875 loc)- Split passes into:
mir/optimizer/{mod.rs,constant_folding.rs,dead_code.rs,inline.rs,type_inference.rs}. - Keep a simple pass runner that sequences the modules.
- Split passes into:
-
src/runner/mod.rs(~885 loc)- Extract modes into
runner/modes/{vm.rs,jit.rs,mir_interpreter.rs,llvm.rs}if not already, and move glue torunner/lib.rs. - Centralize CLI arg parsing in a dedicated module.
- Extract modes into
-
src/backend/vm_instructions/boxcall.rs(~881 loc)- Group by box domain:
boxcall/{array.rs,map.rs,ref.rs,weak.rs,plugin.rs,core.rs}. - Long-term: most of these become
BoxCallhandlers driven by method ID tables.
- Group by box domain:
MIR13 Cleanup Plan
A large portion of pre-MIR13 variants remain. Current occurrences:
- ArrayGet: 11, ArraySet: 11
- RefNew: 8, RefGet: 15, RefSet: 17
- TypeCheck: 13, Cast: 13
- PluginInvoke: 14, Copy: 13, Debug: 8, Print: 10, Nop: 9, Throw: 12, Catch: 13, Safepoint: 14
Phased migration (mechanical, testable per phase):
-
Introduce shims
- Add
BoxCallhelpers covering array/ref/weak/map ops and plugin methods. - Add
TypeOp::{Check,Cast}modes to map legacyTypeCheck/Cast.
- Add
-
Replace uses (non-semantic changes)
- Replace within:
backend/dispatch.rs,backend/mir_interpreter.rs,backend/cranelift/*,backend/wasm/codegen.rs,mir/printer.rs, tests. - Keep legacy variants in enum but mark Deprecated for a short period.
- Replace within:
-
Tighten verification/optimizer
- Update
verification.rsto reason aboutBoxCall/TypeOponly. - Update optimizer patterns (e.g., fold Copy → Load/Store; drop Nop/Safepoint occurrences).
- Update
-
Delete legacy variants
- Remove
ArrayGet/Set, RefNew/Get/Set, PluginInvoke, TypeCheck, Cast, Copy, Debug, Print, Nop, Throw, Catch, Safepoint. - Update discriminant printer and state dumps accordingly.
- Remove
Use tools/mir13-migration-helper.sh to generate per-file tasks and verify.
Commonization Opportunities
-
Backend dispatch duplication
backend/dispatch.rs,backend/vm.rs, and Cranelift JIT lowerings handle overlapping instruction sets. Centralize instruction semantics interfaces (traits) and keep backend-specific execution and codegen in adapters.
-
Method ID resolution
runtime/plugin_loader_v2and backend call sites both compute/lookup method IDs. Provide a single resolver module with caching shared by VM/JIT/LLVM.
-
CLI/runtime bootstrap
- Move repeated plugin host init/logging messages into a small
runtime/bootstrap.rswith a singleinit_plugins(&Config)entry point used by all modes.
- Move repeated plugin host init/logging messages into a small
Suggested Order of Work
- Split
mir/verificationandmir/builderinto submodules (no behavior changes). - Add
BoxCallshims andTypeOpmodes; replace printer/dispatch/codegen uses. - Update verification/optimizer for the unified ops.
- Delete legacy variants and clean up dead code.
- Tackle
runner/mod.rsandbackend/vm_instructions/boxcall.rssplits.
Each step should compile independently and run tools/smoke_vm_jit.sh to validate VM/JIT basics.