Skip to content

Commit d543c23

Browse files
committed
add_thunk: Skip domination check in register_future
1 parent c17b86d commit d543c23

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

src/sch/dynamic.jl

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ function dynamic_listener!(ctx, state, wid)
8282
println(iob)
8383
seek(iob.io, 0)
8484
write(stderr, iob)
85+
println(stderr, res)
8586
end
8687
end
8788
end
@@ -119,13 +120,17 @@ end
119120
"Waits on a thunk to complete, and fetches its result."
120121
function Base.fetch(h::SchedulerHandle, id::ThunkID)
121122
future = ThunkFuture(Future(1))
122-
exec!(_register_future!, h, future, id)
123+
exec!(_register_future!, h, future, id, true)
123124
fetch(future; proc=thunk_processor())
124125
end
125-
"Waits on a thunk to complete, and fetches its result."
126-
register_future!(h::SchedulerHandle, id::ThunkID, future::ThunkFuture) =
127-
exec!(_register_future!, h, future, id)
128-
function _register_future!(ctx, state, task, tid, (future, id)::Tuple{ThunkFuture,ThunkID})
126+
"""
127+
Waits on a thunk to complete, and fetches its result. If `check` is set to
128+
`true` (the default), then a domination check will occur to ensure that the
129+
future isn't being registered on a thunk dominated by the calling thunk.
130+
"""
131+
register_future!(h::SchedulerHandle, id::ThunkID, future::ThunkFuture, check::Bool=true) =
132+
exec!(_register_future!, h, future, id, check)
133+
function _register_future!(ctx, state, task, tid, (future, id, check)::Tuple{ThunkFuture,ThunkID,Bool})
129134
tid != id.id || throw(DynamicThunkException("Cannot fetch own result"))
130135
GC.@preserve id begin
131136
thunk = unwrap_weak_checked(state.thunk_dict[id.id])
@@ -150,7 +155,9 @@ function _register_future!(ctx, state, task, tid, (future, id)::Tuple{ThunkFutur
150155
end
151156
return false
152157
end
153-
!dominates(ownthunk, thunk) || throw(DynamicThunkException("Cannot fetch result of dominated thunk"))
158+
if check && dominates(ownthunk, thunk)
159+
throw(DynamicThunkException("Cannot fetch result of dominated thunk"))
160+
end
154161
# TODO: Assert that future will be fulfilled
155162
if haskey(state.cache, thunk)
156163
put!(future, state.cache[thunk]; error=state.errored[thunk])
@@ -202,7 +209,7 @@ function _add_thunk!(ctx, state, task, tid, (f, args, kwargs, future, ref))
202209
reschedule_inputs!(state, thunk)
203210
if future !== nothing
204211
# Ensure we attach a future before the thunk is scheduled
205-
_register_future!(ctx, state, task, tid, (future, thunk_id))
212+
_register_future!(ctx, state, task, tid, (future, thunk_id, false))
206213
end
207214
if ref !== nothing
208215
# Preserve the `EagerThunkFinalizer` through `thunk`

0 commit comments

Comments
 (0)