Timeline for Why do programs use call stacks, if nested function calls can be inlined?
Current License: CC BY-SA 3.0
18 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jan 5, 2019 at 2:31 | vote | accept | moonman239 | ||
| Jun 15, 2015 at 8:54 | comment | added | JacquesB | @mastov: Good point | |
| Jun 15, 2015 at 8:06 | history | edited | mcottle | CC BY-SA 3.0 |
Corrected two small typos
|
| Jun 15, 2015 at 7:41 | history | edited | JacquesB | CC BY-SA 3.0 |
added 151 characters in body
|
| Jun 14, 2015 at 14:16 | comment | added | MSalters | @user2357112: Not all stack are call stacks. In particular, a call stack contains stack frames for every non-inlined funtion that's been called but hasn't returned yet. | |
| Jun 14, 2015 at 9:59 | comment | added | user2357112 | @immibis: But if that explicit stack is introduced by the compiler, then that stack is the call stack. | |
| Jun 14, 2015 at 8:45 | comment | added | Stack Exchange Broke The Law | You can make all self-recursion iterative if you're okay with an explicit stack. Recursion involving multiple functions is where it gets hard. | |
| Jun 14, 2015 at 6:03 | comment | added | user2357112 | @MSalters: You can inline some recursive calls, but doing so gives you more recursive calls to inline. You can't inline all the calls, so pure inlining can't eliminate the need for a call stack. | |
| Jun 13, 2015 at 23:11 | comment | added | MSalters | @mastov: Why would recursion prevent inlining? Modern compilers actually do inline recursive calls. | |
| Jun 13, 2015 at 3:47 | comment | added | R.. GitHub STOP HELPING ICE | @MSalters: Well they do call it a dynamic linker. But what I meant was that if you want to do these kinds of optimizations, you have to give up dynamic linking as we know it, or at least avoid dynamic linking the parts of your program where the optimizations need to happen. | |
| Jun 13, 2015 at 1:07 | comment | added | MSalters | @R.. : LTO is LINK time Optimization, not LOAD Time Optimization. | |
| Jun 12, 2015 at 22:44 | comment | added | R.. GitHub STOP HELPING ICE | @MSalters: LTO completely precludes any meaningful form of dynamic linking - you can't have shareable code pages, or reasonable program start times, if you're deferring final code generation to load time. | |
| Jun 12, 2015 at 18:45 | comment | added | mastov | Wow, 28 upvotes for an answer that doesn't even mention the reason why inlining everything is impossible: Recursion. | |
| Jun 12, 2015 at 12:28 | comment | added | Blrfl | @MSalters: Code structured to depend on LTO sacrifices inlining entirely on toolchains that don't support it. In situations where 100% of the code will be built in an LTO-enabled world 100% of the time, then by all means go for it. There is lots of code in the world where that guarantee can't be made, and putting inline-able functions in headers allows essentially-identical optimization on the largest possible number of toolchains in a standards-compliant way. | |
| Jun 12, 2015 at 12:04 | comment | added | Random832 | "Functions which are exposed for external callers cannot be optimized away" - the function has to exist, but any given call site to it (either in your own code, or if they have the source, the external callers') can be inlined. | |
| Jun 12, 2015 at 11:21 | comment | added | MSalters | @Blrfl: Modern compilers actually don't need definitions in the header anymore; they can inline across Translation Units. This does require a decent linker, though. Definitions in header files are a workaround for dumb linkers. | |
| Jun 12, 2015 at 10:32 | comment | added | Blrfl | C and C++ allow public functions and methods to be inlined by declaring them in the header included by callers. Whether or not this is a good thing to do depends on your willingness to trade having to recompile everything (vs. just installing new dynamic libraries) for the benefits of the extra optimization. Implementations of languages that do JIT compilation could, in theory, do it as well. | |
| Jun 12, 2015 at 8:07 | history | answered | JacquesB | CC BY-SA 3.0 |