Skip to content

Commit

Permalink
Merge pull request #42 from Drvi/td-try-fix-7
Browse files Browse the repository at this point in the history
Don't add an edge to `Tuple` to the method tables
  • Loading branch information
oxinabox authored Jul 26, 2024
2 parents e97f0c8 + 125f4be commit ac53de4
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Tricks"
uuid = "410a4b4d-49e4-4fbc-ab6d-cb71b17b3775"
authors = ["Frames White"]
version = "0.1.8"
version = "0.1.9"

[compat]
julia = "1.0"
Expand Down
2 changes: 1 addition & 1 deletion src/Tricks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function _method_table_all_edges_all_methods(f, T, world = Base.get_world_counte

# We add an edge to the MethodTable itself so that when any new methods
# are defined, it recompiles the function.
mt_edges = Core.Compiler.vect(mt, Tuple{Vararg{Any}})
mt_edges = Core.Compiler.vect(mt, Tuple{f,Vararg{Any}})

# We want to add an edge to _every existing method instance_, so that
# the deletion of any one of them will trigger recompilation of the function.
Expand Down
28 changes: 28 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,34 @@ VERSION >= v"1.3" && @testset "static_method_count" begin
i(x) = x+1
@test static_method_count(i) == 1
end

@testset "parametric struct" begin
struct Baz{T}; x::T end
@test static_method_count(Baz) == 1
@test static_method_count(Baz{Int}) == 1
@test static_method_count(Baz{Tuple}) == 1


Baz(x::Int) = Baz(x)
@test static_method_count(Baz) == 2
Baz{Float64}(x::Int, y::Int) = Baz(x/y)
@test static_method_count(Baz{Float64}) == 2

Base.delete_method((first methods)(Baz))
@test static_method_count(Baz) == 1
Base.delete_method((first methods)(Baz{Float64}))
@test static_method_count(Baz{Float64}) == 1

Base.delete_method((first methods)(Baz))
@test static_method_count(Baz) == 0
Base.delete_method((first methods)(Baz{Float64}))
@test static_method_count(Baz{Float64}) == 0

Baz(x::Int) = Baz(x)
@test static_method_count(Baz) == 1
Baz{Float64}(x::Int, y::Int) = Baz(x/y)
@test static_method_count(Baz{Float64}) == 1
end
end

VERSION >= v"1.3" && @testset "closures" begin
Expand Down

2 comments on commit ac53de4

@oxinabox
Copy link
Owner Author

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/111812

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.9 -m "<description of version>" ac53de4140df739dd498e76af2f6a15f940d95e2
git push origin v0.1.9

Please sign in to comment.