<div dir="ltr"><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, 7 Jan 2020 at 05:59, Ömer Sinan Ağacan <<a href="mailto:omeragacan@gmail.com">omeragacan@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi all,<br>
<br>
> There's no need to set the srt field of f_info if f_closure is the SRT, since<br>
> any reference to f_info in the code will give rise to a reference to f_closure<br>
> in the SRT corresponding to that code fragment. Does that make sense?<br>
<br>
Makes sense, thanks.<br>
<br>
> The use of a closure as an SRT is really quite a nice optimisation actually.<br>
<br>
Agreed.<br>
<br>
> · If f is top level, and calls itself, there is no need to include a pointer<br>
> to f’s closure in f’s own SRT.<br>
><br>
> I think this last point is the one you are asking, but I’m not certain.<br>
<br>
Close, I'm asking whether we should include a pointer to f in f's SRT (when f is<br>
recursive) when we're using f as the SRT (the [FUN] optimisation).<br></blockquote><div><br></div><div>I think your original question was slightly different, it was about f's info table: </div><div><br></div><div>> should f's entry block's info table have f_closure as its SRT?</div><div><br></div><div>anyway, the answer to both questions is "no."</div><div><br></div><div>Cheers</div><div>Simon</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
I'll document the code I quoted in my original email with this info.<br>
<br>
Thanks,<br>
<br>
Ömer<br>
<br>
Simon Peyton Jones <<a href="mailto:simonpj@microsoft.com" target="_blank">simonpj@microsoft.com</a>>, 7 Oca 2020 Sal, 00:11<br>
tarihinde şunu yazdı:<br>
><br>
> Aha, great. Well at least [Note SRTs] should point back to the wiki page.<br>
><br>
><br>
><br>
> Omer's question is referring specifically to the [FUN] optimisation described in the Note.<br>
><br>
> Hmm. So is he asking whether f’s SRT should have an entry for itself? No, that’ would be silly! It would not lead to any more CAFs being reachable.<br>
><br>
><br>
><br>
> Omer, maybe we are misunderstanding. But if so, can you cast your question more precisely in terms of which lines of the wiki page or Note are you asking about? And let’s make sure that the appropriate bit gets updated when you’ve nailed the answer<br>
><br>
><br>
><br>
> Simon<br>
><br>
><br>
><br>
> From: Simon Marlow <<a href="mailto:marlowsd@gmail.com" target="_blank">marlowsd@gmail.com</a>><br>
> Sent: 06 January 2020 18:17<br>
> To: Simon Peyton Jones <<a href="mailto:simonpj@microsoft.com" target="_blank">simonpj@microsoft.com</a>><br>
> Cc: Ömer Sinan Ağacan <<a href="mailto:omeragacan@gmail.com" target="_blank">omeragacan@gmail.com</a>>; ghc-devs <<a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a>><br>
> Subject: Re: Code generation/SRT question<br>
><br>
><br>
><br>
> We have:<br>
><br>
> * wiki: <a href="https://gitlab.haskell.org/ghc/ghc/wikis/commentary/rts/storage/gc/cafs" rel="noreferrer" target="_blank">https://gitlab.haskell.org/ghc/ghc/wikis/commentary/rts/storage/gc/cafs</a><br>
><br>
> * a huge Note in CmmBuildInfoTables: <a href="https://gitlab.haskell.org/ghc/ghc/blob/master/compiler%2Fcmm%2FCmmBuildInfoTables.hs#L42" rel="noreferrer" target="_blank">https://gitlab.haskell.org/ghc/ghc/blob/master/compiler%2Fcmm%2FCmmBuildInfoTables.hs#L42</a><br>
><br>
><br>
><br>
> Maybe we need links to these from other places?<br>
><br>
><br>
><br>
> Omer's question is referring specifically to the [FUN] optimisation described in the Note.<br>
><br>
><br>
><br>
> Cheers<br>
><br>
> Simon<br>
><br>
><br>
><br>
> On Mon, 6 Jan 2020 at 17:50, Simon Peyton Jones <<a href="mailto:simonpj@microsoft.com" target="_blank">simonpj@microsoft.com</a>> wrote:<br>
><br>
> Omer,<br>
><br>
><br>
><br>
> I think I’m not understanding all the details, but I have a clear “big picture”. Simon can correct me if I’m wrong.<br>
><br>
><br>
><br>
> · The info table for any closure (top-level or otherwise) has a (possibly empty) Static Reference Table, SRT.<br>
><br>
> · The SRT for an info table identifies the static top level closures that the code for that info table mentions. (In principle the garbage collector could parse the code! But it’s easier to find these references if they in a dedicated table alongside the code.)<br>
><br>
> · A top level closure is a CAF if it is born updatable.<br>
><br>
> · A top level closure is CAFFY if it is a CAF, or mentions another CAFFY closure.<br>
><br>
> · An entry in the SRT can point<br>
><br>
> o To a top-level updatable closure. This may now point into the dynamic heap, and is what we want to keep alive. If the closure hasn’t been updated, we should keep alive anything its SRT points to.<br>
><br>
> o Directly to another SRT (or info table?) for a CAFFY top-level closure, which is a bit faster if we know the thing is non-updatable.<br>
><br>
> · If a function f calls a top-level function g, and g is CAFFY, then f’s SRT should point to g’s closure or (if g is not a CAF) directly to its SRT.<br>
><br>
> · If f is top level, and calls itself, there is no need to include a pointer to f’s closure in f’s own SRT.<br>
><br>
> I think this last point is the one you are asking, but I’m not certain.<br>
><br>
> All this should be written down somewhere, and perhaps is. But where?<br>
><br>
> Simon<br>
><br>
><br>
><br>
> From: ghc-devs <<a href="mailto:ghc-devs-bounces@haskell.org" target="_blank">ghc-devs-bounces@haskell.org</a>> On Behalf Of Simon Marlow<br>
> Sent: 06 January 2020 08:17<br>
> To: Ömer Sinan Ağacan <<a href="mailto:omeragacan@gmail.com" target="_blank">omeragacan@gmail.com</a>><br>
> Cc: ghc-devs <<a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a>><br>
> Subject: Re: Code generation/SRT question<br>
><br>
><br>
><br>
> There's no need to set the srt field of f_info if f_closure is the SRT, since any reference to f_info in the code will give rise to a reference to f_closure in the SRT corresponding to that code fragment. Does that make sense?<br>
><br>
><br>
><br>
> The use of a closure as an SRT is really quite a nice optimisation actually.<br>
><br>
><br>
><br>
> Cheers<br>
><br>
> Simon<br>
><br>
><br>
><br>
> On Wed, 1 Jan 2020 at 09:35, Ömer Sinan Ağacan <<a href="mailto:omeragacan@gmail.com" target="_blank">omeragacan@gmail.com</a>> wrote:<br>
><br>
> Hi Simon,<br>
><br>
> In Cmm if I have a recursive group of functions f and g, and I'm using f's<br>
> closure as the SRT for this group, should f's entry block's info table have<br>
> f_closure as its SRT?<br>
><br>
> In Cmm syntax<br>
><br>
> f_entry() {<br>
> { info_tbls: [...<br>
> (c1vn,<br>
> label: ...<br>
> rep: ...<br>
> srt: ??????]<br>
> stack_info: ...<br>
> }<br>
> {offset<br>
> c1vn:<br>
> ...<br>
> }<br>
> }<br>
><br>
> Here should I have `f_closure` in the srt field?<br>
><br>
> I'd expect yes, but looking at the current SRT code, in<br>
> CmmBuildInfoTables.updInfoSRTs, we have this:<br>
><br>
> (newInfo, srtEntries) = case mapLookup (g_entry g) funSRTEnv of<br>
><br>
> Nothing -><br>
> -- if we don't add SRT entries to this closure, then we<br>
> -- want to set the srt field in its info table as usual<br>
> (info_tbl { cit_srt = mapLookup (g_entry g) srt_env }, [])<br>
><br>
> Just srtEntries -> srtTrace "maybeStaticFun" (ppr res)<br>
> (info_tbl { cit_rep = new_rep }, res)<br>
> where res = [ CmmLabel lbl | SRTEntry lbl <- srtEntries ]<br>
><br>
> Here we only update SRT field of the block if we're not adding SRT entries to<br>
> the function's closure, so in the example above, because we're using the<br>
> function as SRT (and adding SRT entries to its closure) SRT field of c1vn won't<br>
> be updated.<br>
><br>
> Am I missing anything?<br>
><br>
> Thanks,<br>
><br>
> Ömer<br>
</blockquote></div></div>