umka-lang icon indicating copy to clipboard operation
umka-lang copied to clipboard

Weird escape analysis

Open vtereshkov opened this issue 2 years ago • 2 comments

A temporary "reference holder" variable that stores a function result may be attached to a reference cycle and therefore never freed.

type T = struct {
        next: ^T
}

fn foo(n: T): T {
        n.next = &n
        return n
}

fn bar() {
        foo(T{})
}                      // Runtime error: Pointer to a local variable escapes from the function

fn main() {
        bar()
}

vtereshkov avatar Nov 12 '23 22:11 vtereshkov

Isn't this related to #200

ske2004 avatar Feb 18 '24 00:02 ske2004

@skejeton I think you mean #199. Yes, it's related, but not the same. There are many ways to produce a reference cycle involving a local variable. What distinguishes the current issue is that a user cannot even see this variable.

vtereshkov avatar Feb 18 '24 00:02 vtereshkov