From 04fe587d1be14f2c79b19607661de554b7250dca Mon Sep 17 00:00:00 2001 From: Drvi Date: Wed, 24 Jul 2024 09:43:50 +0200 Subject: [PATCH 1/4] Don't add an edge to `Tuple` to the method tables --- src/Tricks.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Tricks.jl b/src/Tricks.jl index 2f7fff1..0cd8749 100644 --- a/src/Tricks.jl +++ b/src/Tricks.jl @@ -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. From ebd521207b3f407c84422cc5c0f05775d7fc8c22 Mon Sep 17 00:00:00 2001 From: Drvi Date: Wed, 24 Jul 2024 12:28:10 +0200 Subject: [PATCH 2/4] Add more tests --- test/runtests.jl | 66 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/test/runtests.jl b/test/runtests.jl index faae174..2856b92 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -206,6 +206,72 @@ 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 + + @testset "Tuple" begin + # julia> methods(Base.Tuple) + # # 6 methods for type constructor: + # [1] Tuple(index::CartesianIndex) + # @ Base.IteratorsMD multidimensional.jl:103 + # [2] Tuple(nt::NamedTuple) + # @ Base namedtuple.jl:197 + # [3] Tuple(x::Array{T, 0}) where T + # @ Base tuple.jl:389 + # [4] Tuple(x::Ref) + # @ Base tuple.jl:388 + # [5] (::Type{T})(x::Tuple) where T<:Tuple + # @ Base tuple.jl:386 + # [6] (::Type{T})(itr) where T<:Tuple + # @ Base tuple.jl:391 + default_method_count = static_method_count(Base.Tuple) + Base.Tuple(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z) = 1 + # julia> methods(Base.Tuple) + # # 8 methods for type constructor: + # [1] Tuple(index::CartesianIndex) + # @ Base.IteratorsMD multidimensional.jl:103 + # [2] Tuple(x::Array{T, 0}) where T + # @ Base tuple.jl:389 + # [3] Tuple(x::Ref) + # @ Base tuple.jl:388 + # [4] (::Type{T})(x::Tuple) where T<:Tuple + # @ Base tuple.jl:386 + # [5] Tuple(nt::NamedTuple) + # @ Base namedtuple.jl:197 + # [6] (::Type{T})(nt::NamedTuple) where T<:Tuple + # @ Base namedtuple.jl:198 + # [7] Tuple(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z) + # @ Main REPL[5]:1 + # [8] (::Type{T})(itr) where T<:Tuple + # @ Base tuple.jl:391 + @test static_method_count(Base.Tuple) == default_method_count + 2 + end end VERSION >= v"1.3" && @testset "closures" begin From a63abf679c60a0dc7379844a8cfbd34dd8341156 Mon Sep 17 00:00:00 2001 From: Drvi Date: Wed, 24 Jul 2024 15:33:51 +0200 Subject: [PATCH 3/4] . --- test/runtests.jl | 38 -------------------------------------- 1 file changed, 38 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 2856b92..3b1e384 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -234,44 +234,6 @@ VERSION >= v"1.3" && @testset "static_method_count" begin Baz{Float64}(x::Int, y::Int) = Baz(x/y) @test static_method_count(Baz{Float64}) == 1 end - - @testset "Tuple" begin - # julia> methods(Base.Tuple) - # # 6 methods for type constructor: - # [1] Tuple(index::CartesianIndex) - # @ Base.IteratorsMD multidimensional.jl:103 - # [2] Tuple(nt::NamedTuple) - # @ Base namedtuple.jl:197 - # [3] Tuple(x::Array{T, 0}) where T - # @ Base tuple.jl:389 - # [4] Tuple(x::Ref) - # @ Base tuple.jl:388 - # [5] (::Type{T})(x::Tuple) where T<:Tuple - # @ Base tuple.jl:386 - # [6] (::Type{T})(itr) where T<:Tuple - # @ Base tuple.jl:391 - default_method_count = static_method_count(Base.Tuple) - Base.Tuple(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z) = 1 - # julia> methods(Base.Tuple) - # # 8 methods for type constructor: - # [1] Tuple(index::CartesianIndex) - # @ Base.IteratorsMD multidimensional.jl:103 - # [2] Tuple(x::Array{T, 0}) where T - # @ Base tuple.jl:389 - # [3] Tuple(x::Ref) - # @ Base tuple.jl:388 - # [4] (::Type{T})(x::Tuple) where T<:Tuple - # @ Base tuple.jl:386 - # [5] Tuple(nt::NamedTuple) - # @ Base namedtuple.jl:197 - # [6] (::Type{T})(nt::NamedTuple) where T<:Tuple - # @ Base namedtuple.jl:198 - # [7] Tuple(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z) - # @ Main REPL[5]:1 - # [8] (::Type{T})(itr) where T<:Tuple - # @ Base tuple.jl:391 - @test static_method_count(Base.Tuple) == default_method_count + 2 - end end VERSION >= v"1.3" && @testset "closures" begin From 125f4bedd9ad18ee16465b6e16f55e90effcbdac Mon Sep 17 00:00:00 2001 From: Drvi Date: Wed, 24 Jul 2024 15:34:05 +0200 Subject: [PATCH 4/4] v0.1.9 --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index c6aba78..96d1858 100644 --- a/Project.toml +++ b/Project.toml @@ -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"