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

WIP: support finalizers in trimming #58014

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

JeffBezanson
Copy link
Member

This is sufficient to get finalizers working. Before merging this though I propose generalizing it by adding a new builtin calledge (or something) that we'd use like so:

function finalizer(@nospecialize(f), @nospecialize(o))
    _check_mutable(o)
    Core.finalizer(f, o)
    calledge(Tuple{typeof(f), typeof(o)})
    return o
end

function Core.Task(@nospecialize(f), reserved_stack::Int=0)
    calledge(Tuple{typeof(f)})
    Core._Task(f, reserved_stack, ThreadSynchronizer())
end

which says that if a call to finalizer is reachable, then so is f(o) etc. The implementation would be basically identical to what's here currently.

topolarity and others added 2 commits April 3, 2025 17:43
This adds the changes required to guess the MethodInstance that the
runtime will eventually invoke for this call, enqueue it for codegen,
and then verify its presence in the verifier.
@JeffBezanson JeffBezanson added the trimming Issues with trimming functionality or PR's relevant to its performance/functionality label Apr 4, 2025
@vtjnash vtjnash marked this pull request as draft April 4, 2025 20:07
Comment on lines +1308 to +1310
ci = typeinf_ext(interp, mi, SOURCE_MODE_GET_SOURCE)
# TODO: separate workqueue for NativeInterpreter
ci isa CodeInstance && push!(wq, ci)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs re-work. We need to at least check that we're not re-inserting an mi to the workqueue or else we can infinite loop because we'll get a fresh ci and continually re-insert a recursive finalizer

Jameson suggested a re-factor of the workqueue to accommodate this, which I've started on but it's not done just yet

@topolarity
Copy link
Member

adding a new builtin calledge (or something) that we'd use like so

I was thinking perhaps Core._predeclare_call(foo, a, b)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
trimming Issues with trimming functionality or PR's relevant to its performance/functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants