While pure and inline do have a lot of overlap and, internally, probably
share some features for convenience (like a copy of the node tree), they
are not the same - for example, recursive functions can be pure, but not
inline, and functions that dereference pointers can be inlined, but not
made pure. The constant initialisation is one reason for pure
functions, as it might be more convenient to declare things like "const
ONE_OVER_E = Exp(-1);" instead of "const ONE_OVER_E =
0.36787944117144232159552377016146;" (although Exp might be an intrinsic
rather than a function - not sure).
Note that while there's room for auto-inlining certain routines, I would
not recommend "auto-puring" because determining if a function actually
is pure or not is likely going to be an expensive operation, and it's
more likely that a function will not be pure.
Gareth aka. Kit
On 25/06/2019 16:31, Ben Grasset wrote:
On Tue, Jun 25, 2019 at 1:20 AM Sven Barth via fpc-devel
<fpc-devel@lists.freepascal.org
<mailto:fpc-devel@lists.freepascal.org>> wrote:
Correct. Though considering that we're talking about *compile
time* the
compiler *could* treat consts (in {$J-} mode) as constants if pure
functions are involved...
I'd be fine with the {$J-} requirement (I tend to use {$J-} most of
the time anyways, actually.)
Again, I'm aware all of this will take a while to implement, and will
be an incremental process. Overall though I think proper compile-time
constant initialization needs to be something `pure` eventually
enables, as if it doesn't then it just becomes
"slightly-different-inlining". (And like denisgolovan pointed out in
another message, inlining should remain a separate concept that can be
mixed with pure, or not mixed with it, depending on the use case. E.G.
a C++ compiler will automatically inline basically anything at -O3,
but it will not let you use a non-constexpr function to initialize an
actual constexpr value.)
_______________________________________________
fpc-devel maillist - fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
_______________________________________________
fpc-devel maillist - fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel