[fpc-devel] Little question about the "First Pass"

Sven Barth pascaldragon at googlemail.com
Thu Aug 9 11:15:14 CEST 2018


J. Gareth Moreton <gareth at moreton-family.com> schrieb am Mi., 8. Aug. 2018,
23:45:

> Hi everyone,
>
> So I'm making progress with my pure function implementation, or something
> passing as an early alpha prototype.  I do have a question though... when
> the "firstpass" routines are called, have all the procedures been compiled
> into nodes yet? I'm still trying to work out the best time to evaluate
> function purity, partly due to constructs such as this:
>
> interface
>
> function PureFunc1(Input: Integer): Boolean;
> function PureFunc2(Input: Integer): Boolean;
>
> implementation
>
> function PureFunc1(Input: Integer): Boolean; pure;
> begin
>   Result := PureFunc2(Input * Input); { "pure" directive for PureFunc2
> hasn't been seen yet }
> end;
>
> function PureFunc2(Input: Integer): Boolean; pure;
> begin
>   { Do something complicated but deterministic! }
> end;
>
> ****
>
> I could probably find the answer after some long research, but I'm trying
> to avoid wasting time unnecessarily.  I would guess that the evaluation
> should occur at a similar time to when inline functions are expanded, where
> they are fully-defined and known to be inlinable.
>

First of such modifiers should only be allowed in the interface section,
not the implementation section as they would essentially be a change of the
routine's signature (doesn't matter that it isn't part of the routine's
mangled name) and thus a change of the unit's interface which in turn would
require a recompilation of units using that unit.

To your question itself: once a non-nested routine body is parsed it's code
is generated which includes both the first and second pass. For nested
routines the same is done once the outermost routine as been parsed (but
before that one's first pass).

Regards,
Sven

>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20180809/50a0e163/attachment.html>


More information about the fpc-devel mailing list