Parent: #469; related: #491, #466.
Implement the optimizer roadmap's explicit IR-verification requirement. Current Plan/ValueGraph already carries block arguments, edges, frame and edge recovery maps, active handler stacks, and exceptional targets. The existing graph compaction and selected-loop compaction phases need a common verifier before additional global optimization passes can rely on those contracts.
Scope:
- Verify block/instruction/value identity and bounded slices before dereferencing malformed metadata.
- Verify SSA definition order and CFG dominance, including exception edges, block arguments, entry seeds, and selected-loop entry/exit boundaries.
- Verify effect flags/order and pre-operation recovery states; unknown values are not pure, and a future effect result cannot appear in its own pre-effect map.
- Verify recovery value availability, edge arity, handler and exceptional-target shape, and preserve roots needed by maps.
- Run the verifier after existing graph phases in test builds; retain a callable verifier for deterministic mutation tests. Keep production validation/compilation costs unchanged until separately measured and accepted.
- Use iterative traversal and linear scratch storage; preserve allocation-failure cleanup and deterministic output.
Definition of done:
- Valid loops, diamonds, calls/coercions, catch/finally, and selected-loop plans pass verification.
- Corrupt ids/slices, non-dominating/forward values, missing effects/maps, inconsistent edge/handler state, and unsafe recovery values fail with stable verifier errors.
- Existing planning and loop-compaction test paths invoke verification; OOM sweeps leak nothing.
- Focused Debug, ReleaseSafe, unsuppressed TSan, broader native semantic/GC tests, and scoped before/after corpus comparisons pass.
This is a verifier prerequisite, not a claim that #469's optimization passes or performance acceptance are complete.