Skip to content

Commit d662e72

Browse files
committed
better native_call impl
1 parent 0ac6269 commit d662e72

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/interpret.jl

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -224,18 +224,21 @@ function bypass_builtins(interp::Interpreter, frame::Frame, call_expr::Expr, pc:
224224
end
225225

226226
function native_call(fargs::Vector{Any}, frame::Frame)
227-
f = popfirst!(fargs) # now it's really just `args`
228-
if (@static isdefinedglobal(Core.IR, :EnterNode) && true)
229-
newscope = Core.current_scope()
230-
if newscope !== nothing || !isempty(frame.framedata.current_scopes)
231-
for scope in frame.framedata.current_scopes
232-
newscope = Scope(newscope, scope.values...)
233-
end
234-
ex = Expr(:tryfinally, :($f($fargs...)), nothing, newscope)
235-
return Core.eval(moduleof(frame), ex)
227+
f = popfirst!(fargs)
228+
@something maybe_eval_with_scope(f, fargs, frame) return @invokelatest f(fargs...)
229+
end
230+
231+
function maybe_eval_with_scope(@nospecialize(f), fargs::Vector{Any}, frame::Frame)
232+
@static isdefinedglobal(Core.IR, :EnterNode) || return nothing
233+
newscope = Core.current_scope()
234+
if newscope !== nothing || !isempty(frame.framedata.current_scopes)
235+
for scope in frame.framedata.current_scopes
236+
newscope = Scope(newscope, scope.values...)
236237
end
238+
ex = Expr(:tryfinally, :($f($fargs...)), nothing, newscope)
239+
return Some{Any}(Core.eval(moduleof(frame), ex))
237240
end
238-
return @invokelatest f(fargs...)
241+
return nothing
239242
end
240243

241244
function evaluate_call!(interp::Compiled, frame::Frame, call_expr::Expr, enter_generated::Bool=false)

0 commit comments

Comments
 (0)