
#5916: runST isn't free -------------------------------------+------------------------------------ Reporter: tibbe | Owner: Type: bug | Status: new Priority: normal | Milestone: 7.6.2 Component: Compiler | Version: 7.4.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by nomeata): Just noting down some idée fixe: The reason we are not inlining `runSTRep` is that we don’t want to expressions using the `realWorld#` token to become shared, right? How about `runSTRep` gets a special inlining that mentions all free variables of its argument, using a special token of type `stWorld# :: a -> RealWorld#`. So `runSTRep (f x (z x))` would get unfolded to {{{ case f x (z x) (stWorld# (f,x,z)) of (# _, r #) -> r }}} The variables mentioned in `stWorld’s` argument prevent this from being floated out, and I believe it ouldn’t that solve tibbe’s problem, right? It might also enable more CPR-related optimizations. When generating `STG`, the argument of `stWorld#` would of course be ignored. (In fact, it seems it would be correct ot have `runSTRep e = case e (stWorld# e) of (# _, #r) -> r`, which could be formulated as a plain `RULE`, but that would blow up the core expressions during compilation too much, I’d expect.) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/5916#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler