#13807: GHC 8.2 nondeterministic with foreign imports -------------------------------------+------------------------------------- Reporter: niteria | Owner: (none) Type: bug | Status: new Priority: high | Milestone: Component: Compiler | Version: 8.2.1-rc2 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- See the attached Repro.hs. Reproduction steps: {{{ $ rm Repro.{o,hi}; ghc -O -dunique-increment=-1 Repro.hs; md5sum Repro.hi; rm Repro.{o,hi}; ghc -O -dunique-increment=1 Repro.hs; md5sum Repro.hi; [1 of 1] Compiling Repro ( Repro.hs, Repro.o ) 97f005e3959b657bfac761aa3e8a9447 Repro.hi [1 of 1] Compiling Repro ( Repro.hs, Repro.o ) 691f891fb404eb874e8bedd7bda1c8b7 Repro.hi }}} The crucial difference comes from: {{{ 08fffd1551f79b5aca3cafdceaf865b9 mkStringWriter1 :: Int -> State# RealWorld -> (# State# RealWorld, Ptr Int #) {- Arity: 2, HasNoCafRefs, Strictness: <L,U><S,U>, Unfolding: InlineRule (2, True, False) (\ (ds :: Int) (s :: State# RealWorld) -> case makeStablePtr# @ Int ds s of ds1 { (#,#) ipv ipv1 -> case {__pkg_ccall Int# -> StablePtr# Int -> Addr# -> Addr# -> State# RealWorld -> (# State# RealWorld, Addr# #)} 1# ipv1 __label "Repro_d105" (function) mkStringWriter2 ipv of wild { (#,#) ds2 ds3 -> (# ds2, Ptr @ Int ds3 #) } }) -} }}} vs {{{ a766a748e60cec63a74534e03db3bf30 mkStringWriter1 :: Int -> State# RealWorld -> (# State# RealWorld, Ptr Int #) {- Arity: 2, HasNoCafRefs, Strictness: <L,U><S,U>, Unfolding: InlineRule (2, True, False) (\ (ds :: Int) (s :: State# RealWorld) -> case makeStablePtr# @ Int ds s of ds1 { (#,#) ipv ipv1 -> case {__pkg_ccall Int# -> StablePtr# Int -> Addr# -> Addr# -> State# RealWorld -> (# State# RealWorld, Addr# #)} 1# ipv1 __label "Repro_d5k1wlNFGaX" (function) mkStringWriter2 ipv of wild { (#,#) ds2 ds3 -> (# ds2, Ptr @ Int ds3 #) } }) -} }}} Notice that the labels are different. This doesn't reproduce under GHC 8.0.2, but that may be only because that version doesn't optimize it this way. This is what GHC 8.0.2 produces: {{{ ccf55489bd76322a9404b365b7be7628 mkStringWriter :: Int -> IO (Ptr Int) {- Arity: 2, HasNoCafRefs, Strictness: <L,U><S,U>, Inline: [NEVER] -} }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13807> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler