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

Make tickets reliable #86

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

treeowl
Copy link

@treeowl treeowl commented Mar 3, 2023

  • All the unsafeCoerce tricks to try to block up inlining are quite unreliable, especially these days. We can get much more reliable results by making Ticket a datatype, and using lazy when peeking into it. Do that.

  • Remove the Eq Ticket instance. It was never sensible or lawful.

  • Add strictness annotations to suppress warnings.

  • Add a peekTicketA function to extract the value from a ticket in an Applicative context, so we can unbox the ticket even if the value within will be used lazily.

  • Make atomicModifyIORefCAS and atomicModifyIORefCAS_ strictness as consistent as possible in the fall-back case where we use atomicModifyIORef. As I wrote it, the code is only as strict as it should be for base >= 4.13 / GHC >= 8.8.1. The previous promise never to install a thunk in the IORef simply can't be kept in the fall-back case; adjust the documentation to match reality.

Fixes #5.
Fixes #69.

* All the `unsafeCoerce` tricks to try to block up inlining are quite
  unreliable, especially these days. We can get much more reliable
  results by making `Ticket` a datatype, and using `lazy` when peeking
  into it. Do that.

* Remove the `Eq Ticket` instance. It was never sensible or lawful.

* Add strictness annotations to suppress warnings.

* Add a `peekTicketA` function to extract the value from a ticket in
  an `Applicative` context, so we can unbox the ticket even if the
  value within will be used lazily.

* Make `atomicModifyIORefCAS` and `atomicModifyIORefCAS_` strictness
  as consistent as possible in the fall-back case where we use
  `atomicModifyIORef`. As I wrote it, the code is only as strict as
  it should be for `base >= 4.13` / `GHC >= 8.8.1`. The previous promise
  never to install a thunk in the `IORef` simply can't be kept in the
  fall-back case; adjust the documentation to match reality.

Fixes rrnewton#5.
Fixes rrnewton#69.
@treeowl treeowl force-pushed the reliable-tickets branch from 26e7e07 to e6f6ac4 Compare March 3, 2023 05:26
@treeowl
Copy link
Author

treeowl commented Mar 3, 2023

@jberryman Do you think you still have what you need to see if this happens to fix #77? That one looks pretty involved.

@jberryman
Copy link
Collaborator

jberryman commented Mar 13, 2023

hey thanks for working on this. it should be easy to delete some of the few other tests in this file to get something totally self-contained that just depends on atomic-primops, if you want to try it on your branch: https://github.com/jberryman/unagi-chan/blob/master/tests/Atomics.hs#L94

@mitchellwrosen
Copy link

Hi, friendly ping. This seems like an important PR with some critical bug fixes for some years-old tickets. Just curious, what's the status -- is this repo still maintained? (Would be great to throw up an "unmaintained" banner on Hackage if not!)

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.

CAS fails with newly created ticket PeekTicket needs to be INLINE and shouldn't be
3 participants