RE: Proposal: Improved error message of "Error in array index"

On 08 November 2005 12:09, Rene de Visser wrote:
One idea that occurred to us recently is this: GHCi could provide a simplified version of the cost-centre-stack machinery *all the time*,
Simon
This still doesn't explain to me why
C:\Haskell\dev>main +RTS -xc
gave
main: Error in array index (This is with full profiling turned on)
This sort of stack is not going to help anyone.
Hmm yes, this is indeed rather unhelpful. I can explain why it happens, though. The compiler has lifted out the error case into a top-level binding: x = error "Error in array index" and the profiling system takes the view that any costs involved in evaluating a CAF to head normal form should not be attributed to any particular call site in particular, because the call site that gets to evaluate the CAF first can change as a result of strictness analysis or other optimisations, and it isn't useful to expose this kind of non-determinism to the programmer. So the cost center stack when evaluating a CAF is always rooted at the CAF itself, and ignores the call site. CAFs are the free variables of the program, if you like. This is the argument, however I'm not sure I buy it any more. It clearly isn't very useful for backtracing, for one thing. It wouldn't really do any harm to have the costs for a CAF grafted onto the call stack at the site of its first evaluation. Figuring out how to make cost-centre-stacks do the right thing with CAFs is something of an open problem, in fact; there are currently cases where GHC produces strange results. Things get hairy when CAFs get evaluated to data structures that contain functions (eg. dictionaries). Cheers, Simon

Simon Marlow wrote:
Hmm yes, this is indeed rather unhelpful. I can explain why it happens, though. The compiler has lifted out the error case into a top-level binding:
x = error "Error in array index"
Would the compiler be less agressive with this if I turn off optimization? I usually use optimization with profiling as well, but could of course turn it off if it would result in more useful stack backtraces. -k

Simon Marlow wrote:
I can explain why it happens, though. The compiler has lifted out the error case into a top-level binding:
x = error "Error in array index"
So cost-centre stacks are not produced for the original program written by the user, but for the intermediate program after optimisation. I understand that you want to profile the optimised version, but the fact that your profile does not quite match your program can be confusing. For debugging, however, I think that it is clear that you want your debugging information (cost centre stacks) to match your program, even if it costs you some performance. Ciao, Olaf
participants (3)
-
Ketil Malde
-
Olaf Chitil
-
Simon Marlow