<div dir="ltr">Ah right, I had in mind that the transformation would still work because foo isn't mentioned in the loop, I guess that is a bad transformation because it will require changing the variable indexes.<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Apr 21, 2017 at 8:02 PM, Ramana Kumar <span dir="ltr"><<a href="mailto:Ramana.Kumar@cl.cam.ac.uk" target="_blank">Ramana.Kumar@cl.cam.ac.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Regarding point 1, the term is not ground because it has free variables "n" and "loop" in it.<br></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On 22 April 2017 at 09:42, Yong Kiam <span dir="ltr"><<a href="mailto:tanyongkiam@gmail.com" target="_blank">tanyongkiam@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Ah, I guess that's bvi_let. I'll have a look at whether it's actually doing it.<br></div><div class="m_5964680004467772917HOEnZb"><div class="m_5964680004467772917h5"><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Apr 21, 2017 at 7:37 PM, Magnus Myreen <span dir="ltr"><<a href="mailto:magnus.myreen@gmail.com" target="_blank">magnus.myreen@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Yong Kiam,<br><br>There is (or was meant to be) a phase around BVL or BVI that aims to turn Let xs (Var (LENGTH xs - 1)) into the desired code with last of xs moved into tail position.<br><br>Cheers,<br>Magnus<br><div class="gmail_quote"><div><div class="m_5964680004467772917m_-4984413284427820799h5"><div dir="ltr">On Sat, 22 Apr 2017 at 05:48, Yong Kiam <<a href="mailto:tanyongkiam@gmail.com" target="_blank">tanyongkiam@gmail.com</a>> wrote:<br></div></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="m_5964680004467772917m_-4984413284427820799h5"><div dir="ltr"><div><div>Hi dev,<br><br></div>I'm trying to get this benchmark running: <a href="https://raw.githubusercontent.com/MLton/mlton/master/benchmark/tests/tailfib.sml" target="_blank">https://raw.githubusercontent.<wbr>com/MLton/mlton/master/benchma<wbr>rk/tests/tailfib.sml</a> on a recent build of the bootstrapped compiler<br><br>I ran into this strange scenario:<br><br>Writing the loop like the following makes CakeML run out of stack (I think it fails to optimize the tail call because increasing the stack limit manually works):<br><br>val doit =<br>  fn n =><br>  let<br>    fun loop n =<br>      if n = 0<br>        then ()<br>        else (doit();loop(n-1))<br>  in loop (n * 1000000)<br>  end;<br><br></div><div>On the other hand, making the ; explicit:<br><br>val doit =<br>  fn n =><br>  let<br>    fun loop n =<br>      if n = 0<br>        then ()<br>        else <b>(let val foo = doit() in loop(n-1) end)<br></b>  in loop (n * 1000000)<br>  end;g<br><br></div><div>works fine.<br><br></div><div>I checked out the compilation down to patLang, and the only difference between the two is that the first is compiled to a Seq while the second is compiled to a Let.<br><br></div><div>There are actually two things of interest:<br><br></div><div>1) The ground check in exh_to_pat incorrectly says that  <b>(let val foo = doit() in loop(n-1) end) </b>is not ground, and does not compile it to doit() ; loop (n-1)<br><br></div><div>2) pat_to_clos compiles Seqs to Let [compile e1;compile e2] (Var 1) while the Lets go to Let [compile e1] (compile e2)<br><br></div><div>I think the issue is that the tail call detector cannot / does not detect the first tail call shape.<br></div><div><br></div><div>I'm not sure what the best fix is here, is the multiple-argument Let compilation of Seq important? If so, I guess the tail call detector in bvi_to_data should be updated to detect those shapes too.<br></div></div></div></div>
______________________________<wbr>_________________<br>
Developers mailing list<br>
<a href="mailto:Developers@cakeml.org" target="_blank">Developers@cakeml.org</a><br>
<a href="https://lists.cakeml.org/listinfo/developers" rel="noreferrer" target="_blank">https://lists.cakeml.org/listi<wbr>nfo/developers</a><br>
</blockquote></div>
</blockquote></div><br></div>
</div></div><br>______________________________<wbr>_________________<br>
Developers mailing list<br>
<a href="mailto:Developers@cakeml.org" target="_blank">Developers@cakeml.org</a><br>
<a href="https://lists.cakeml.org/listinfo/developers" rel="noreferrer" target="_blank">https://lists.cakeml.org/listi<wbr>nfo/developers</a><br>
<br></blockquote></div><br></div>
</div></div></blockquote></div><br></div>