Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically insert lifetimes #7

Open
MilesCranmer opened this issue Jan 20, 2025 · 0 comments
Open

Automatically insert lifetimes #7

MilesCranmer opened this issue Jan 20, 2025 · 0 comments

Comments

@MilesCranmer
Copy link
Owner

MilesCranmer commented Jan 20, 2025

Using https://docs.julialang.org/en/v1.12-dev/devdocs/EscapeAnalysis/ it might be possible to avoid the explicit @lifetime scope and instead have lifetimes get inserted by the compiler automatically.

e.g.,

@do_magic function foo(x::Array, y)
    @own :mut x y

    @ref rx = x
    @own result = my_sum(rx)
    
    push!(x, result)
end

You would want it to generate this:

function foo(x::Array, y)
    @own :mut x y

    lt1 = Lifetime()
    @ref ~lt1 rx = x
    @own result = my_sum(rx)
    cleanup!(lt1)
    
    push!(x, result)
end

based on detecting that rx is last used at the line my_sum(rx). However, I'm not sure if EscapeAnalysis is smart enough to figure this out or not?

@MasonProtter interested in your thoughts.

If we figure this out, we could even allow for @ref x which could be really nice. Then it's basically the same as &x in Rust.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant