feat: !! panic-unwrap operator#272
Merged
Merged
Conversation
Higher priority than single-char Bang so logos picks the longer match when scanning `func!! args`.
Symmetric with `!` over Result and Optional, but on Err / nil aborts
with a diagnostic + exit 1 instead of propagating via the enclosing
function's return type. Removes the viral R/O constraint for one-shot
scripts: `rdl!! path` from `main>t` now works without the `>R t t` +
`~v` wrapping ceremony.
- ast: replace `unwrap: bool` on Expr::Call with `UnwrapMode { None,
Propagate, Panic }`. Single enum field makes the two modes mutually
exclusive at the type level.
- parser: probe `!!` at every postfix-Bang site, emit Panic mode.
- verify: Panic mode accepts callee returning R or O, skips the
enclosing-return-type check that `!` requires.
- interpreter (tree): new Panic arm returns RuntimeError directly
without propagate_value, ILO-R026 with the inner Err / nil context.
- vm: new OP_PANIC_UNWRAP opcode that routes through
jit_set_runtime_error so the existing JIT_RUNTIME_ERROR channel
surfaces it identically across VM and Cranelift.
- cranelift: new jit_panic_unwrap helper mirroring the VM opcode.
- codegen/fmt: emit `!!` for Panic mode.
- codegen/python: emit a `_ilo_panic_unwrap` raise helper.
- diagnostic: register ILO-R026 with examples.
New Panic-Unwrap section explaining semantics, examples for `main>t`, `main>n` contexts, and the rule difference from `!` (no enclosing-return-type constraint). Updates the auto-unwrap rules to note both `R` and `O` callees are accepted. ai.txt picks up the same operator entry and updated rules in token-dense form.
regression_bangbang.rs exercises tree / VM / Cranelift on the success path, Err / nil abort paths, callee returning R, callee returning O, no-enclosing-return-constraint case, and composition with `!`. Also covers verifier rejection when the callee return type cannot fail. examples/bangbang-panic-unwrap.ilo gives agents an in-context demo of the now-correct behaviour and is exercised by tests/examples_engines.rs across every engine.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
!!as a sibling to!: same auto-unwrap shape overRandO, but on^e/ nil it aborts with a runtime diagnostic and exit 1 instead of propagating via the enclosing function's return type. This removes the viral R/O constraint for one-shot scripts and personas:The token-cost win is real: a persona that just wants to read a file and bail on error no longer has to wrap
mainin>R t tand emit~v, then deal with a propagated Err the runner has nowhere sensible to send.Repro before / after
Before, this required a Result-typed
mainand explicit unwrapping:After:
What's in the diff (per commit)
!!panic-unwrap operator across all engines —UnwrapMode { None, Propagate, Panic }replacesunwrap: boolonExpr::Call. Parser probes!!at every postfix-Bang site. Verifier accepts the same R/O callee shape as!but skips the enclosing-return-type check. Tree, VM (OP_PANIC_UNWRAP), and Cranelift (jit_panic_unwrap) all route through the existingJIT_RUNTIME_ERRORchannel for identical surfacing. fmt emits!!; python emits a_ilo_panic_unwrapraise helper. New diagnosticILO-R026.tests/regression_bangbang.rscovers success path, abort paths, R and O callees, no-enclosing-return-constraint, composition with!, and verifier rejection of non-failing callees, across tree / VM / Cranelift.examples/bangbang-panic-unwrap.ilois picked up by the existing examples_engines harness.Test plan
cargo build --release --features craneliftcleancargo test --release --features cranelift— 4699 passed, 0 failedcargo fmt --checkcleancargo clippy --release --features cranelift --all-targets -- -D warningscleanregression_bangbang.rstests passexamples/bangbang-panic-unwrap.iloexercised byexamples_engines.rsacross every engineFollow-ups
None planned. Documents the design rationale for picking single-enum
UnwrapModeover paired booleans inline (type-system enforcement that the two modes are mutually exclusive).