mixins as inline functions

Sean Kelly sean at f4.ca
Fri Aug 18 18:48:47 PDT 2006


Serg Kovrov wrote:
> Walter Bright wrote:
>> Serg Kovrov wrote:
>>> First time I looked at mixins in D reference, I thought that it could 
>>> be used as inline function. Like a big C macro. But better =)
>>>
>>> It has its own scope, it has access to parent scope, everything seems 
>>> fit. Except that in mixins it is not possible to use assign 
>>> operations. Could this restriction be removed in future? Is there any 
>>> plans for mixins evolution?
>>
>> Why not just use inline functions?
> 
> Er... Because there is no inline functions? =)
> 
> But if seriously, does virtual methods (accessing 'this') can be inlined?

In some cases, yes, if the compiler can determine that the result will 
be correct.  However, use of function pointers and delegates is not 
inlined.  For this reason, I sometimes use a struct with opCall defined 
instead (as these calls are inlined by DMD in many cases).  I haven't 
figured out the magic formula for having an opCall be inlined however (I 
should really look at the DMD front-end code and figure it out). 
Sometimes simply adding "static" to the opCall declaration is enough to 
have the function go from inlined to not, and in other cases an opCall 
that is inlined in one routine is not inlined in another.  I'm currently 
wrestling with this in a quicksort implementation I've been tweaking.

If you don't mind the work, the best thing is to simply experiment 
(compile with "-inline -release -O") and view the output with obj2asm.


Sean



More information about the Digitalmars-d mailing list