Yes, it would work in this case. useless's node would hold a reference
to xs, but the bytecode rewriter would remove the assignment to the
local reference to useless, since it is not used later. (The lastRef
fix does not yet handle this sort of case, but eventually will.) For
that reason, useless would not be referenced at the time of the call
to length. Then, before length is called, the local reference to xs
would be nulled out.

In fact, it's a little more complex than this, since the CAL compiler
itself removes useless, so the bytecode rewriter does not need to deal
with it. But the rewriting will work even in cases where the CAL
compiler does not perform this optimization.

For a better of idea of what is and isn't handled, note that the
rewriter is using liveness analysis on the bytecode, which it uses to
determine where to null variables. (Eventually, the lastRef fix will
use a similar technique, but in the CAL compiler instead.) So the
rewriter handles no more and no less than what it can detect with
liveness analysis.

On Oct 31, 2:34 am, Ingo Wechsung <[EMAIL PROTECTED]> wrote:
> On 30 Okt., 17:26, Malcolm Sharpe <[EMAIL PROTECTED]> wrote:
>
> > Proper tail calls would help sometimes, but not always.
>
> This is sad, but, of course, true.
> As I understand you, your optimizations for the CAL language would
> help in the
> following case:
>
> foo () = let xs = ... in 2+length xs
>
> since the compiler would see that xs is not used anymore after the
> call to length and would take care that in the stack frame of foo no
> reference to xs retains.
>
> Would it also work in the following case:
>
> foo() = let
>        xs = ....create long lazy list ....
>        useless = tail xs;
>     in 2+length xs;


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "JVM 
Languages" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/jvm-languages?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to