A programming language idea: no static code, explicit caller context (Kite)
H. S. Teoh
hsteoh at qfbox.info
Sat May 2 14:11:07 UTC 2026
On Sat, May 02, 2026 at 01:42:11PM +0000, Marconi via Digitalmars-d wrote:
> ```c
[...]
> void add(int v) {
> node n;
> // n is created here
> // if it does NOT escape this scope → stack
> // if it escapes (like below) → heap via owner.on_heap()
>
> n.value = v;
>
> // n escapes here because it's stored in a field
> // compiler promotes it to heap
> // owner.on_heap(...) is called internally
> n.next = head;
> head = n;
> }
[...]
Wow, this makes code incredibly hard to follow. Instead of being like
C, where you know everything must be manually freed, or a GC language
where you know everything is automatically cleaned up, here you have to
carefully read through every line of a function just to determine
whether an object was allocated on the stack or on the heap. The
declaration doesn't help because the declared type does not
differentiate between stack or heap allocation.
Not only so, the caller has to know this in order to know whether or not
it needs to deallocate the object. Meaning that to determine whether
the caller has a memory leak, you need to recursively scan every callee
and keep track of whether something was allocated on the stack or heap.
For every single object declaration. And this has to be done for *every
single caller*. And good luck if you're calling a 3rd party library
function for which you have no access to source code.
I can already see from a mile away that this is going to be a major
source of bugs.
T
--
"Do you know what's the price of a chimney?"
"Let me guess: nothing, because it's on the house."
"No, on the contrary, it's through the roof!"
More information about the Digitalmars-d
mailing list