Recent

Author Topic: Call to subroutine is not inlined  (Read 2871 times)

Kwadrum

  • New Member
  • *
  • Posts: 17
Call to subroutine is not inlined
« on: August 20, 2020, 04:54:54 am »
Hi,
I have a question on a hint given by a compiler.
I receive this:
Quote
main.pas(336,23) Note: Call to subroutine "procedure MeanAndStdDev(const data:{Open} Array Of Double;var mean:Extended;var stddev:Extended);" marked as inline is not inlined
for this:
Code: Pascal  [Select][+][-]
  1. var
  2. AR_dwell: array of array of array of double;
  3. ......
  4. begin
  5. ......
  6. SetLength(AR_dwell,5,5);       
  7. for j:=0 to 4 do
  8.     for k:=0 to 4 do
  9.         SetLength(AR_dwell[j][k], AR_trans[j,k]);    //variable sizes of the third dimension
  10. .....
  11. MeanAndStdDev(AR_dwell[j][k],mean,stdev);      //here the hint is given
  12. .....
  13. end.
  14.  
The values of mean and stdev are returned correctly, so it doesn't seem to be a real issue, but I'd like to make sure I understand what all this means. My guess is its somehow related to the fact that the array is dynamic and is addressed as open, probably smth like described here:
https://forum.lazarus.freepascal.org/index.php?topic=42141.0, a response from engkin

Do I understand it right? Do you think there is a better (correct) way to handle this in the code (as I am definitely not an expert)?
In case there is a question why 3-dimention array: I think in my case it is a very convenient way to handle a set of data which represents transitions of some system between several (5) states. So that the first dimension is the initial state, 2nd is the final state and the 3rd is some transition parameter.Transitions occur randomly and repeatedly with different unpredictable probabilities, which means the numbers of transitions for different pairs of states may differ by an order(s) of magnitude.

Thank you.

TRon

  • Hero Member
  • *****
  • Posts: 2435
Re: Call to subroutine is not inlined
« Reply #1 on: August 20, 2020, 05:06:13 am »
Do I understand it right? Do you think there is a better (correct) way to handle this in the code (as I am definitely not an expert)?
There is nothing you can do in your code to remove that hint.

It is a hint and that is simply all that t is: a hint from the compiler that tells that the mentioned procedure or function that you included/used and that is marked as inlined is unable to actually be inlined by the compiler during compilation.

If case it able to help you feel more secure, if you compile large amount of packages/units then you get these hints by the dozens, if not hundreds  :)

Kwadrum

  • New Member
  • *
  • Posts: 17
Re: Call to subroutine is not inlined
« Reply #2 on: August 20, 2020, 05:45:12 am »
Well, I see...
But who and based on what assumes it is inlined first of all? What handles the "inlined" label (or whatever it is) to the compiler?

TRon

  • Hero Member
  • *****
  • Posts: 2435
Re: Call to subroutine is not inlined
« Reply #3 on: August 20, 2020, 06:10:26 am »
But who and based on what assumes it is inlined first of all?
Unit math, function MeanAndStdDev, see https://svn.freepascal.org/cgi-bin/viewvc.cgi/tags/release_3_2_0/rtl/objpas/math.pp?view=markup#l513

Code: Pascal  [Select][+][-]
  1. procedure MeanAndStdDev(const data : array of Single; var mean,stddev : float);inline;
  2.  
Can you locate the word inline there ?

What the modifier inline actually means/does can be read here, https://www.freepascal.org/docs-html/current/ref/refsu75.html#x195-21700014.9.5

Also note the remark here, https://wiki.freepascal.org/Inline
Quote
Warning: Use inline with caution as there are currently bugs in all FPC versions. This affects all platforms. As of 14 February 2020

Quote
What handles the "inlined" label (or whatever it is) to the compiler?
It is called a modifier. The compiler handles it...

.. or at least it did. The note in the wiki probably means that work is (currently?) done on the compiler (with regards to the inline modifier) in order to fix the issues as reported. That could mean that for safety reasons it is turned off/ignored by default when  certain conditions are met (that causes issues). But the last paragraph is pure speculation on my part.

dbannon

  • Hero Member
  • *****
  • Posts: 2786
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Call to subroutine is not inlined
« Reply #4 on: August 20, 2020, 06:40:12 am »

There is nothing you can do in your code to remove that hint.

It is a hint and that is simply all that t is: a hint from the compiler that tells that the mentioned procedure or function that you included/used and that is marked as inlined is unable to actually be inlined by the compiler during compilation.
Well, you can suppress that hint.  In Lazarus IDE you can do it with Project Options, if compiling from the commad line, pass  -vm6058 to fpc.  The problem with this approach is that message 6058 is not defined in FPC304 so, your project will no longer build with the previous compiler.  In my build scripts, I now test to see which compiler is being used and act accordingly. (I also suppress 5027 - var not used and 2005 - level 2 comment).

If case it able to help you feel more secure, if you compile large amount of packages/units then you get these hints by the dozens, if not hundreds  :)
Indeed. And getting all those hints can easily obscure something you do need to see.

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: Call to subroutine is not inlined
« Reply #5 on: August 20, 2020, 09:19:55 am »
Do I understand it right? Do you think there is a better (correct) way to handle this in the code (as I am definitely not an expert)?
In case there is a question why 3-dimention array: I think in my case it is a very convenient way to handle a set of data which represents transitions of some system between several (5) states. So that the first dimension is the initial state, 2nd is the final state and the 3rd is some transition parameter.Transitions occur randomly and repeatedly with different unpredictable probabilities, which means the numbers of transitions for different pairs of states may differ by an order(s) of magnitude.

It is a note, essentially the lowest verbosity of a message available. And it simply means that the function MeanAndStdDev is declared with the inline directive (as TRon mentioned), but it's simply not inlined (in this case due to the open array parameter). There is nothing you can do here except disabling the message.

In addition to what dbannon wrote you can also use the following if you want it to be more targeted:

Code: Pascal  [Select][+][-]
  1. {$push}
  2. {$warn 6058 off}
  3. procedure Test;
  4. var
  5.   mean, stddev: Extended;
  6. begin
  7.   MeanAndStdDev([2.5, 53.4, 694], mean, stddev);
  8. end;
  9. {$pop}
  10.  

Please note that the disabling of the note needs to surround the whole function/method.

Quote
What handles the "inlined" label (or whatever it is) to the compiler?
It is called a modifier. The compiler handles it...

.. or at least it did. The note in the wiki probably means that work is (currently?) done on the compiler (with regards to the inline modifier) in order to fix the issues as reported. That could mean that for safety reasons it is turned off/ignored by default when  certain conditions are met (that causes issues). But the last paragraph is pure speculation on my part.

Users never knew if their routines were inlined or not. That's why we added the note so that users know that the compiler decided not to inline a routine due to one reason or the other (a very common one is inside a unit if the body of the function to be inlined has not yet been parsed, thus can't be inlined obviously). Also inlining does not support open array parameters (or inherited) yet.

TRon

  • Hero Member
  • *****
  • Posts: 2435
Re: Call to subroutine is not inlined
« Reply #6 on: August 21, 2020, 12:05:26 am »
Well, you can suppress that hint.
...
Thank you for mentioning the message hiding (forgot about that).

Quote
Indeed. And getting all those hints can easily obscure something you do need to see.
... such as an non inlined routine that you really wish to be inlined  :D

@PascalDragon:
Thank you for the elaboration on the why for this particular case.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: Call to subroutine is not inlined
« Reply #7 on: August 21, 2020, 09:32:48 am »
Quote
Indeed. And getting all those hints can easily obscure something you do need to see.
... such as an non inlined routine that you really wish to be inlined  :D

Even if you desperately wish it to be inlined there might always be a situation where the compiler says "nope, not gonna do that". After all inline is only a hint to the compiler, nothing more (and it's documented as such).

furious programming

  • Hero Member
  • *****
  • Posts: 853
Re: Call to subroutine is not inlined
« Reply #8 on: August 22, 2020, 07:41:58 pm »
@Kwadrum: don't worry — some people get worse. 8)
Lazarus 3.2 with FPC 3.2.2, Windows 10 — all 64-bit

Working solo on an acrade, action/adventure game in retro style (pixelart), programming the engine and shell from scratch, using Free Pascal and SDL. Release planned in 2026.

Kwadrum

  • New Member
  • *
  • Posts: 17
Re: Call to subroutine is not inlined
« Reply #9 on: September 28, 2020, 03:29:25 am »
Hi,
Thanks for a valuable discussion, I never thought it might result in so many comments  :)
I have made some reading on what "inlining" actually is, so it makes some sense now (to me).

Thank you!

MarkMLl

  • Hero Member
  • *****
  • Posts: 6676
Re: Call to subroutine is not inlined
« Reply #10 on: September 29, 2020, 08:44:41 pm »
Thanks for a valuable discussion, I never thought it might result in so many comments  :)
I have made some reading on what "inlining" actually is, so it makes some sense now (to me).

If you think that was a lot of comments then you ain't seen nothin' yet :-)

Actually, when this was last discussed (about three weeks ago IIRC) I highlighted the relevant bit of the compiler sources. Basically, and assuming that it's not disabled for maintenance, the compiler looks at the complexity of a branch of the parse tree and will only obey an  inline  modifier for relatively simple code. And the decision appears to be guided by a single number...

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

 

TinyPortal © 2005-2018