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

rts_getThreadId: fix return type on newer GHCs #263

Conversation

amesgen
Copy link
Contributor

@amesgen amesgen commented Jan 4, 2023

Found via the GHC WASM backend: https://gitlab.haskell.org/ghc/ghc/-/issues/22617#note_470653

Also see https://hackage-search.serokell.io/?q=rts_getThreadId for other packages doing the same thing.

@@ -763,7 +769,15 @@ hashThreadId (ThreadId t) = hash (fromIntegral (getThreadId t) :: Int)

-- this cannot be capi, as GHC panics.
foreign import ccall unsafe "rts_getThreadId" getThreadId
Copy link
Contributor

@phadej phadej Jan 4, 2023

Choose a reason for hiding this comment

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

is rts_getThreadId exported from some header? Could you change that to ccall to capi (with CApiFFI).

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, crap. It cannot be capi as GHC panics, but does even GHC-9.4 panic still? It does :( https://gitlab.haskell.org/ghc/ghc/-/issues/22705

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I change it to capi, I get

ghc: panic! (the 'impossible' happened)
  (GHC version 9.2.4:
	toCType
  ThreadId#
  Call stack:
      CallStack (from HasCallStack):
        callStackDoc, called at compiler/GHC/Utils/Panic.hs:181:37 in ghc:GHC.Utils.Panic
        pprPanic, called at compiler/GHC/HsToCore/Foreign/Decl.hs:763:17 in ghc:GHC.HsToCore.Foreign.Decl

which seems to be consistent with the comment

-- this cannot be capi, as GHC panics.

you added in #213.

@phadej phadej merged commit ee10c3d into haskell-unordered-containers:master Jan 4, 2023
@amesgen amesgen deleted the fix-rts_getThreadId-return-type branch January 4, 2023 17:11
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this pull request Jan 25, 2023
Version 1.4.2.0
* Fix the foreign signature of getThreadId
  haskell-unordered-containers/hashable#263
* Drop support for GHCs prior GHC-8.2 The recent unordered-containers
  releases support only GHC-8.2+
* Add instance for OsString, PosixString, WindowsString from
  filepath-1.4.100.1
* Add Hashable ByteArray instance using data-array-byte compat package
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