Opened 6 years ago

Closed 6 years ago

#5540 closed bug (fixed)

Non-deterministic pure code in Data.Typeable

Reported by: guest Owned by:
Priority: normal Milestone:
Component: libraries/base Version: 7.0.3
Keywords: Cc: jmg@…
Operating System: MacOS X Architecture: x86_64 (amd64)
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


Comparing the result of 'typeOf ()' performed in different threads sometimes yields true and sometimes false. To reproduce compile the attached source file with

ghc-7.0.3 -threaded -rtsopts TypeRepEq.hs

And execute it in a shell loop. Looping the inside the Haskell program will usually not show the bug.

while true ; do ./TypeReqEq +RTS -N ; done

Every program run will print either "Ok" or "typeOf () /= typeOf ()". The latter would indicate the bug.

The issue has been discussed on the glasgow-haskell-users mailing list in this thread:

Different people said that they can reproduce the bug on Mac OS X and Linux with different versions of GHC 6.12.x and 7.0.x. GHC 7.2 does not show the bug.

Attachments (1)

TypeRepEq.2.hs (483 bytes) - added by guest 6 years ago.

Download all attachments as: .zip

Change History (4)

Changed 6 years ago by guest

Attachment: TypeRepEq.2.hs added


comment:1 Changed 6 years ago by simonpj

Thank you for the detailed investigation. I have not followed all the details of this thread, but I think that it may (happily) represent a bug in generating TypeReps that is already fixed.

  • We used to have a global cache from which we generated unique Int keys corresponding to type constructors. The trouble with this was that (a) you weren’t guaranteed to get the same key in every run, and (b) the cache was not initially designed to be thread-safe, and I’m not sure that we’d closed all race conditions.
  • But NOW we generate a MD5 hash, or fingerprint, of the type. So there is no global cache, no race condition, and you should get the same behaviour ever time.

In short, can you try with 7.2?



comment:2 Changed 6 years ago by jmg

I had already tested with 7.2 and the bug did not show up. Nevertheless I started the discussion, because I wanted to make sure that it is not my fault, and because I needed a workaround. Now I have one. Thanks for the confirmation.

comment:3 Changed 6 years ago by simonmar

Resolution: fixed
Status: newclosed

Sorry about the bug. It is fixed in 7.2.1 and later, but we aren't planning to patch older releases. I wish we had noticed this bug earlier!

Note: See TracTickets for help on using tickets.