[erlang-questions] How to get the line number of current executable code?
Robert Virding
rvirding@REDACTED
Mon Aug 18 14:59:18 CEST 2008
2008/8/18 Richard A. O'Keefe <ok@REDACTED>
>
> On 16 Aug 2008, at 8:35 am, Kevin Scaldeferri wrote:
>
> There is a tradeoff.
> When your compiler does good stuff like constant propagation,
> inlining, loop unrolling, loop fusion, &c, it gets hard to make
> 'the line number' mean anything. For example, suppose we had
>
> Ns = [sum(L) || L <- Ls],
> Ds = [length(L) || L <- Ls],
> Aves = [N/D || {N,D} <- lists:zip(Ns, Ds)]
>
> This is the kind of thing the GHC compiler eats for lunch;
> assuming Ns and Ds are not used anywhere else it turns into
> the equivalent of
>
> Aves = [sum(L)/length(L) || L <- Ls]
>
> Which line does this correspond to? ALL of them.
> (Actually, I believe GHC will take this a stage further, and inline
> and fuse the sum and length loops as well. In which case we have
> code within a single "line" coming from several files.)
>
> The Erlang compiler isn't that smart. (Yet. A man can dream.)
One problem Erlang would have doing this type of optimisation, which would
be wonderful to have, is the handling of side effects and errors. That type
of aggressive inlining and fusing would change the order in which side
effects occur which means that the code would not be equivalent. Similar for
errors. Haskell, being side-effect free, does not have this problem.
Robert
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20080818/41fd6265/attachment.htm>
More information about the erlang-questions
mailing list