pragma(inline, true) not very useful in its current state?

Artur Skawina via Digitalmars-d digitalmars-d at puremagic.com
Sat Sep 26 10:58:14 PDT 2015


On 09/26/15 18:42, Marco Leise via Digitalmars-d wrote:
> Am Sat, 26 Sep 2015 12:21:15 +0200
> schrieb Jacob Carlborg <doob at me.com>:
> 
>> On 2015-09-26 06:27, Manu via Digitalmars-d wrote:
>>
>>> We _really_ need attribute aliasing in
>>> some form, especially since LDC/GDC have compiler-specific attributes
>>> that DMD doesn't recognise.
>>
>> I'm not sure how much this helps but can't you use a dummy UDA on DMD 
>> for the GDC/LDC attributes?
>  
> pragma(inline, true) void foo() @gcc.attribute.attribute("forceinline") @ldc.attribute.attribute("alwaysinline") @safe pure nothrow @nogc
> {
> 	// Ok, what did I want this to do again ... ?
> }

It's more like:

 pragma(inline, true) void foo() @inline @safe pure nothrow @nogc
 {
 	// Ok, what did I want this to do again ... ?
 }

where `inline` would be aliased to the right LDC/GDC attribute.


> Maybe the compiler devs can decide on more common syntax like
> a generic core.attribute or just use pragma for inlining, but

No, `pragma` can not be conditionally enabled or aliased.

It does not work well in D, except in cases it's used to extend
the language in a non-implementation-specific way.
(C/C++ have the preprocessor, that's why it works there)


> extend it so that it offers more options:
> 
> * no
> * force
> * flatten
> (And maybe an additional 'allow' that convinces the compiler
>  that inlining is safe.)

`allow` is the default state and always safe; for the cases
where it's /undesirable/, there is noinline.

artur


More information about the Digitalmars-d mailing list