From d0f3a386d76cc447e886fed587d5b229fd06d2dc Mon Sep 17 00:00:00 2001 From: Frames White Date: Wed, 29 Mar 2023 11:43:46 +0800 Subject: [PATCH 1/5] Make identity op on julia v1.10 --- Project.toml | 4 ++-- README.md | 8 +++++++ src/Tricks.jl | 56 ++++++++++++++++++++++++++++++++---------------- test/runtests.jl | 4 +++- 4 files changed, 50 insertions(+), 22 deletions(-) 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..8bd3faf 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 | +| as the features of running `methods` etc 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..017885f 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -189,7 +189,9 @@ 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) + + # Our post-v1.10 solution actually does have a call, but it is ok + VERSION < v"1.10.0-DEV.609" && @test has_no_calls(code_typed[1].code) @testset "delete method" begin i(::Int) = 1 From 1905541eb3c2f6b6e54c89e4e324c5c0bcacb62c Mon Sep 17 00:00:00 2001 From: Frames White Date: Wed, 29 Mar 2023 11:51:36 +0800 Subject: [PATCH 2/5] Wording in readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8bd3faf..46e4525 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,8 @@ | ⚠️ Notice ⚠️ | | --- | -| **Tricks.jl is not required post-Julia v1.10.0-DEV.609 | -| as the features of running `methods` etc at compile-time are now built into the language. | +| **Tricks.jl is not required post-Julia v1.10.0-DEV.609. | +|The features of running `methods` etc at compile-time are now built into the language. | | It can still be used for compatibility with older versions of the language. | From 7f5a92feec3626272e80560d0aab0a9c21787265 Mon Sep 17 00:00:00 2001 From: Frames White Date: Wed, 29 Mar 2023 11:53:31 +0800 Subject: [PATCH 3/5] Make Ngihtly CI not cron, so it doesn't time out --- .github/workflows/JuliaNightly.yml | 2 -- 1 file changed, 2 deletions(-) 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: From d7102dc9d16fd4ff3e5118e15f04b7471d545e52 Mon Sep 17 00:00:00 2001 From: Frames White Date: Wed, 29 Mar 2023 11:57:54 +0800 Subject: [PATCH 4/5] mark static_methodcount as broken on Julia 1.10 --- test/runtests.jl | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 017885f..d83f382 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -190,8 +190,12 @@ VERSION >= v"1.3" && @testset "static_method_count" begin code_typed = (@code_typed static_method_count(f)) @test code_typed[2] === Int # return type - # Our post-v1.10 solution actually does have a call, but it is ok - VERSION < v"1.10.0-DEV.609" && @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 From 3bb42aa0767300617c28f0bdd89aebc258a5587d Mon Sep 17 00:00:00 2001 From: Frames White Date: Wed, 29 Mar 2023 12:02:16 +0800 Subject: [PATCH 5/5] fix readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 46e4525..2f82642 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,8 @@ | ⚠️ Notice ⚠️ | | --- | -| **Tricks.jl is not required post-Julia v1.10.0-DEV.609. | -|The features of running `methods` etc at compile-time are now built into the language. | +| **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. |