diff --git a/.github/workflows/JuliaNightly.yml b/.github/workflows/JuliaNightly.yml index b570b2f..1fd7f5b 100644 --- a/.github/workflows/JuliaNightly.yml +++ b/.github/workflows/JuliaNightly.yml @@ -5,8 +5,6 @@ on: branches: [master] tags: [v*] pull_request: - schedule: - - cron: "0 0 * * *" jobs: test: diff --git a/Project.toml b/Project.toml index 5cf0fb2..a1c2634 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "Tricks" uuid = "410a4b4d-49e4-4fbc-ab6d-cb71b17b3775" -authors = ["Lyndon White"] -version = "0.1.6" +authors = ["Frames White"] +version = "0.1.7" [compat] julia = "1.0" diff --git a/README.md b/README.md index f0f1efb..2f82642 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,14 @@ --> [![Codecov](https://codecov.io/gh/oxinabox/Tricks.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/oxinabox/Tricks.jl) + +| ⚠️ Notice ⚠️ | +| --- | +| **Tricks.jl** is not required post-Julia v1.10.0-DEV.609. | +|The features of running `hasmethod` at compile-time are now built into the language. | +| It can still be used for compatibility with older versions of the language. | + + Tricks.jl is an particularly ~evil~ cunning package that does tricks with the Julia edge system. Currently it has the following tricks: diff --git a/src/Tricks.jl b/src/Tricks.jl index 7f83c29..a42e3b4 100644 --- a/src/Tricks.jl +++ b/src/Tricks.jl @@ -10,12 +10,8 @@ export static_hasmethod, static_methods, static_method_count, compat_hasmethod, _hasmethod_false(@nospecialize(f), @nospecialize(t)) = false _hasmethod_true(@nospecialize(f), @nospecialize(t)) = true -""" - static_hasmethod(f, type_tuple::Type{<:Tuple) -Like `hasmethod` but runs at compile-time (and does not accept a worldage argument). -""" -@generated function static_hasmethod(@nospecialize(f), @nospecialize(t::Type{T}),) where {T<:Tuple} +@generated function _static_hasmethod(@nospecialize(f), @nospecialize(t::Type{T}),) where {T<:Tuple} # The signature type: method_insts = _method_instances(f, T) @@ -39,7 +35,17 @@ Like `hasmethod` but runs at compile-time (and does not accept a worldage argume return ci end +""" + static_hasmethod(f, type_tuple::Type{<:Tuple) +Like `hasmethod` but runs at compile-time (and does not accept a worldage argument). +""" +const static_hasmethod = if VERSION >= v"1.10.0-DEV.609" + # Feature is now part of julia itself + hasmethod +else + _static_hasmethod +end function create_codeinfo_with_returnvalue(argnames, spnames, sp, value) expr = Expr(:lambda, @@ -63,14 +69,19 @@ end Like `methods` but runs at compile-time (and does not accept a worldage argument). """ -static_methods(@nospecialize(f)) = static_methods(f, Tuple{Vararg{Any}}) -@generated function static_methods(@nospecialize(f) , @nospecialize(_T::Type{T})) where {T <: Tuple} - list_of_methods = _methods(f, T) - ci = create_codeinfo_with_returnvalue([Symbol("#self#"), :f, :_T], [:T], (:T,), :($list_of_methods)) - - # Now we add the edges so if a method is defined this recompiles - ci.edges = _method_table_all_edges_all_methods(f, T) - return ci +const static_methods = if VERSION >= v"1.10.0-DEV.609" + # feature is now built in + methods +else + _static_methods(@nospecialize(f)) = static_methods(f, Tuple{Vararg{Any}}) + @generated function _static_methods(@nospecialize(f) , @nospecialize(_T::Type{T})) where {T <: Tuple} + list_of_methods = _methods(f, T) + ci = create_codeinfo_with_returnvalue([Symbol("#self#"), :f, :_T], [:T], (:T,), :($list_of_methods)) + + # Now we add the edges so if a method is defined this recompiles + ci.edges = _method_table_all_edges_all_methods(f, T) + return ci + end end function _method_table_all_edges_all_methods(f, T) @@ -95,13 +106,20 @@ end Returns `length(methods(f, tt))` but runs at compile-time (and does not accept a worldage argument). """ static_method_count(@nospecialize(f)) = static_method_count(f, Tuple{Vararg{Any}}) -@generated function static_method_count(@nospecialize(f) , @nospecialize(_T::Type{T})) where {T <: Tuple} - method_count = length(_methods(f, T)) - ci = create_codeinfo_with_returnvalue([Symbol("#self#"), :f, :_T], [:T], (:T,), :($method_count)) +if VERSION >= v"1.10.0-DEV.609" + # feature is now built in + function static_method_count(@nospecialize(f) , @nospecialize(_T::Type{T})) where {T <: Tuple} + return length(methods(f, _T)) + end +else + @generated function static_method_count(@nospecialize(f) , @nospecialize(_T::Type{T})) where {T <: Tuple} + method_count = length(_methods(f, T)) + ci = create_codeinfo_with_returnvalue([Symbol("#self#"), :f, :_T], [:T], (:T,), :($method_count)) - # Now we add the edges so if a method is defined this recompiles - ci.edges = _method_table_all_edges_all_methods(f, T) - return ci + # Now we add the edges so if a method is defined this recompiles + ci.edges = _method_table_all_edges_all_methods(f, T) + return ci + end end @static if VERSION < v"1.3" diff --git a/test/runtests.jl b/test/runtests.jl index faae174..d83f382 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -189,7 +189,13 @@ VERSION >= v"1.3" && @testset "static_method_count" begin # Code Generation code_typed = (@code_typed static_method_count(f)) @test code_typed[2] === Int # return type - @test has_no_calls(code_typed[1].code) + + if VERSION < v"1.10.0-DEV.609" + @test has_no_calls(code_typed[1].code) + else + # Actually does have calls on new version, because `methods` isn't constant folded right now + @test_broken has_no_calls(code_typed[1].code) + end @testset "delete method" begin i(::Int) = 1