Skip to content
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

Exceptions 0.10.0 #61

Merged
merged 3 commits into from
May 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions hint.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ test-suite unit-tests
directory,
filepath,
extensible-exceptions,
exceptions == 0.8.*
exceptions >= 0.10.0

if !os(windows) {
build-depends: unix >= 2.2.0.0
Expand All @@ -56,7 +56,7 @@ library
ghc-boot,
mtl,
filepath,
exceptions == 0.8.*,
exceptions == 0.10.*,
random,
directory

Expand Down
15 changes: 14 additions & 1 deletion src/Control/Monad/Ghc.hs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,20 @@ instance (MonadIO m, MonadMask m) => MonadMask (GhcT m) where
wrap g = GhcT $ GHC.GhcT $ \s -> MTLAdapter (g s)
unwrap m = unMTLA . GHC.unGhcT (unGhcT m)

uninterruptibleMask = mask
uninterruptibleMask f = wrap $ \s ->
uninterruptibleMask $ \io_restore ->
unwrap (f $ \m -> (wrap $ \s' -> io_restore (unwrap m s'))) s
where
wrap g = GhcT $ GHC.GhcT $ \s -> MTLAdapter (g s)
unwrap m = unMTLA . GHC.unGhcT (unGhcT m)
Copy link
Contributor Author

@gelisam gelisam May 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also took the opportunity to fix the implementation of uninterruptibleMask. It was previously defined as uninterruptibleMask = mask, so calling uninterruptibleMask body was misleadingly running body in interruptible mode, not in uninterruptible mode. The difference is that some calls, like threadDelay, are intentionally marked as being interruptible even when running inside mask. As a result,

> timeout 1000000 $ mask_ $ threadDelay 3000000

terminates after 1 second because the timeout successfully interrupts the threadDelay after 1 second, while

> timeout 1000000 $ uninterruptibleMask_ $ threadDelay 3000000

terminates after 3 seconds, because the timeout has to wait until the uninterruptibleMask computation terminates before aborting the computation.

Without this fix,

> timeout 1000000 $ runGhcT ... $ mask_ $ lift $ threadDelay 3000000

and

> timeout 1000000 $ runGhcT ... $ uninterruptibleMask_ $ lift $ threadDelay 3000000

both terminate after 1 second, whereas with this fix, the second terminates after 3 seconds, as desired.


generalBracket acquire release body
= wrap $ \s -> generalBracket (unwrap acquire s)
(\a exitCase -> unwrap (release a exitCase) s)
(\a -> unwrap (body a) s)
where
wrap g = GhcT $ GHC.GhcT $ \s -> MTLAdapter (g s)
unwrap m = unMTLA . GHC.unGhcT (unGhcT m)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the main fix: exceptions-0.9 introduced a new method named generalBracket, whose type I fixed in exceptions-0.10, so in order to upgrade from exceptions-0.8 to exceptions-0.10, we have to implement this method. If we wanted, we could add an #ifdef around this method definition in order to support both.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about depending on exceptions >= 0.8.0?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean >= 0.10.0, or did you change your mind and now want an #ifdef in order to support both 0.8 and 0.10?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I indeed meant >= 0.10.0 - thanks for spotting that. I would not bother supporting 0.8 and earlier, especially given how it's a v0, and how we're likely one of the last libraries to add support for the new exceptions versions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed, merging


instance (MonadIO m, MonadCatch m, MonadMask m) => GHC.ExceptionMonad (GhcT m) where
gcatch = catch
Expand Down