Skip to content

Commit

Permalink
bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
CarloLucibello committed Nov 4, 2024
1 parent 3af3482 commit e4b98d3
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 57 deletions.
6 changes: 2 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
name = "Functors"
uuid = "d9f16b24-f501-4c13-a1f2-28368ffc5196"
authors = ["Mike J Innes <[email protected]>"]
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"
Expand Down
59 changes: 18 additions & 41 deletions src/cache.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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]
10 changes: 0 additions & 10 deletions src/functor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions test/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit e4b98d3

Please sign in to comment.