-
Notifications
You must be signed in to change notification settings - Fork 73
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
resourceToIO
doesn't protect against IO exceptions thrown by interpreters run after it
#268
Comments
This strikes me as the expected behavior --- it's the local/global semantics thing all over again, right? Resource will (/should?) only protect you against exceptions that are more local than it. |
Depends on your perspective. IMO, Anyway, even with the viewpoint that data HO m a where
HO :: m a -> HO m a
makeSem ''HO
runHO :: Sem (HO ': r) a -> Sem r a
runHO = interpretH $ \(HO m) -> runT m >>= raise . runHO
bad :: IO ()
bad =
runM
. traceToIO
. runHO
. resourceToIO
. failToEmbed @IO
$ do
bracket
(trace "alloc")
(\_ -> trace "dealloc")
(\_ -> hO $ trace "use" >> Fail.fail "bad") > bad
alloc
use
*** Exception: user error (bad) |
My feeling is that there are very few effects you'd ever want to eliminate after |
I suppose there's some argument in using it as part of an interpretation of some other effect. Which would indeed expect to not crash. I'm OK adding |
I'm exploring a rework on
Resource
's semantics, and I discovered this issue while working on it.For example:
It also doesn't protect from IO exceptions thrown via
embedFinal
(and thus it doesn't protect against the exceptions thaterrorToIOFinal
throws):Fixing these would require introducing a
Final IO
constraint towithLowerToIO
.This would let us do the following:
withLowerToIO
would be able to lift and applyControl.Exception.try
to the requests it gets. If it catches an exception, then it sends that back to the querying thread, which will then throw that exception within that thread. This way,bracket
s within the querying thread will be able to react to the exception.withWeavingToFinal
and interpret them in the forked thread, rather than shipping them off to the interpreter thread.1 is the big thing here; 2's just a bonus.
In my
Resource
rework,resourceToIO
would also benefit from having access toFinal IO
; I'll put up a draft of itsoonwithin a week.The downside is adding
Final IO
as a constraint towithLowerToIO
(we may want to keep theEmbed
constraint so thatrunViaForklift
may intercept it.)The text was updated successfully, but these errors were encountered: