It seems to me that @notriddle’s example could work without being statically specialized, because the length is an input parameter — its binder is inside the angle brackets instead of the parentheses, and the compiler might be able to do term inference for it at the call site instead of needing it specified explicitly, but either way it’s supplied by the caller to the callee, which means that the caller can also supply enough space for the return value.
Another thing — which I realized while trying to write that out with hypothetical dependent types and then decided that just made it more confusing, not less — is that this is weaker than alloca: even if the compiler doesn’t emit specialized code, it could (I think?) still do enough monomorphization to statically reason about the set of possible values of each type-level integer. For example, it should be able to detemine the maximum possible size of each non-constant alloca it emits.
That might help somewhat with the reason I’ve seen for avoiding alloca and variable-length arrays in C, which is that they’re unsafe and a known security hazard if the length is untrusted (assuming the implementation doesn’t check for stack overflow and arithmetic / address space overflow).
All that said, I wonder if there are cases where the programmer would specifically want specialization — e.g., to allow loop unrolling, or avoid expensive operations like division by a non-immediate.