Files
hakorune/docs/private/papers/paper-o-result-mode-exceptions.md

29 lines
1.2 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.

# Structured Exceptions via ResultMode (Draft)
Problem
- Language exceptions are hard to implement portably (unwinding, landing pads) and complicate SSA/CFG.
Contribution (Nyash)
- Express try/catch/finally with Resultmode lowering (no MIR Throw/Catch): structured blocks and jumps.
- Threadlocal ThrowCtx to aggregate nested `throw` to a single catch.
- PHIOff: merge variables via edgecopy; harness synthesizes PHIs.
- BlockPostfix Catch syntax: `{ body } catch (e) { … } [finally { … }]` with singlecatch policy.
Method
- Parser (gated): accept try/throw + postfix catch, normalize to `ASTNode::TryCatch`.
- Bridge: set ThrowCtx on try entry; route `throw` to catch BB; bind catch param via incoming.
- Finally: always runs; merge at exit with PHIoff rules.
Code References
- Parser: `src/parser/statements.rs`
- Bridge lowering: `src/runner/json_v0_bridge/lowering/{try_catch.rs, throw_ctx.rs}`
- Smokes: `tools/test/smoke/bridge/try_result_mode.sh`
Evaluation Plan
- Semantic parity: PyVM vs. harness binaries on representative cases.
- Controlflow complexity: nested if/loop + finally; ensure merges are stable.
Reproduce
- `bash tools/test/smoke/bridge/try_result_mode.sh`