Forum > Suggestions
Proposition — new modifier to force compiler to inline or throw warning/error
marcov:
Forcing might not be possible in all cases anyway. So even with a forced inline it might not inline. Which means the name is wrong. It is a "try harder" not a guaranteed inline.
So if were really needed, I think a local directive to give the normal inline a bit more weight would be more sensible then yet another language extension.
And brings us to why you need this. You don't give much examples or reasons for that.
Thaddy:
Well Marco:
to some a note to understand what is happening is not good enough or clear enough. So the above suggestion to promote it to a hint or warning is a good idea and easy to fix.
That said, OP does not fully understand that in any inline mode, be it local or global, the compiler already does a best effort. The compiler is usually better than the programmer to decide this.
flowCRANE:
--- Quote from: marcov on November 08, 2023, 10:12:19 am ---Forcing might not be possible in all cases anyway. So even with a forced inline it might not inline. Which means the name is wrong. It is a "try harder" not a guaranteed inline.
--- End quote ---
Exactly — that's why I would like to know that the compiler could not do something what I want. if something cannot be inlined (even if force it), I can change my code, remove this function, place its code where it was previously called and create longer function without such calls. Currently, the inlining feature is more or less a mystery box.
By the way, I have an additional question about inline.
If the {$AUTOINLINE} is disabled, compiler will inline only routines that are marked as inlined (if it can do it). But what is going on if the {$AUTOINLINE} is enabled? Does the compiler decide to inline each routine separately, regardless of whether it is marked as inline or not? What if a routine is marked as inline? Does autoinline determine its inline in the same way as regular routines, or is the inline modifier taken into account and the compiler tries to inline it? In short, does autoiline treat routines marked with this modifier differently from those not marked?
I'm asking because I would like to understand how exactly this autoinline works.
MarkMLl:
--- Quote from: Thaddy on November 08, 2023, 10:39:34 am ---That said, OP does not fully understand that in any inline mode, be it local or global, the compiler already does a best effort. The compiler is usually better than the programmer to decide this.
--- End quote ---
In that case, by any reasonable standards, the compiler is broken.
If the programmer explicitly says "I want this to be inlined", and the compiler can't do it, then it's an error. "I prefer not to" is not an option here.
It's exactly the same as a programmer (back in the day) defining a procedure as an interrupt handler, or (more recently) declaring that a record is to be packed or that something must be stored as a threadvar, or a C programmer declaring a variable as volatile.
It is not the compiler's job to tell the programmer what to do.
MarkMLl
PascalDragon:
--- Quote from: furious programming on November 06, 2023, 02:02:54 pm ---This is only a free proposition.
Currently we have a inline modifier, which may or may not cause the compiler to inline a subroutine. There is also noinline to prevent compiler from inlining. But there is no modifier to force FPC to inline, so if the compiler can inline, it do so but if not, the appropriate compilation warning/error should be thrown (in the case of error, compilation should be aborted). IDK if currently is it possible to check if a given inlined subroutine was actually inlined or not, but AFAIK it's not.
My proposition is to use new doinline or forceinline keyword.
--- End quote ---
No, because the decision to inline not only depends on the routine that is marked as inline, but also on the routine that is calling the routine (and thus would receive the inlined body). If the node count becomes to complex (e.g. due to multiple inlinings) then the compiler will not inline it. Enforcing inlining goes against this.
--- Quote from: furious programming on November 08, 2023, 01:01:28 pm ---If the {$AUTOINLINE} is disabled, compiler will inline only routines that are marked as inlined (if it can do it). But what is going on if the {$AUTOINLINE} is enabled? Does the compiler decide to inline each routine separately, regardless of whether it is marked as inline or not? What if a routine is marked as inline? Does autoinline determine its inline in the same way as regular routines, or is the inline modifier taken into account and the compiler tries to inline it? In short, does autoiline treat routines marked with this modifier differently from those not marked?
--- End quote ---
$AutoInline is as if all routines are marked with inline (at least if they are technically inlinable anyway) though the compiler won't warn if it can't inline them anyway.
--- Quote from: MarkMLl on November 08, 2023, 04:00:10 pm ---If the programmer explicitly says "I want this to be inlined", and the compiler can't do it, then it's an error. "I prefer not to" is not an option here.
--- End quote ---
No. There might be reasons on the callsite that the compiler can't inline a routine marked as inline.
Navigation
[0] Message Index
[#] Next page
[*] Previous page