From e4b98d3f2e6a7f9d38e55d018bb2a63d806436e9 Mon Sep 17 00:00:00 2001 From: Carlo Lucibello Date: Mon, 4 Nov 2024 10:18:34 +0100 Subject: [PATCH] bump version --- Project.toml | 6 ++--- src/cache.jl | 59 +++++++++++++++----------------------------------- src/functor.jl | 10 --------- test/base.jl | 4 ++-- 4 files changed, 22 insertions(+), 57 deletions(-) diff --git a/Project.toml b/Project.toml index 9b67af5..63eecba 100644 --- a/Project.toml +++ b/Project.toml @@ -1,23 +1,21 @@ name = "Functors" uuid = "d9f16b24-f501-4c13-a1f2-28368ffc5196" authors = ["Mike J Innes "] -version = "0.4.12" +version = "0.5.0" [deps] Compat = "34da2185-b29b-5c13-b0c7-acf172513d20" ConstructionBase = "187b0558-2788-49d3-abe0-74a17ed4e7c9" -LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" [compat] Compat = "4.16" ConstructionBase = "1.4" -LaTeXStrings = "1.4.0" Measurements = "2" OrderedCollections = "1.6" Random = "1" -julia = "1.6" +julia = "1.10" [extras] Measurements = "eff96d63-e80a-5855-80a2-b1b0885c5ab7" diff --git a/src/cache.jl b/src/cache.jl index a4af472..76184fb 100644 --- a/src/cache.jl +++ b/src/cache.jl @@ -11,48 +11,25 @@ Base.iterate(cache::WalkCache, state...) = iterate(cache.cache, state...) Base.setindex!(cache::WalkCache, value, key) = setindex!(cache.cache, value, key) Base.getindex(cache::WalkCache, x) = cache.cache[x] -@static if VERSION >= v"1.10.0-DEV.609" - function __cacheget_generator__(world, source, self, cache, x, args #= for `return_type` only =#) - # :(return cache.cache[x]::(return_type(cache.walk, typeof(args)))) - walk = cache.parameters[3] - RT = Core.Compiler.return_type(Tuple{walk, args...}, world) - body = Expr(:call, GlobalRef(Base, :getindex), Expr(:., :cache, QuoteNode(:cache)), :x) - if RT != Any - body = Expr(:(::), body, RT) - end - expr = Expr(:lambda, [Symbol("#self#"), :cache, :x, :args], - Expr(Symbol("scope-block"), Expr(:block, Expr(:meta, :inline), Expr(:return, body)))) - ci = ccall(:jl_expand, Any, (Any, Any), expr, @__MODULE__) - ci.inlineable = true - return ci - end - @eval function cacheget(cache::WalkCache, x, args...) - $(Expr(:meta, :generated, __cacheget_generator__)) - $(Expr(:meta, :generated_only)) - end -else - @generated function cacheget(cache::WalkCache, x, args...) - walk = cache.parameters[3] - world = typemax(UInt) - @static if VERSION >= v"1.8" - RT = Core.Compiler.return_type(Tuple{walk, args...}, world) - else - if isdefined(walk, :instance) - RT = Core.Compiler.return_type(walk.instance, Tuple{args...}, world) - else - RT = Any - end - end - body = Expr(:call, GlobalRef(Base, :getindex), Expr(:., :cache, QuoteNode(:cache)), :x) - if RT != Any - body = Expr(:(::), body, RT) - end - expr = Expr(:lambda, [Symbol("#self#"), :cache, :x, :args], - Expr(Symbol("scope-block"), Expr(:block, Expr(:meta, :inline), Expr(:return, body)))) - ci = ccall(:jl_expand, Any, (Any, Any), expr, @__MODULE__) - ci.inlineable = true - return ci +function __cacheget_generator__(world, source, self, cache, x, args #= for `return_type` only =#) + # :(return cache.cache[x]::(return_type(cache.walk, typeof(args)))) + walk = cache.parameters[3] + RT = Core.Compiler.return_type(Tuple{walk, args...}, world) + body = Expr(:call, GlobalRef(Base, :getindex), Expr(:., :cache, QuoteNode(:cache)), :x) + if RT != Any + body = Expr(:(::), body, RT) end + expr = Expr(:lambda, [Symbol("#self#"), :cache, :x, :args], + Expr(Symbol("scope-block"), Expr(:block, Expr(:meta, :inline), Expr(:return, body)))) + ci = ccall(:jl_expand, Any, (Any, Any), expr, @__MODULE__) + ci.inlineable = true + return ci end + +@eval function cacheget(cache::WalkCache, x, args...) + $(Expr(:meta, :generated, __cacheget_generator__)) + $(Expr(:meta, :generated_only)) +end + # fallback behavior that only lookup for `x` @inline cacheget(cache::AbstractDict, x, args...) = cache[x] diff --git a/src/functor.jl b/src/functor.jl index a770652..b63e75f 100644 --- a/src/functor.jl +++ b/src/functor.jl @@ -85,13 +85,3 @@ end macro flexiblefunctor(args...) flexiblefunctorm(args...) end - -### -### Compat -### - -if VERSION < v"1.7" - # Function in 1.7 checks t.name.flags & 0x2 == 0x2, - # but for 1.6 this seems to work instead: - ismutabletype(@nospecialize t) = t.mutable -end diff --git a/test/base.jl b/test/base.jl index 2997b84..e4b1701 100644 --- a/test/base.jl +++ b/test/base.jl @@ -57,13 +57,13 @@ end @test fmap(x -> x + 10, bf) == Base.Broadcast.BroadcastFunction(Bar(13.3)) end -VERSION >= v"1.7" && @testset "Returns" begin +@testset "Returns" begin ret = Returns([0, pi, 2pi]) @test Functors.functor(ret)[1] == (value = [0, pi, 2pi],) @test Functors.functor(ret)[2]((value = 1:3,)) === Returns(1:3) end -VERSION >= v"1.9" && @testset "Splat" begin +@testset "Splat" begin ret = Base.splat(Returns([0, pi, 2pi])) @test Functors.functor(ret)[1].f.value == [0, pi, 2pi] @test Functors.functor(ret)[2]((f = sin,)) === Base.splat(sin)