[GHC] #11035: Add implicit call-stacks to partial functions in base
GHC
ghc-devs at haskell.org
Thu Oct 29 17:55:53 UTC 2015
#11035: Add implicit call-stacks to partial functions in base
-------------------------------------+-------------------------------------
Reporter: gridaphobe | 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 Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by gridaphobe):
Regarding problem (1): I get the feeling this will require code
duplication at the source level, which would be a Bad Thing.
We can't just write
{{{#!haskell
foldr1 :: (?callStack :: CallStack) => ...
foldr1 = faster_foldr1
faster_foldr1 :: ...
faster_foldr1 f [] = error
faster_foldr1 f (x:xs) = foldr f xs
}}}
because the call to `error` in `faster_foldr1` won't see a given
CallStack, and the chain will be broken there. Instead we'd have to write
{{{#!haskell
foldr1 :: (?callStack :: CallStack) => ...
foldr1 f [] = error
foldr1 f (x:xs) = foldr f x xs
faster_foldr1 :: ...
faster_foldr1 f [] = error
faster_foldr1 f (x:xs) = foldr f xs
}}}
It may be the case that most partial functions in base are either simple
themselves (like `head`) or have simple definitions in terms of a total
function (like `foldr`). So maybe the duplication wouldn't be ''that''
bad, but I'm still pretty wary of this route...
A more heavyweight solution could be to have GHC generate a callstack-free
version of each function that takes a CallStack, along with a RULE like
you described. Then the source-level duplication is gone, but the
desugarer or simplifier becomes more complex.
In either scenario we end up exporting multiple versions of the "same"
function, which will bloat library sizes. But maybe that's not so bad, the
binaries shouldn't be affected.
(I kinda like the `PartialFunction` constraint too, it's cute.)
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11035#comment:2>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list