yav / haskell-lexer

A fully compliant Haskell 98 lexer.
MIT License
15 stars 7 forks source link

Non-deterministic behavior?! #3

Closed sol closed 7 years ago

sol commented 7 years ago

Steps to reproduce:

-- Test.hs
import Test.QuickCheck
import Language.Haskell.Lexer

lexer :: String -> [(Token, String)]
lexer = map (\(token, (_pos, s)) -> (token, s)) . lexerPass1

input :: String
input = show 23

prop :: Int -> Property
prop _ = lexer input === lexer input

main :: IO ()
main = quickCheckWith stdArgs { maxSuccess = 1000000 } prop
$ runhaskell Test.hs 
*** Failed! Falsifiable (after 105133 tests):                  
13
[(Open 1,""),(Conid,"23")] /= [(Open 1,""),(IntLit,"23")]
$ runhaskell --$ runhaskell --version
runghc 8.0.1

Note: This only happens when haskell-lexer is compiled (not interpreted).

sol commented 7 years ago

The scary thing is that I didn't see any uses of unsafePerformIO and friends. This seems to be pure Haskell code.

erikd commented 7 years ago

I'm pretty sure I've seen something like this, but I was never able to narrow it down to a nice small test case.

yav commented 7 years ago

Yes, I've also run into this, it is due to a bug in GHC's PIC generation (so it happens with GHCi and -dynamic). It should be fixed in GHC 8.0.2. Here is the relevant bug report:

https://ghc.haskell.org/trac/ghc/ticket/12433