4

Ada Information Clearinghouse states the following:

The use of pragma Inline does have its disadvantages. It can create compilation dependencies on the body; that is, when the specification uses a pragma Inline, both the specification and corresponding body may need to be compiled before the specification can be used.

Does putting pragma Inline in the body avoid this problem?

Rodeo
  • 151
  • 9
  • 2
    Then how do you compile callers if they can't see the call will be inlined? –  Feb 14 '20 at 09:15
  • I might suggest that for functions you can also consider completing the inline functions in the private section of your package, assuming they are simple. Ada2012 has a lot of features to support expression functions. That'll keep the dependencies out of the body, but it won't work for a procedure. – Jere Feb 15 '20 at 17:03
  • Reading about expression functions, my question now is what the difference is between using a pragma inline and using an aspect `with inline` on an expression function. Is the result the same? – Rodeo Feb 15 '20 at 18:59
  • @BrianDrummond I suppose only units within the same body would get inlined then. That's probably not desirable. – Rodeo Feb 15 '20 at 19:01
  • @Rodeo well if you use an expression function you can place the function in the spec file, which is an additional way of avoiding dependencies on the body file. Otherwise, functionally it is the same or should be. Pragma inline and aspect inline should be the same. I *think* the pragma version is depricated now in favor of the aspect. – Jere Feb 15 '20 at 21:21

1 Answers1

5

The advantage is that Inline in the specification allows for cross-unit inlining which can be a very powerful run-time optimization.

The disadvantage you mention matters rather when you compile on a computer which is slow or has few cores. Then it's a run time vs compile time trade-off.

Note that on GNAT, cross-unit inlining is enabled by a single switch (-gnatn), so don't be afraid by the Inline pragma creating compilation dependencies: you can switch the whole mechanism on or off with that switch.

Zerte
  • 1,478
  • 10
  • 9