<div dir="ltr"><div dir="ltr">On Wed, Jun 19, 2019 at 3:40 PM Ryan Joseph <<a href="mailto:genericptr@gmail.com">genericptr@gmail.com</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
What are the rules with he calling context? I didn’t even know that was a factor! I’ll have to look to get some examples.<br></blockquote><div><br></div><div>Basically, if you're calling a function marked inline from another function, the implementation of the function to be inlined has to come first in the unit.</div><div><br></div><div>So for example, the following code generates assembly that is completely identical for all three functions, because `Proc` gets inlined into `Proc2` and then through that into `Proc3`.</div><div><br></div><div style="color:rgb(0,0,0);background-color:rgb(255,255,254)">unit Example;<br><br>{$mode ObjFPC}<br>{$modeswitch AdvancedRecords}<br><br>interface<br><br>type Letters = (A, B, C);<br><br>type<br> TRecord = record<br> procedure Proc; inline;<br> procedure Proc2; inline;<br> procedure Proc3;<br> end;<br><br>implementation<br><br>procedure TRecord.Proc;<br>begin<br> WriteLn([B] <= [A, B, C]);<br>end;<br><br>procedure TRecord.Proc2;<br>begin<br> Proc();<br>end;<br><br>procedure TRecord.Proc3;<br>begin<br> Proc2();<br>end;<br><br>end.<br></div><div style="color:rgb(0,0,0);background-color:rgb(255,255,254)"><br></div><div style="color:rgb(0,0,0);background-color:rgb(255,255,254)">If the implementation order was `Proc2` -> `Proc` -> `Proc3`, however, `Proc3` could still inline away both `Proc` and `Proc2`, but `Proc2` itself could not inline away `Proc.`</div><div style="color:rgb(0,0,0);background-color:rgb(255,255,254)"><br></div><div style="color:rgb(0,0,0);background-color:rgb(255,255,254)">Lastly, if the implementation for `Proc` came after both those for `Proc2` and `Proc3`, it would not be inlined into either. (I.E. `Proc3` would directly call `Proc2`, and `Proc2` would directly call `Proc`.)</div></div></div>