Skip to content

Commit 97e69ed

Browse files
committed
Remove addreference!
1 parent f863a7d commit 97e69ed

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

ext/AdvancedPSLibtaskExt.jl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ end
4949

5050
const LibtaskTrace{R} = AdvancedPS.Trace{<:AdvancedPS.LibtaskModel,R}
5151

52+
function Base.copy(trace::LibtaskTrace)
53+
newtrace = AdvancedPS.Trace(copy(trace.model), deepcopy(trace.rng))
54+
set_other_global!(newtrace, newtrace)
55+
return newtrace
56+
end
57+
5258
"""Get the RNG from a `LibtaskTrace`."""
5359
function get_rng(trace::LibtaskTrace)
5460
return trace.model.ctask.taped_globals.rng
@@ -75,7 +81,11 @@ get_other_global(trace::LibtaskTrace) = trace.model.ctask.taped_globals.other
7581
function AdvancedPS.Trace(
7682
model::AdvancedPS.AbstractGenericModel, rng::Random.AbstractRNG, args...
7783
)
78-
return AdvancedPS.Trace(AdvancedPS.LibtaskModel(model, rng, args...), rng)
84+
trace = AdvancedPS.Trace(AdvancedPS.LibtaskModel(model, rng, args...), rng)
85+
# Set a backreference so that the TapedTask in `trace` stores the `trace` itself in its
86+
# taped globals.
87+
set_other_global!(trace, trace)
88+
return trace
7989
end
8090

8191
# step to the next observe statement and
@@ -88,22 +98,12 @@ function AdvancedPS.advance!(trace::LibtaskTrace, isref::Bool=false)
8898
return Libtask.consume(trace.model.ctask)
8999
end
90100

91-
"""
92-
Set a backreference so that the TapedTask in `trace` stores the `trace` itself in the
93-
taped globals.
94-
"""
95-
function AdvancedPS.addreference!(trace::LibtaskTrace)
96-
set_other_global!(trace, trace)
97-
return trace
98-
end
99-
100101
# Task copying version of fork for Trace.
101102
function AdvancedPS.fork(trace::LibtaskTrace, isref::Bool=false)
102103
newtrace = copy(trace)
103104
set_rng!(newtrace, deepcopy(get_rng(newtrace)))
104105
isref && AdvancedPS.delete_retained!(newtrace.model.f)
105106
isref && delete_seeds!(newtrace)
106-
AdvancedPS.addreference!(newtrace)
107107
return newtrace
108108
end
109109

src/model.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ end
6262
# in an extension, we just define dummy in the main module and implement them in the extension.
6363
function observe end
6464
function replay end
65-
function addreference! end
6665

6766
# We need this one to be visible outside of the extension for dispatching (Turing.jl).
6867
struct LibtaskModel{F,T}

test/container.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@
159159
end
160160

161161
trace = AdvancedPS.Trace(TaskIdModel(), AdvancedPS.TracedRNG())
162-
AdvancedPS.addreference!(trace)
163162

164163
@test AdvancedPS.advance!(trace, false) === objectid(trace)
165164
end

0 commit comments

Comments
 (0)