Hacker News new | ask | show | jobs
by brundolf 1897 days ago
What I actually had in mind was Rust. Broadly speaking Rust requires all stack-allocated values to be sized at compile time. Also, thanks to borrow-checking, code is encouraged to stay fairly stack-oriented, so at least I personally end up with lots of function-local data structures that get passed by reference down to other logic. So I think "pointless" is overstating it.

However, the bigger question wasn't about the size limit but about being runtime-dynamic. Why can't a function's argument have a dynamic size, and the stack frame just allocates the needed space at call-time? Even if we're not talking about large structures, this would be useful for things like (for example) ad-hoc union types (as opposed to enums, where all variants have to be known at compile time and are packed into a single bit-width regardless of the value). Maybe you could even get rid of some of the code-duplication that happens when generic functions get reified.

I assume there's a good reason, I just don't see what it is.

1 comments

Let's look at this question from the compiler's point of view : What will be the assembly sequence are you going to generate for that dynamic-sized-argument runtime behavior?

For compiled languages it is handled with calling convention, and most architectures (ARM, PPC, RISC-V, ...) have register-based calling convention. Only when all the argument registers are consumed, the function call pass the rest arguments on the stack.