Thread overview
mixins as inline functions
Aug 18, 2006
Serg Kovrov
Aug 18, 2006
Craig Black
Aug 18, 2006
Walter Bright
Aug 19, 2006
Serg Kovrov
Aug 19, 2006
Sean Kelly
Aug 19, 2006
Walter Bright
August 18, 2006
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?

-- 
serg.
August 18, 2006
There should definitely be plans for the evolution of mixins.  The feature is way jacked up and unusable for a lot of things that should work.  I don't forsee anything changing for 1.0 though.

-Craig

"Serg Kovrov" <kovrov@no.spam> wrote in message news:ec402d$pgv$1@digitaldaemon.com...
> 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?
>
> -- 
> serg.


August 18, 2006
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?
August 19, 2006
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?

-- 
serg.
August 19, 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
August 19, 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? =)

All functions are candidates for inlining.


> But if seriously, does virtual methods (accessing 'this') can be inlined?

Functions accessed through the virtual function pointer table cannot be inlined. Mixins can't fix that. To access a function directly, rather than through virtual dispatch, declare it to be 'final'.