I don't know much about allocators and the implications of low level optimisations, but this occurred to me a few days ago, and I have been thinking about it a bit. I did a bit of searching online but couldn't find much information about anything like this being done in other languages.
Is it possible, under some circumstances, for (a future version of) Rust to support dynamically resizable function stack frames?
It seems to me that the following conditions are sufficient:
- There is one dynamically sized variable per function.
- The function is the owner of that variable.
- Mutations of the variable which affect its size may only be performed by:
a. the owning function or
b. strictly inlined methods that are called by the function or
c. other functions where the mutation is the last thing the function does.
If the compiler can be certain that those conditions are met, then the memory holding the variable can be guaranteed to be the top of the stack, and it could be always be resized into contiguous memory.
Has anything similar to this been discussed anywhere? I would be interested to read about it more.