Skip to content

feat(Reporter): add discontinue_with_fatal - #201

Merged
favonia merged 7 commits into
RedPRL:mainfrom
mikeshulman:discontinue
Oct 19, 2026
Merged

favonia merged 7 commits into
RedPRL:mainfrom
mikeshulman:discontinue

Conversation

@mikeshulman

Copy link
Copy Markdown
Collaborator

Asai fatal errors are represented internally as exceptions, but the wrapper exception Fatal is not exposed outside Asai. This works fine as long as the only things you want to do with a fatal exception are raise it (with fatal) or catch it (with run and try_with), but in the presence of effects there is something else we can do with an exception: we can discontinue a continuation. This PR adds a discontinue_fatal function that creates a diagnostic wrapped in an exception just like fatal, but then passes it to discontinue rather than raise. (I admit discontinue_fatal isn't the snappiest name, but I couldn't think of a better one.)

@favonia

favonia commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

@mikeshulman Thanks! Good catch. The only other name that comes to mind is discontinue without the _fatal suffix. I feel Reporter.discontinue might be clear enough with the module name.

Comment thread src/Reporter_sigs.ml Resolved
Comment thread src/Structured_reporter_sigs.ml Resolved
Comment thread src/Reporter_sigs.ml Resolved
Comment thread src/Reporter_sigs.ml Resolved
Comment thread src/Structured_reporter_sigs.ml Resolved
mikeshulman and others added 5 commits October 14, 2026 22:38
Co-authored-by: favonia <favonia@gmail.com>
Co-authored-by: favonia <favonia@gmail.com>
Co-authored-by: favonia <favonia@gmail.com>
Co-authored-by: favonia <favonia@gmail.com>
Co-authored-by: favonia <favonia@gmail.com>
@mikeshulman

Copy link
Copy Markdown
Collaborator Author

I did think of that, but decided against it. I agree that Reporter.discontinue would be fine. The problem is that I, at least, usually open Reporter so that I can just write fatal and emit. And then if I've also done open Effect.Deep, a bare discontinue would be ambiguous, its meaning depending on the order of opens. Also, fatal and emit have different names than raise and perform, so it seems consistent for Reporter to have a different name for its version of discontinue.

@mikeshulman

Copy link
Copy Markdown
Collaborator Author

But of course the final decision is yours!

@favonia

favonia commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

@mikeshulman I've also been considering discontinue_with_fatal{,f,_diagnostic}, but that might be a mouthful. What do you think? I'm leaning towards merging this as is.

@mikeshulman

Copy link
Copy Markdown
Collaborator Author

I think that would be okay too. The extra 5 characters aren't terrible, and it might be clearer. I could go either way.

Another option, of course, would be to actually expose the exception and effect names, so the user could just call Effect.Deep.discontinue directly. Now that OCaml has sensible syntax for effect handlers, I'm not sure that so much is gained by forcing the user to call Reporter.try_with instead of using OCaml's built-in try.

@mikeshulman

Copy link
Copy Markdown
Collaborator Author

Another point for exposing exceptions is that (at least, according to both Gemini and Claude, and their explanation makes sense to me) effect handlers are substantially slower than exception handlers. So if a user only wants to catch fatal errors and not emit-diagnostics, having to use Reporter.try_with which always installs an effect handler is an unnecessary performance hit. Of course Asai could also expose a variant of try_with that doesn't take an ~emit argument and only catches Fatal.

@mikeshulman

Copy link
Copy Markdown
Collaborator Author

Or rewrite try_with so that if emit is not explicitly given. it skips installing an effect handler, rather than handling and immediately re-raising Emit effects.

@favonia

favonia commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

@mikeshulman I will use discontinue_with_fatal{,f,_diagnostic} then. Let me update the PR...

@favonia favonia changed the title feat(Reporter): add discontinue_fatal feat(Reporter): add discontinue_with_fatal Oct 18, 2026
@favonia
favonia merged commit 5db65b3 into RedPRL:main Oct 19, 2026
1 check passed
@mikeshulman
mikeshulman deleted the discontinue branch October 19, 2026 00:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants