Thread overview | |||||
---|---|---|---|---|---|
|
May 28, 2015 @forceInline can't inline when source code is available | ||||
---|---|---|---|---|
| ||||
Consider this code testInline.d ************ module testInline; import gcc.attribute; public enum inline = gcc.attribute.attribute("forceinline"); @inline int add(int a, int b) { return a + b; } test.d ****** import std.stdio; import testInline; void main() { writeln(add(1, 2)); } Compiler Output *************** gdc test.d test.d: In function 'D main': testInline.d:7:13: error: inlining failed in call to always_inline 'add': function body not available @inline int add(int a, int b) ^ test.d:8:5: error: called from here writeln(add(1, 2)); ^ Shouldn't it be able to inline the "add" function since the source code is there in the testInline.d file? Should I file a bug? Mike |
May 28, 2015 Re: @forceInline can't inline when source code is available | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mike Attachments: | On Thu, 28 May 2015 02:12:10 +0000, Mike wrote:
> Shouldn't it be able to inline the "add" function since the source code is there in the testInline.d file? Should I file a bug?
actually, the code is not available, as ".d" file is treated like ".di" file here, i.e. file with only interface declarations. fixing this will require to change frontend to distinguish between ".d" and ".di" files, and will be inconsistent.
but you can fix your code instead: declare your function as template:
@inline int add()(int a, int b) { return a+b; }
this way it will work, and it will be consistent, as ".di" files includes source for templates.
|
May 28, 2015 Re: @forceInline can't inline when source code is available | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mike Attachments:
| On 28 May 2015 04:15, "Mike via D.gnu" <d.gnu@puremagic.com> wrote: > > Consider this code > > testInline.d > ************ > module testInline; > > import gcc.attribute; > > public enum inline = gcc.attribute.attribute("forceinline"); > > @inline int add(int a, int b) > { > return a + b; > } > > test.d > ****** > import std.stdio; > > import testInline; > > void main() > { > writeln(add(1, 2)); > } > > Compiler Output > *************** > gdc test.d > test.d: In function 'D main': > testInline.d:7:13: error: inlining failed in call to always_inline 'add': function body not available > @inline int add(int a, int b) > ^ > test.d:8:5: error: called from here > writeln(add(1, 2)); > ^ > > > Shouldn't it be able to inline the "add" function since the source code is there in the testInline.d file? Should I file a bug? > It's well known that cross-module inlining doesn't work for separate compilation. Only option is to compile all sources in one go. Isin |
Copyright © 1999-2021 by the D Language Foundation