* Interfaces, Inlining, and Dispatching
@ 2017-04-16 15:59 Jere
2017-04-17 5:53 ` G.B.
0 siblings, 1 reply; 2+ messages in thread
From: Jere @ 2017-04-16 15:59 UTC (permalink / raw)
As I am messing around with interface types I am trying to figure
out some things:
1. Is it possible for compilers to inline interface procedure
implementations if the type being used is known at compile time?
I.E: not using a class wide type or class wide access type to
invoke the procedure.
2. If so, do current compilers implement this?
3. Assuming another part of the code use a separate implementation
but dispatches from a class wide type or access type, will this
revoke the inlining in the other code mentioned in question 1?
I.E. Can the compiler have an inline version for statically
dispatched procedure calls and a non inline version for dynamically
dispatched calls?
4. If so, do current compilers implement this?
Example:
package Some_Interface is
type Intfc is interface;
type Intfc_Class_Access is access all Intfc'Class;
procedure Do_Somethig(Self : in Intfc) is abstract;
end Some_Interface;
package Implementor_1 is
type Impl is new interface with null record;
overriding
procedure Do_Something(Self : in Impl);
end Implementor_1;
package Implementor_2 is
type Impl is new interface with null record;
overriding
procedure Do_Something(Self : in Impl);
end Implementor_2;
procedure Test_Intfc is
Impl1 : Implementor_1.Impl;
Impl2 : Implementor_2.Impl;
Impls : array(1..2) of Some_Interface.Intfc_Class_Access
:= (1 => new Implementor_1.Impl,
2 => new Implementor_2.Impl);
begin
-- I think these cannot be inlined in order to do
-- the dynamic dispatching
for Ptr of Impls loop
Ptr.Do_Something;
end loop;
-- Can (and does) the compiler inline these
-- if they have a small simple implementation
-- like just calling another private procedure,
-- or does the dynamic dispatching above prevent the
-- compiler from making a second inlined version
-- of these procedures.
Impl1.Do_Something;
Impl2.Do_Something;
end Test_Intfc;
Forgive any typos. This was typed up just to illustrate the
question.
Thanks!
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Interfaces, Inlining, and Dispatching
2017-04-16 15:59 Interfaces, Inlining, and Dispatching Jere
@ 2017-04-17 5:53 ` G.B.
0 siblings, 0 replies; 2+ messages in thread
From: G.B. @ 2017-04-17 5:53 UTC (permalink / raw)
On 16.04.17 17:59, Jere wrote:
> As I am messing around with interface types I am trying to figure
> out some things:
>
> 1. Is it possible for compilers to inline interface procedure
> implementations if the type being used is known at compile time?
> I.E: not using a class wide type or class wide access type to
> invoke the procedure.
>
> 2. If so, do current compilers implement this?
>
> 3. Assuming another part of the code use a separate implementation
> but dispatches from a class wide type or access type, will this
> revoke the inlining in the other code mentioned in question 1?
> I.E. Can the compiler have an inline version for statically
> dispatched procedure calls and a non inline version for dynamically
> dispatched calls?
>
> 4. If so, do current compilers implement this?
Editing the program so that it can be compiled, and then
choosing one of the freely available compilers has answered
questions 3 and 4 for me. I believe that strictly speaking,
an Inline aspect must apply to a subprogram if the compiler
is to remove the call in favor of inlining. I don't see,
both physically by looking at generated code, and logically
by guessing, mostly, that a compiler isn't allowed to translate
a subprogram in ways that preserve the intended semantics.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-04-17 5:53 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-16 15:59 Interfaces, Inlining, and Dispatching Jere
2017-04-17 5:53 ` G.B.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox