[GHC] #10744: Allow oneShot to work with unboxed types
GHC
ghc-devs at haskell.org
Fri Aug 7 08:08:53 UTC 2015
#10744: Allow oneShot to work with unboxed types
-------------------------------------+-------------------------------------
Reporter: akio | Owner:
Type: feature request | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 7.10.2
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Revisions:
-------------------------------------+-------------------------------------
Comment (by simonpj):
I think it'd be fine to allow `oneShot` to accept unboxed types; just a
matter of using `openAlphaTyVar` etc in `MkId.oneShot`. Give it a try and
submit a patch.
Moreover, the worst that can happen if you mis-use it, by applying it to a
function that is called many times, is that computation may be repeated.
For example
{{{
f xs y = let x = expensive_fn y
in map (oneShot (\v. x+v)) xs
}}}
The `oneShot` claims (falsely unless `xs` has length at most one) that
`(\v. x+v)` is called at most once. So GHC will move the call to
`expensive_fn` inside the lambda thus:
{{{
f xs y = map (oneShot (\v. expensive_fn y + v)) xs
}}}
That will work just fine, but it'll call `expensive_fn` once per element
of `xs`.
So, no seg-faults at least!
It would be good if someone felt like extending the Haddock comments for
`GHC.Magic.oneShot` to explain this.
Thanks
Simon
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10744#comment:8>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list