<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Generator" content="Microsoft Exchange Server">
<!-- converted from text --><style><!-- .EmailQuote { margin-left: 1pt; padding-left: 4pt; border-left: #800000 2px solid; } --></style>
</head>
<body>
<meta content="text/html; charset=UTF-8">
<style type="text/css" style="">
<!--
p
        {margin-top:0;
        margin-bottom:0}
-->
</style>
<div dir="ltr">
<div id="x_divtagdefaultwrapper" dir="ltr" style="font-size:12pt; color:#000000; font-family:Calibri,Helvetica,sans-serif">
<p>Hi Ramana,</p>
<p><br>
</p>
<p>The offset is not used. We were told it is used to specify at what character number (as an ordinal) the location is. So in a file with the following contents</p>
<p><br>
</p>
<p>  Hello,</p>
<p>  World</p>
<p><br>
</p>
<p>the "," would be at offset 6 (assuming 1-indexing) and "W" at offset 7. This might be useful for some use cases of the datatype, but for our purposes we <span style="font-size:12pt">don't need it. Start position and end position is enough to uniquely identify
 an expression. So what you are seeing is correct.</span></p>
<p><br>
</p>
<p>As for the second problem, what you are doing as it stands is assign the same trace to several expressions. This is indeed problematic, as we would want each expression to have a unique trace. The only exception is expressions which exactly share trace with
 their ancestor, i.e., an expression they were derived from.</p>
<p><br>
</p>
<p>In general, when a trace appears more than once in the right hand side of a declaration, it should be split using the Cons constructor to ensure uniqueness of every trace. So I would write it something like this:</p>
<p><br>
</p>
<p><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:15px">  (compile_exp t env (ast$App op es) =</span><br style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:15px">
<span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:15px">    if op = AallocEmpty then</span><br style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:15px">
<span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:15px">      FOLDR (Let
<b>(Cons t 1)</b> NONE) (modLang$App <b>(Cons t 2)</b> Aalloc [Lit <b>(Cons t 3)</b> (IntLit (&0));Lit
<b>(Cons t 4)</b> (IntLit (&0))])</span><br style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:15px">
<span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:15px">        (REVERSE (compile_exps
<b>(Cons </b><b>t 5)</b> env es))</span><br style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:15px">
<span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:15px">    else</span><br style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:15px">
<span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:15px">      modLang$App
<b>(Cons </b><b>t 1)</b> (astOp_to_modOp op) (compile_exps <b>(Cons </b><b>t 2)</b> env es))</span><br>
</p>
<p><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:15px"><br>
</span></p>
<p><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:15px">Of course, a bad thing about this way to write it is that as the new trace gets passed to compile_exps, it also
 grows. Ideally, you would have a number <i>n</i> which would serve as a counter, telling you the next number to add in a Cons. If that was an extra parameter, it would instead be:</span></p>
<p><br>
</p>
<p><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:15px">  (compile_exp t
<b>n </b>env (ast$App op es) =</span><br style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:15px">
<span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:15px">    if op = AallocEmpty then</span><br style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:15px">
<span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:15px">      FOLDR (Let <b>(Cons t n)</b> NONE) (modLang$App <b>(Cons t (n+1))</b> Aalloc [Lit <b>(Cons t (n+2))</b> (IntLit
 (&0));Lit <b>(Cons t (n+3))</b> (IntLit (&0))])</span><br style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:15px">
<span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:15px">        (REVERSE (compile_exps t
<b>(n+4)</b> env es))</span><br style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:15px">
<span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:15px">    else</span><br style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:15px">
<span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:15px">      modLang$App <b>(Cons </b><b>t n)</b> (astOp_to_modOp op) (compile_exps t
<b>(n+1)</b> env es))</span><br>
</p>
<p><br>
</p>
<p>This is cleaner in the sense that all the newly created expressions would then have the same trace, only wrapped in a single Cons, rather than the traces growing increasingly bigger.</p>
</div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="x_divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>Från:</b> Magnus Myreen <magnus.myreen@gmail.com><br>
<b>Skickat:</b> den 30 juni 2017 08:50:37<br>
<b>Till:</b> Ramana Kumar<br>
<b>Kopia:</b> developers@cakeml.org<br>
<b>Ämne:</b> Re: [CakeML-dev] compiler explorer</font>
<div> </div>
</div>
</div>
<font size="2"><span style="font-size:10pt;">
<div class="PlainText">On 30 June 2017 at 08:39, Ramana Kumar <Ramana.Kumar@cl.cam.ac.uk> wrote:<br>
> The compiler explorer seems to have been written prior to some changes to<br>
> the locations type. Looking at this line in particular, I notice that the<br>
> offset field of the locn record is not used. Is this correct?<br>
><br>
>   (compile_exp t env (Lannot e (Locs st en)) =<br>
>     let t' = if t = None then t else (Cons (Cons (Cons (Cons Empty st.row)<br>
> st.col) en.row) en.col) in<br>
>       compile_exp t' env e)<br>
><br>
> for reference:<br>
><br>
> val _ = Datatype `<br>
>  locn = <| row : num;  col : num; offset : num |>`;<br>
><br>
> val _ = Datatype `<br>
>   locs = Locs locn locn<br>
> `<br>
<br>
I don't think it matters. As far as I know, the offset is just another<br>
way of representing the same information.<br>
<br>
By the way, the (Cons (Cons (Cons (Cons Empty st.row) pattern should<br>
have constructor `SourceLoc num num num num` of its own in the tra<br>
type (backend_common).<br>
<br>
> Another problematic case, where probably I am not passing along the right<br>
> traces in the AallocEmpty case:<br>
><br>
>   (compile_exp t env (ast$App op es) =<br>
>     if op = AallocEmpty then<br>
>       FOLDR (Let t NONE) (modLang$App t Aalloc [Lit t (IntLit (&0)); Lit t<br>
> (IntLit (&0))])<br>
>         (REVERSE (compile_exps t env es))<br>
>     else<br>
>       modLang$App t (astOp_to_modOp op) (compile_exps t env es))<br>
<br>
Yup, the function needs to become a little bit more complicated in<br>
order to ensure that each constructor has a unique trace t.<br>
<br>
_______________________________________________<br>
Developers mailing list<br>
Developers@cakeml.org<br>
<a href="https://lists.cakeml.org/listinfo/developers">https://lists.cakeml.org/listinfo/developers</a><br>
</div>
</span></font>
</body>
</html>