[GHC] #9291: Don't reconstruct sum types if the type subtly changes
GHC
ghc-devs at haskell.org
Tue Dec 6 16:24:48 UTC 2016
#9291: Don't reconstruct sum types if the type subtly changes
-------------------------------------+-------------------------------------
Reporter: schyler | Owner:
Type: feature request | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 7.8.2
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
Type of failure: Runtime | Unknown/Multiple
performance bug | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by rwbarton):
Replying to [comment:36 nomeata]:
> > Is this related with typed-ness of the IR?
>
> Yes! The type system of Core ensures that we cannot get the ST stuff
wrong (to some extent. It still requires us to also not inline `runRW#`,
for example).
Is this really true? Say I write
{{{#!hs
f :: Bool -> IORef Int -> IO ()
f b v = v `seq` when b (writeIORef v 3)
}}}
GHC produces
{{{
f1 =
\ b_auQ v_auR eta_B1 ->
case v_auR `cast` ... of _ { STRef ipv_sPi ->
case b_auQ of _ {
False -> (# eta_B1, () #);
True ->
case writeMutVar# ipv_sPi f2 eta_B1 of s2#_aQd { __DEFAULT ->
(# s2#_aQd, () #)
}
}
}
}}}
What stops me from rewriting this via case-of-case to the inequivalent
{{{
f1 =
\ b_auQ v_auR eta_B1 ->
case v_auR `cast` ... of _ { STRef ipv_sPi ->
case writeMutVar# ipv_sPi f2 eta_B1 of s2#_aQd { __DEFAULT ->
case b_auQ of _ {
False -> (# eta_B1, () #); -- Haha, don't actually use s2#_aQd
here.
True -> (# s2#_aQd, () #)
}
}
}
}}}
I think it is just the flag `has_side_effects = True` on `writeMutVar#`,
and doesn't have to do with types.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9291#comment:37>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list