2.5 KiB
2.5 KiB
Refactoring Candidates — Phase 15 (Mainline only)
Scope: PyVM/LLVM/Runner mainline. JIT/Cranelift is explicitly out of scope for this pass.
Goals
- Improve maintainability and locality of logic in the primary execution paths.
- Reduce ad-hoc env access; prefer
src/config/env.rshelpers. - Clarify control-flow lowering responsibilities in LLVM codegen.
High‑Value Candidates
-
Runner CLI directives
- Extract header‐comment directives scanning from
runner/mod.rs→runner/cli_directives.rs(done). - Next: Move using/alias/env merge traces behind a
runner::tracehelper to keepmod.rsslim.
- Extract header‐comment directives scanning from
-
LLVM codegen structure
- Introduce
instructions/terminators.rs(return/jump/branch emit glue) andinstructions/select.rs(cond/short‑circuit pre‑normalize). Initially re‑export fromflow.rs; later migrate implementations. - Keep
function.rsfocused on BB visitation + delegations (no heavy logic inline).
- Introduce
-
VM dispatch integration
- Gradually route the big
matchin VM throughbackend/dispatch.rs(already scaffolded). Start with side‑effect‑free ops (Const/Compare/TypeOp) to de‑risk. - Add opt‑in flag
NYASH_VM_USE_DISPATCH=1to gate behavior during the transition.
- Gradually route the big
-
Env access centralization
- Replace scattered
std::env::var("NYASH_*")withconfig::envgetters in hot paths (VM tracing, GC barriers, resolver toggles). - Add tiny wrappers where a tri‑state is needed (off/soft/on).
- Replace scattered
-
MIR builder granularity (non‑breaking)
- Extract loop helpers:
mir/builder/loops.rs(headers/exits/latch snapshot utilities). - Extract phi helpers:
mir/builder/phi.rs(if‑else merge, header normalize for latch).
- Extract loop helpers:
Low‑Risk Cleanups
- Tools scripts: dedupe
tools/*smoke*.shintotools/smokes/with common helpers (env, timeout, exit filtering). - Tests naming: prefer
*_test.rsandapps/tests/*.nyashconsistency for smokes. - Logging: add
NYASH_CLI_VERBOSEguards consistently; providerunner::trace!(...)macro for concise on/off.
Suggested Sequencing
- Runner small extractions (directives/trace). Validate with existing smokes.
- LLVM
terminators.rs/select.rsscaffolding + staged migration; zero behavior change initially. - VM dispatch gating: land flag and migrate 3–5 simple opcodes; parity by unit tests.
- MIR builder helpers: extract without API changes; run PyVM/LLVM curated smokes.
Notes
- Keep JIT/Cranelift untouched in this phase to avoid drift from the mainline policy.
- Prefer file‑level docs on new modules to guide incremental migration.