www.digitalmars.com         C & C++   DMDScript  

D - How good is DMD at inlining?

reply Hauke Duden <H.NS.Duden gmx.net> writes:
I have a question about the way inlining works in D. If a base class 
function contains a call to a function that is overridden in a child 
class, can that call be inlined if the compiler knows the full type of 
the object? I.e. will it generate a new version for the base class function?

Example:

interface I
{
	void a();
	void b();
}

class A : I
{
	void a()
	{
		b();
	}

	//b() is left unimplemented
}

class B : A
{
	void b()
	{
		... do stuff
	}
}

B ob=new B();

ob.a();

Will the b() call in a() be inlined by DMD? My gut tells me that this 
should be possible if the ob.a() call is inlined as well, but maybe the 
compiler does enough magic that this is also possible if it is not?

And if DMD does not do it: is it possible in theory? I.e. can we expect 
this to work sometime in the foreseeable future?

Hauke


	
Dec 28 2003
parent "Walter" <walter digitalmars.com> writes:
"Hauke Duden" <H.NS.Duden gmx.net> wrote in message
news:bsmr3u$1hbr$1 digitaldaemon.com...
 I have a question about the way inlining works in D. If a base class
 function contains a call to a function that is overridden in a child
 class, can that call be inlined if the compiler knows the full type of
 the object? I.e. will it generate a new version for the base class

 Example:

 interface I
 {
 void a();
 void b();
 }

 class A : I
 {
 void a()
 {
 b();
 }

 //b() is left unimplemented
 }

 class B : A
 {
 void b()
 {
 ... do stuff
 }
 }

 B ob=new B();

 ob.a();

 Will the b() call in a() be inlined by DMD?

No.
 My gut tells me that this
 should be possible if the ob.a() call is inlined as well, but maybe the
 compiler does enough magic that this is also possible if it is not?

 And if DMD does not do it: is it possible in theory? I.e. can we expect
 this to work sometime in the foreseeable future?

I think it's possible to do, but at the moment I'm working on a big upgrade to the templates!
Dec 28 2003