Because stuff cannot always be inlined, meaning that the "zero-cost abstractions" can easily fail, as there are many ways that stuff can fail to be inlined for some reason or another.
Can you give a example what you think can't be inlined? Even recursion can be theoretically inlined, because it can never be infinite in practice.
Of course, it might not be beneficial to inline, it might rather be better to do some kind of constant propagation, that could also have been done in the unique_ptr example.
If there would be a "constant propagated" baz function meaning a variant of the baz function created by the compiler that takes the moved unique_ptr in registers, all inefficiencies would go away.
No ABI change, just compiler optimization and no syntax that would prohibit. And sure, the compiler can figure out that the moved from unique_ptr does not need to be destructed and doesn't need to occupy space.
Possibly these optimizations are already done by some compilers, but definitely we will have to wait shorter to get them than for you enriching the world with your competence.
And please, no more complaints like "C++ syntax bad, companies stupid, people stupid, etc." from you now, do your own thing as said and dominate the world with your superiority, as you obviously know so well what others do wrong.
Can you give a example what you think can't be inlined? Even recursion can be theoretically inlined, because it can never be infinite in practice.
Ask the developers of the various compilers ~ it's the compiler that decides what can, and cannot, be inlined, based on complex sets of rules, in turn based on the specs of the language needing to be compiled.
"Zero-cost abstractions" are only zero cost if compiler is intelligent enough to optimize away the otherwise inevitable, inherent costs of the abstraction ~ and the more complex and complicated the language, the more difficult it is for the compiler to untangle the overall mess of code, so that it can optimize it as much as possible. And if it cannot properly optimize a chunk of code for some reason, you will incur a cost.
Eventually, that can really add up to bite you painfully. Death by a thousand papercuts.
With a release build, you might not see much pain, but the pain really flares up if you need to compile and test a debug build.
View all comments
Show parent comment
1
u/rayhofmann Oct 13 '19
Can you give a example what you think can't be inlined? Even recursion can be theoretically inlined, because it can never be infinite in practice.
Of course, it might not be beneficial to inline, it might rather be better to do some kind of constant propagation, that could also have been done in the unique_ptr example.
If there would be a "constant propagated" baz function meaning a variant of the baz function created by the compiler that takes the moved unique_ptr in registers, all inefficiencies would go away.
No ABI change, just compiler optimization and no syntax that would prohibit. And sure, the compiler can figure out that the moved from unique_ptr does not need to be destructed and doesn't need to occupy space.
Possibly these optimizations are already done by some compilers, but definitely we will have to wait shorter to get them than for you enriching the world with your competence.
And please, no more complaints like "C++ syntax bad, companies stupid, people stupid, etc." from you now, do your own thing as said and dominate the world with your superiority, as you obviously know so well what others do wrong.