D.gnu - forceInline can't inline when source code is available
- Mike (33/33) May 27 2015 Consider this code
- ketmar (9/11) May 27 2015 actually, the code is not available, as ".d" file is treated like ".di"=...
- Iain Buclaw via D.gnu (6/35) May 27 2015 is there in the testInline.d file? Should I file a bug?
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 27 2015
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"=20 file here, i.e. file with only interface declarations. fixing this will=20 require to change frontend to distinguish between ".d" and ".di" files,=20 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=20 source for templates.=
May 27 2015
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 availableinline 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 codeis 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
May 27 2015