Files
hakorune/docs/papers/result_mode_exceptions.md

1.2 KiB
Raw Blame History

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/cleanup 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) { … } [cleanup { … }] 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.
  • Cleanup: 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 + cleanup; ensure merges are stable.

Reproduce

  • bash tools/test/smoke/bridge/try_result_mode.sh