[GHC] #855: Improvements to SpecConstr
GHC
ghc-devs at haskell.org
Mon Feb 26 09:06:04 UTC 2018
#855: Improvements to SpecConstr
-------------------------------------+-------------------------------------
Reporter: simonpj | Owner: (none)
Type: task | Status: new
Priority: normal | Milestone: ⊥
Component: Compiler | Version: 6.4.2
Resolution: | Keywords: SpecConstr
Operating System: Unknown/Multiple | Architecture:
Type of failure: Runtime | Unknown/Multiple
performance bug | Test Case: N/A
Blocked By: | Blocking: 915
Related Tickets: | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by simonpj):
Another way of thinking about: thing in terms of defunctionalisation.
Consider this higher order function
{{{
let f :: (Int -> Bool) -> Int -> Char
f g x = ....(g e)...
in
...(f (\x.y+x)).... (f (\v.v*p*q))....(f h)...
}}}
Now defunctionalise by making a version of `f` that takes
a data structure as its argument:
{{{
data G_Fun = G1 Int -- \x.y+x
| G2 Int Int -- \v.v*p*q
| G3 (Int->Int) -- Escape hatch
applyG :: G_Fun -> Int -> Bool
applyG (G1 x) = \x.y+x
applyG (G2 p q) = \v.v*p*q in ...(g e)...
applyG (G3 g) = g
let f' :: G_Fun -> Int -> Char
f' ga x = ...(applyG ga e)...
in
...(f' (G1 x))...(f' (G2 p q))...(f' (G3 h))
}}}
(I guess you could do this via a w/w kind of transformation, but for
now it's purely hypothetical.)
Now we are back in the land of data-constructors, where `SpecConstr`
thrives.
Suppose the call is actually
{{{
...(f' (G1 (Yield e1 e2 e3)))...
}}}
Should we specialise on `(G1 x)` or on the deeper pattern `(G1 (Yield a b
c))`?
It depends how much `f'` scrutinises its argument. And you can see that
from
what `applyG` does.
I think you could follow all this reasoning without ''actually'' createing
`G_Fun` etc.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/855#comment:15>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list