Automatic insertion of malloc/free

Raul Duke wrote:

If the compiler could insert the malloc’s and free’s that a human does
in C, then that seems to just end up as reference counting? As much as
I like GC in some ways, I don’t utterly dislike e.g. ARC.

But the problem is that we don’t really know how a human does it in C.

You could have:

fun foo (list_vt(int)): void // freeing the argument
fun foo2 (!list_vt(int)): void // not freeing the argument

Both make perfect sense. If foo and foo2 have the same body of code, there
is really no way for the compiler to determine what the programmer really
needs: foo
or foo2?

I am not denying that there are special cases where automatic insertion of
malloc/free
can be done meaningfully. To me, handling these cases lies in the realm of
meta-programming.