@@ -28,9 +28,9 @@ Base.schedule(t, val; error=false) = (schedule(t.t, val; error); t)
28
28
macro spawn (ex)
29
29
tp = QuoteNode (:default )
30
30
31
- letargs = Base . _lift_one_interp! (ex)
31
+ letargs = _lift_one_interp! (ex)
32
32
33
- thunk = Base . replace_linenums! (:(()-> ($ (esc (ex)))), __source__)
33
+ thunk = replace_linenums! (:(()-> ($ (esc (ex)))), __source__)
34
34
var = esc (Base. sync_varname) # This is for the @sync macro which sets a local variable whose name is
35
35
# the symbol bound to Base.sync_varname
36
36
# I asked on slack and this is apparently safe to consider a public API
@@ -80,4 +80,25 @@ function _lift_one_interp_helper(expr::Expr, in_quote_context, letargs)
80
80
expr
81
81
end
82
82
83
+ # Copied from base rather than calling it directly because who knows if it'll change in the future
84
+ replace_linenums! (ex, ln:: LineNumberNode ) = ex
85
+ function replace_linenums! (ex:: Expr , ln:: LineNumberNode )
86
+ if ex. head === :block || ex. head === :quote
87
+ # replace line number expressions from metadata (not argument literal or inert) position
88
+ map! (ex. args, ex. args) do @nospecialize (x)
89
+ isa (x, Expr) && x. head === :line && length (x. args) == 1 && return Expr (:line , ln. line)
90
+ isa (x, Expr) && x. head === :line && length (x. args) == 2 && return Expr (:line , ln. line, ln. file)
91
+ isa (x, LineNumberNode) && return ln
92
+ return x
93
+ end
94
+ end
95
+ # preserve any linenums inside `esc(...)` guards
96
+ if ex. head != = :escape
97
+ for subex in ex. args
98
+ subex isa Expr && replace_linenums! (subex, ln)
99
+ end
100
+ end
101
+ return ex
102
+ end
103
+
83
104
end # module Internals
0 commit comments