Skip to content

Commit

Permalink
Fix non-concrete type near TRCache (#118)
Browse files Browse the repository at this point in the history
* Fix non-concrete type near TRCache

* Add `@inferred` test

* Bump version to 0.6.8
  • Loading branch information
rikhuijzer authored Feb 16, 2022
1 parent 340df34 commit 8db6c3a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions src/tapedfunction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/tapedtask.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
struct TapedTaskException
exc::Exception
backtrace
backtrace::Vector{Any}
end

struct TapedTask
Expand Down
2 changes: 2 additions & 0 deletions test/ctask.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

2 comments on commit 8db6c3a

@devmotion
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/54768

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.6.8 -m "<description of version>" 8db6c3a928f4698ccfbce4953cbc74f6d35b60d1
git push origin v0.6.8

Please sign in to comment.