Skip to content

Deleted method doesn't recompile on first call if called inside block with Base.delete_method in v1.12 #57020

New issue

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

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

Already on GitHub? # to your account

Closed
chengchingwen opened this issue Jan 12, 2025 · 3 comments

Comments

@chengchingwen
Copy link
Member

This was noticed in oxinabox/Tricks.jl#44 that the generated function does not correctly recompile if Base.delete_method and function call happened in a block, but it seems to be a regression on v1.12 without generated function. Here is a MWE:

on v1.10-v1.11:

julia> foo(x) = "1"
foo (generic function with 1 method)

julia> foo(::Int) = "2"
foo (generic function with 2 methods)

julia> foo(1)
"2"

julia> begin
           Base.delete_method(first(methods(foo)))
           @show foo(1)
       end
foo(1) = "1"
"1"

but on v1.12 (1.12.0-DEV.1869 (2025-01-10) Commit d3964b600a5):

julia> foo(x) = "1"
foo (generic function with 1 method)

julia> foo(::Int) = "2"
foo (generic function with 2 methods)

julia> foo(1)
"2"

julia> begin
           Base.delete_method(first(methods(foo)))
           @show length(methods(foo))
           @show foo(1)
           @show foo(1)
       end
length(methods(foo)) = 1
foo(1) = "2"
foo(1) = "2"
"2"

julia> foo(1)
"1"

However, the new behavior seems to match the behavior on all versions if you put the block inside a function. I'm not sure if it's an intended result.

@maleadt
Copy link
Member

maleadt commented Jan 12, 2025

This was changed by #56509 (cc @Keno).

@Keno
Copy link
Member

Keno commented Jan 12, 2025

The behavior is intentional. Your can insert and explicit latest world Expr to force the world age increment

@chengchingwen
Copy link
Member Author

Adding Core.@latestworld after Base.delete_method resolves the issue. Thanks!

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

No branches or pull requests

3 participants