Skip to content

Commit 35b83a4

Browse files
committed
record where thunks actually created
1 parent d829da4 commit 35b83a4

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/differentials.jl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,17 @@ struct Thunk{F} <: AbstractThunk
212212
f::F
213213
end
214214

215+
216+
"""
217+
@thunk expr
218+
219+
Define a [`Thunk`](@ref) wrapping the `expr`, to lazily defer its evaluation.
220+
"""
215221
macro thunk(body)
216-
return :(Thunk(() -> $(esc(body))))
222+
# Basically `:(Thunk(() -> $(esc(body))))` but use the location where it is defined.
223+
# so we get useful stack traces if it errors.
224+
func = Expr(:->, Expr(:tuple), Expr(:block, __source__, body))
225+
return :(Thunk($(esc(func))))
217226
end
218227

219228
# have to define this here after `@thunk` and `Thunk` is defined

0 commit comments

Comments
 (0)