Skip to content

Commit 0a7c946

Browse files
authored
Fix method tables in Julia 1.12 (#2841)
1 parent 53f219b commit 0a7c946

File tree

2 files changed

+27
-22
lines changed

2 files changed

+27
-22
lines changed

src/runner/PlutoRunner/src/PlutoRunner.jl

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -807,28 +807,33 @@ function delete_toplevel_methods(f::Function, cell_id::UUID)::Bool
807807
end
808808
end
809809

810-
# if `f` is an extension to an external function, and we defined a method that overrides a method, for example,
811-
# we define `Base.isodd(n::Integer) = rand(Bool)`, which overrides the existing method `Base.isodd(n::Integer)`
812-
# calling `Base.delete_method` on this method won't bring back the old method, because our new method still exists in the method table, and it has a world age which is newer than the original. (our method has a deleted_world value set, which disables it)
813-
#
814-
# To solve this, we iterate again, and _re-enable any methods that were hidden in this way_, by adding them again to the method table with an even newer `primary_world`.
815-
if !isempty(deleted_sigs)
816-
to_insert = Method[]
817-
Base.visit(methods_table) do method
818-
if !isfromcell(method, cell_id) && method.sig deleted_sigs
819-
push!(to_insert, method)
810+
811+
if VERSION < v"1.12.0-0"
812+
# not necessary in Julia after https://github.com/JuliaLang/julia/pull/53415 💛
813+
814+
# if `f` is an extension to an external function, and we defined a method that overrides a method, for example,
815+
# we define `Base.isodd(n::Integer) = rand(Bool)`, which overrides the existing method `Base.isodd(n::Integer)`
816+
# calling `Base.delete_method` on this method won't bring back the old method, because our new method still exists in the method table, and it has a world age which is newer than the original. (our method has a deleted_world value set, which disables it)
817+
#
818+
# To solve this, we iterate again, and _re-enable any methods that were hidden in this way_, by adding them again to the method table with an even newer `primary_world`.
819+
if !isempty(deleted_sigs)
820+
to_insert = Method[]
821+
Base.visit(methods_table) do method
822+
if !isfromcell(method, cell_id) && method.sig deleted_sigs
823+
push!(to_insert, method)
824+
end
820825
end
821-
end
822-
# separate loop to avoid visiting the recently added method
823-
for method in Iterators.reverse(to_insert)
824-
if VERSION >= v"1.11.0-0"
825-
@atomic method.primary_world = one(typeof(alive_world_val)) # `1` will tell Julia to increment the world counter and set it as this function's world
826-
@atomic method.deleted_world = alive_world_val # set the `deleted_world` property back to the 'alive' value (for Julia v1.6 and up)
827-
else
828-
method.primary_world = one(typeof(alive_world_val))
829-
method.deleted_world = alive_world_val
826+
# separate loop to avoid visiting the recently added method
827+
for method in Iterators.reverse(to_insert)
828+
if VERSION >= v"1.11.0-0"
829+
@atomic method.primary_world = one(typeof(alive_world_val)) # `1` will tell Julia to increment the world counter and set it as this function's world
830+
@atomic method.deleted_world = alive_world_val # set the `deleted_world` property back to the 'alive' value (for Julia v1.6 and up)
831+
else
832+
method.primary_world = one(typeof(alive_world_val))
833+
method.deleted_world = alive_world_val
834+
end
835+
ccall(:jl_method_table_insert, Cvoid, (Any, Any, Ptr{Cvoid}), methods_table, method, C_NULL) # i dont like doing this either!
830836
end
831-
ccall(:jl_method_table_insert, Cvoid, (Any, Any, Ptr{Cvoid}), methods_table, method, C_NULL) # i dont like doing this either!
832837
end
833838
end
834839
return !isempty(methods(f).ms)

test/runtests.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ end
1212
verify_no_running_processes()
1313
@timeit_include("Configuration.jl")
1414
verify_no_running_processes()
15-
@timeit_include("packages/Basic.jl")
15+
@timeit_include("React.jl")
1616
verify_no_running_processes()
1717
@timeit_include("Bonds.jl")
1818
verify_no_running_processes()
1919
@timeit_include("RichOutput.jl")
2020
verify_no_running_processes()
21-
@timeit_include("React.jl")
21+
@timeit_include("packages/Basic.jl")
2222
verify_no_running_processes()
2323
@timeit_include("Dynamic.jl")
2424
verify_no_running_processes()

0 commit comments

Comments
 (0)