Files
hakorune/docs/development/refactoring/candidates_phase15.md
nyash-codex 51ff558904 feat(phase32): L-2.1 Stage-1 UsingResolver JoinIR integration + cleanup
Phase 32 L-2.1 complete implementation:

1. Stage-1 UsingResolver main line JoinIR connection
   - CFG-based LoopForm construction for resolve_for_source/5
   - LoopToJoinLowerer integration with handwritten fallback
   - JSON snapshot tests 6/6 PASS

2. JoinIR/VM Bridge improvements
   - Simplified join_ir_vm_bridge.rs dispatch logic
   - Enhanced json.rs serialization
   - PHI core boxes cleanup (local_scope_inspector, loop_exit_liveness, loop_var_classifier)

3. Stage-1 CLI enhancements
   - Extended args.rs, groups.rs, mod.rs for new options
   - Improved stage1_bridge module (args, env, mod)
   - Updated stage1_cli.hako

4. MIR builder cleanup
   - Simplified if_form.rs control flow
   - Removed dead code from loop_builder.rs
   - Enhanced phi_merge.rs

5. Runner module updates
   - json_v0_bridge/lowering.rs improvements
   - dispatch.rs, selfhost.rs, modes/vm.rs cleanup

6. Documentation updates
   - CURRENT_TASK.md, AGENTS.md
   - Various docs/ updates

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-26 10:17:37 +09:00

45 lines
2.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 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.rs` helpers.
- Clarify control-flow lowering responsibilities in LLVM codegen.
HighValue Candidates
- Runner CLI directives
- Extract headercomment directives scanning from `runner/mod.rs``runner/cli_directives.rs` (done).
- Next: Move using/alias/env merge traces behind a `runner::trace` helper to keep `mod.rs` slim.
- LLVM codegen structure
- Introduce `instructions/terminators.rs` (return/jump/branch emit glue) and `instructions/select.rs` (cond/shortcircuit prenormalize). Initially reexport from `flow.rs`; later migrate implementations.
- Keep `function.rs` focused on BB visitation + delegations (no heavy logic inline).
- VM dispatch integration
- Gradually route the big `match` in VM through `backend/dispatch.rs` (already scaffolded). Start with sideeffectfree ops (Const/Compare/TypeOp) to derisk.
- (撤去済み) `NYASH_VM_USE_DISPATCH=1` でのディスパッチ経路スイッチ案は廃止。
- Env access centralization
- Replace scattered `std::env::var("NYASH_*")` with `config::env` getters in hot paths (VM tracing, GC barriers, resolver toggles).
- Add tiny wrappers where a tristate is needed (off/soft/on).
- MIR builder granularity (nonbreaking)
- Extract loop helpers: `mir/builder/loops.rs` (headers/exits/latch snapshot utilities).
- Extract phi helpers: `mir/builder/phi.rs` (ifelse merge, header normalize for latch).
LowRisk Cleanups
- Tools scripts: dedupe `tools/*smoke*.sh` into `tools/smokes/` with common helpers (env, timeout, exit filtering).
- Tests naming: prefer `*_test.rs` and `apps/tests/*.hako` consistency for smokes.
- Logging: add `NYASH_CLI_VERBOSE` guards consistently; provide `runner::trace!(...)` macro for concise on/off.
Suggested Sequencing
1) Runner small extractions (directives/trace). Validate with existing smokes.
2) LLVM `terminators.rs`/`select.rs` scaffolding + staged migration; zero behavior change initially.
3) VM dispatch gating: land flag and migrate 35 simple opcodes; parity by unit tests.
4) 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 filelevel docs on new modules to guide incremental migration.