Visitar URL original
rts_getThreadId: fix return type on newer GHCs by amesgen · Pull Request #263 · haskell-unordered-containers/hashable · GitHub
Skip to content
Merged
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
14 changes: 14 additions & 0 deletions src/Data/Hashable/Class.hs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,13 @@ import Data.Typeable.Internal (Typeable, TypeRep (..))
import GHC.Fingerprint.Type(Fingerprint(..))
#endif

#if __GLASGOW_HASKELL__ >= 904
import Foreign.C.Types (CULLong(..))
#elif __GLASGOW_HASKELL__ >= 900
import Foreign.C.Types (CLong(..))
#else
import Foreign.C.Types (CInt(..))
#endif

#if !(MIN_VERSION_base(4,8,0))
import Data.Word (Word)
Expand Down Expand Up @@ -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

@phadej phadej Jan 4, 2023 •

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
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.

#if __GLASGOW_HASKELL__ >= 904
-- https://gitlab.haskell.org/ghc/ghc/-/merge_requests/6163
:: ThreadId# -> CULLong
#elif __GLASGOW_HASKELL__ >= 900
-- https://gitlab.haskell.org/ghc/ghc/-/merge_requests/1254
:: ThreadId# -> CLong
#else
:: ThreadId# -> CInt
#endif

instance Hashable ThreadId where
hash = hashThreadId
Expand Down