From 8db6c3a928f4698ccfbce4953cbc74f6d35b60d1 Mon Sep 17 00:00:00 2001 From: Rik Huijzer Date: Wed, 16 Feb 2022 15:48:30 +0100 Subject: [PATCH] Fix non-concrete type near TRCache (#118) * Fix non-concrete type near TRCache * Add `@inferred` test * Bump version to 0.6.8 --- Project.toml | 2 +- src/tapedfunction.jl | 8 ++++---- src/tapedtask.jl | 2 +- test/ctask.jl | 2 ++ 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Project.toml b/Project.toml index e0bdc1b9..4ea2e86c 100644 --- a/Project.toml +++ b/Project.toml @@ -3,7 +3,7 @@ uuid = "6f1fad26-d15e-5dc8-ae53-837a1d7b8c9f" license = "MIT" desc = "Tape based task copying in Turing" repo = "https://github.com/TuringLang/Libtask.jl.git" -version = "0.6.7" +version = "0.6.8" [deps] IRTools = "7869d1d1-7146-5819-86e3-90919afe41df" diff --git a/src/tapedfunction.jl b/src/tapedfunction.jl index 3ff032ca..ea5ea13c 100644 --- a/src/tapedfunction.jl +++ b/src/tapedfunction.jl @@ -36,10 +36,8 @@ mutable struct ReturnInstruction{TA, T<:Taped} <: AbstractInstruction tape::T end -const TRCache = LRU{Any, Any}(maxsize=10) - mutable struct TapedFunction{F} <: Taped - func::F # maybe a function, a constructor, or a callable obejct + func::F # maybe a function, a constructor, or a callable object arity::Int ir::IRTools.IR tape::RawTape @@ -53,7 +51,7 @@ mutable struct TapedFunction{F} <: Taped cache_key = (f, typeof.(args)...) if cache && haskey(TRCache, cache_key) # use cache - cached_tf = TRCache[cache_key] + cached_tf = TRCache[cache_key]::TapedFunction{F} tf = copy(cached_tf) tf.counter = 1 return tf @@ -77,6 +75,8 @@ mutable struct TapedFunction{F} <: Taped end end +const TRCache = LRU{Tuple, TapedFunction}(maxsize=10) + ## methods for Box val(x) = x val(x::Box) = x.val diff --git a/src/tapedtask.jl b/src/tapedtask.jl index e1e387a9..fca577cc 100644 --- a/src/tapedtask.jl +++ b/src/tapedtask.jl @@ -1,6 +1,6 @@ struct TapedTaskException exc::Exception - backtrace + backtrace::Vector{Any} end struct TapedTask diff --git a/test/ctask.jl b/test/ctask.jl index 625b1b01..cb85908c 100644 --- a/test/ctask.jl +++ b/test/ctask.jl @@ -17,6 +17,8 @@ @test consume(a) == 3 @test consume(ctask) == 2 @test consume(ctask) == 3 + + @inferred Libtask.TapedFunction(f) end # Test case 2: heap allocated objects are shallowly copied.