[fpc-pascal] not inlined?

Ben Grasset operator97 at gmail.com
Wed Jun 19 22:21:55 CEST 2019


On Wed, Jun 19, 2019 at 3:40 PM Ryan Joseph <genericptr at gmail.com> wrote:

> 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.
>

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.

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`.

unit Example;

{$mode ObjFPC}
{$modeswitch AdvancedRecords}

interface

type Letters = (A, B, C);

type
  TRecord = record
    procedure Proc; inline;
    procedure Proc2; inline;
    procedure Proc3;
  end;

implementation

procedure TRecord.Proc;
begin
  WriteLn([B] <= [A, B, C]);
end;

procedure TRecord.Proc2;
begin
  Proc();
end;

procedure TRecord.Proc3;
begin
  Proc2();
end;

end.

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.`

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`.)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20190619/3fe61ca6/attachment.html>


More information about the fpc-pascal mailing list