-
Notifications
You must be signed in to change notification settings - Fork 274
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow Exception
ability to be used by main functions
#2029
Conversation
@dolio Not urgent. |
I think what's happening with the error message you get is that it's looking up the dynamically scoped I think it should be possible to instead populate it with something that just throws an appropriate runtime exception that is caught with the other exceptions. If you use a different exception type than the one used for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tested this locally and ran some terms with the type '{IO, Exception}()
and had them succeed without needing to call an Exception handler at the top level!
When raising an exception I do see the resolve
statement as the error, but it sounds like Dan is on it!
Next step on this @dolio - could you install a top-level handler for the Something else I want to figure out is catching exceptions in pure code, and I wonder if they're related. Like what if -- a new builtin function which is just a cast
builtin Exception.unsafeRun : '{g,Exception} a -> {g} a
bug : a -> x
bug a = Exception.unsafeRun '(raise (Failure (typeLink Bug) "a bug" (Any a)))
todo : a -> x
todo a = Exception.unsafeRun '(raise (Failure (typeLink Todo) "a todo" (Any a))) |
I'm not clear what direction these are for. If "catch exceptions in pure code" means that If "catch exceptions in pure code" means that there needs to be a way to catch (catch exceptions) in pure code vs. catch (exceptions in pure code). :) |
I think we should go in the opposite direction: if UCM knows that your main function transitively depends on |
Hmm can you explain? Are you saying you shouldn't be able to run programs unless you can (statically) determine they don't call |
I was saying you shouldn't be able to run programs with the |
But in the spirit of keeping the ticket minimal, let's just keep it to being able to run a program with unhandled |
Yeah, agree, let's just keep this to installing a top-level Unison I think this is lower priority than fixing up the new inference algorithm issues recently reported. |
- Might be more complicated than necessary right now, but it's more like a genuine handler than just calling a primop throw. - Probably could use a better error message, but I'm not sure how to display `Failure` in a desirable way.
- The 'pure' case was implemented incorrectly - Also fixed the implementation of putBytes, it was giving back a 'unit' value that was actually a handle.
@dolio sweet! Can you merge trunk into this branch and fixup conflicts? |
Yeah. Do you have some idea about the error message? Right now it's just printing out the |
@dolio yeah, I'd reword a bit just to use full sentences. The program halted with an unhandled exception: And then I'd pass a suffixed pretty-print environment to the runtime so it uses shorter names. I think you can make this change in
I think change to
|
Hopefully this merge works. I was getting local warnings about |
@dolio if you do a |
Nah, I'm using cabal, so it doesn't seem likely to be that. Maybe it also wasn't rebuilding the relevant file. Is that pragma actually new? I didn't think it was. |
Maybe cabal's compilation cache has the same bug? :) The pragma was newly added to ABT.hs in trunk kinda recently yeah. |
Prior to this PR, the main type has to be
'{IO} ()
, now it can be'{IO,Exception} ()
, allowing unhandled exceptions to bubble to top level. If they make it there they should just act similar to as if you calledbug
on the failure.io.test
command gets a similar upgrade.See this transcript
Suggested by @rlmark and @stew.
Implementation notes
Right now, the implementation literally just allowing the exceptions to bubble up to the top of the runtime. This used to give a nice uncaught request message similar to if you called
bug
, but in the current runtime it yields:Which is no good. We could either fix the runtime to generate a nice message in the case of uncaught requests, or wrap all calls to
run
in something like this:The thing is that I'd like to customize the message a bit, rather than just getting the default
bug
message. So I guess I'd lean toward fixing up the runtime if that's easily doable. @dolio WDYT?Testing
I added a transcript to exercise this (and it currently succeeds with that poor error message). I think that should be sufficient testing once the error message gets sorted out.