Bug 16360 – DMD fails to inline functions that contain a type

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-08-07T16:00:22Z
Last change time
2019-01-28T00:06:16Z
Keywords
pull
Assigned to
Basile-z
Creator
Basile-z
See also
https://issues.dlang.org/show_bug.cgi?id=19375

Comments

Comment #0 by b2.temp — 2016-08-07T16:00:22Z
When a simple type is nested in the function, e.g as an helper DMD fails to inline: °°°°°°°°°°°°°°°°°°°°°°°°°°°° #!runnable-flags: -O -inline module runnable; import std.stdio; pragma(inline, true) auto foo(int t) { struct Bar{} return t; } void main() { auto v = foo(1); } °°°°°°°°°°°°°°°°°°°°°°°°°°°° outputs: > /tmp/temp_7FD0A006D9F0.d(7,6): Error: function runnable.foo cannot inline function
Comment #1 by b2.temp — 2016-08-13T23:28:43Z
LDC succeeds, so DMD inliner only.
Comment #2 by ag0aep6g — 2016-08-14T00:15:10Z
I'm removing the "wrong-code" keyword, and downgrading this to an enhancement request. A wrong-code bug is when incorrect machine code is generated. The test case must compile and link for that, but dmd rejects the test case. It's only an enhancement request, because the spec explicitly allows the compiler to error out when it can't inline a function that has pragma(inline, true).
Comment #3 by turkeyman — 2018-06-27T06:35:31Z
This code should obviously inline. I think rejecting inline should be because there's a reason it can't inline. There's no such reason here, failure to inline is an implementation detail (ie, a bug).
Comment #4 by b2.temp — 2018-06-27T08:59:47Z
(In reply to Basile B. from comment #0) > When a simple type is nested in the function, e.g as an helper DMD fails to > inline: > > °°°°°°°°°°°°°°°°°°°°°°°°°°°° > #!runnable-flags: -O -inline > module runnable; > > import std.stdio; > > pragma(inline, true) > auto foo(int t) > { > struct Bar{} > return t; > } > > void main() > { > auto v = foo(1); > } > °°°°°°°°°°°°°°°°°°°°°°°°°°°° > > outputs: > > /tmp/temp_7FD0A006D9F0.d(7,6): Error: function runnable.foo cannot inline function Note : 1. this also fails if Bar is a nested static struct, which is more surprising. 2. this case is suspected to be part of the perf problem DMD has with ranges and pipelines (Voldemort types are often nested...)
Comment #5 by b2.temp — 2019-01-25T15:37:54Z
Comment #6 by github-bugzilla — 2019-01-28T00:06:15Z
Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/5f9f52d63819e96e5b89365d6d03d18cc3b2b948 fix issue 16360 - DMD fails to inline functions that contain a type https://github.com/dlang/dmd/commit/f38300766514ecc906904a209a5c2414cee8894f Merge pull request #9294 from Basile-z/static-nested-aggr-inline fix issue 16360 - DMD fails to inline functions that contain a type merged-on-behalf-of: Nicholas Wilson <[email protected]>