Skip to content

Commit 5fa1aaf

Browse files
committed
update builtins, use @invokelatest instead of the function version
1 parent 64cfc37 commit 5fa1aaf

File tree

4 files changed

+22
-12
lines changed

4 files changed

+22
-12
lines changed

src/breakpoints.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ function shouldbreak(frame::Frame, pc::Int)
195195
isassigned(bps, pc) || return false
196196
bp = bps[pc]
197197
bp.isactive || return false
198-
return Base.invokelatest(bp.condition, frame)::Bool
198+
return invokelatest(bp.condition, frame)::Bool
199199
end
200200

201201
function prepare_slotfunction(framecode::FrameCode, body::Union{Symbol,Expr})

src/builtins.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,12 @@ function maybe_evaluate_builtin(frame, call_expr, expand::Bool)
163163
else
164164
return Some{Any}(Core.ifelse(getargs(args, frame)...))
165165
end
166+
elseif f === Core.memorynew
167+
if nargs == 2
168+
return Some{Any}(Core.memorynew(@lookup(frame, args[2]), @lookup(frame, args[3])))
169+
else
170+
return Some{Any}(Core.memorynew(getargs(args, frame)...))
171+
end
166172
elseif @static isdefined(Core, :memoryref_isassigned) && f === Core.memoryref_isassigned
167173
if nargs == 3
168174
return Some{Any}(Core.memoryref_isassigned(@lookup(frame, args[2]), @lookup(frame, args[3]), @lookup(frame, args[4])))
@@ -285,6 +291,8 @@ function maybe_evaluate_builtin(frame, call_expr, expand::Bool)
285291
else
286292
return Some{Any}(isdefined(getargs(args, frame)...))
287293
end
294+
elseif f === isdefinedglobal
295+
return Some{Any}(isdefinedglobal(getargs(args, frame)...))
288296
elseif f === modifyfield!
289297
if nargs == 4
290298
return Some{Any}(modifyfield!(@lookup(frame, args[2]), @lookup(frame, args[3]), @lookup(frame, args[4]), @lookup(frame, args[5])))

src/interpret.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ isassign(frame::Frame) = isassign(frame, frame.pc)
22
isassign(frame::Frame, pc::Int) = (pc in frame.framecode.used)
33

44
lookup_var(frame::Frame, val::SSAValue) = frame.framedata.ssavalues[val.id]
5-
lookup_var(frame::Frame, ref::GlobalRef) = invokelatest(getfield, ref.mod, ref.name)
5+
lookup_var(frame::Frame, ref::GlobalRef) = @invokelatest getfield(ref.mod, ref.name)
66
function lookup_var(frame::Frame, slot::SlotNumber)
77
val = frame.framedata.locals[slot.id]
88
val !== nothing && return val.value
@@ -117,7 +117,7 @@ function lookup_or_eval(@nospecialize(recurse), frame::Frame, @nospecialize(node
117117
elseif f === Val && length(ex.args) == 2
118118
return Val(ex.args[2])
119119
else
120-
Base.invokelatest(error, "unknown call f introduced by ccall lowering ", f)
120+
@invokelatest error("unknown call f introduced by ccall lowering ", f)
121121
end
122122
else
123123
return lookup_expr(frame, ex)
@@ -147,7 +147,7 @@ function resolvefc(frame::Frame, @nospecialize(expr))
147147
(isa(a, QuoteNode) && a.value === Core.tuple) || error("unexpected ccall to ", expr)
148148
return Expr(:call, GlobalRef(Core, :tuple), (expr::Expr).args[2:end]...)
149149
end
150-
Base.invokelatest(error, "unexpected ccall to ", expr)
150+
@invokelatest error("unexpected ccall to ", expr)
151151
end
152152

153153
function collect_args(@nospecialize(recurse), frame::Frame, call_expr::Expr; isfc::Bool=false)
@@ -229,7 +229,7 @@ function native_call(fargs::Vector{Any}, frame::Frame)
229229
return Core.eval(moduleof(frame), ex)
230230
end
231231
end
232-
return Base.invokelatest(f, fargs...)
232+
return @invokelatest f(fargs...)
233233
end
234234

235235
function evaluate_call_compiled!(::Compiled, frame::Frame, call_expr::Expr; enter_generated::Bool=false)
@@ -311,8 +311,8 @@ function evaluate_methoddef(frame::Frame, node::Expr)
311311
if f isa Symbol || f isa GlobalRef
312312
mod = f isa Symbol ? moduleof(frame) : f.mod
313313
name = f isa Symbol ? f : f.name
314-
if Base.isbindingresolved(mod, name) && invokelatest(isdefined, mod, name) # `isdefined` accesses the binding, making it impossible to create a new one
315-
f = invokelatest(getfield, mod, name)
314+
if Base.isbindingresolved(mod, name) && @invokelatest isdefined(mod, name) # `isdefined` accesses the binding, making it impossible to create a new one
315+
f = @invokelatest getfield(mod, name)
316316
else
317317
f = Core.eval(mod, Expr(:function, name)) # create a new function
318318
end
@@ -656,7 +656,7 @@ e.g., [`JuliaInterpreter.finish!`](@ref)).
656656
"""
657657
function get_return(frame)
658658
node = pc_expr(frame)
659-
is_return(node) || Base.invokelatest(error, "expected return statement, got ", node)
659+
is_return(node) || @invokelatest error("expected return statement, got ", node)
660660
return lookup_return(frame, node)
661661
end
662662
get_return(t::Tuple{Module,Expr,Frame}) = get_return(t[end])

src/optimize.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ function smallest_ref(stmts, arg, idmin)
2424
end
2525

2626
function lookup_global_ref(a::GlobalRef)
27-
if Base.isbindingresolved(a.mod, a.name) && invokelatest(isdefined, a.mod, a.name) && invokelatest(isconst, a.mod, a.name)
28-
return QuoteNode(invokelatest(getfield, a.mod, a.name))
27+
if (Base.isbindingresolved(a.mod, a.name) &&
28+
(@invokelatest isdefined(a.mod, a.name)) &&
29+
(@invokelatest isconst(a.mod, a.name)))
30+
return QuoteNode(@invokelatest getfield(a.mod, a.name))
2931
end
3032
return a
3133
end
@@ -114,12 +116,12 @@ function optimize!(code::CodeInfo, scope)
114116
arg1 = stmt.args[1]
115117
if (arg1 === :llvmcall || lookup_stmt(code.code, arg1) === Base.llvmcall) && isempty(sparams) && scope isa Method
116118
# Call via `invokelatest` to avoid compiling it until we need it
117-
Base.invokelatest(build_compiled_llvmcall!, stmt, code, idx, evalmod)
119+
@invokelatest build_compiled_llvmcall!(stmt, code, idx, evalmod)
118120
methodtables[idx] = Compiled()
119121
end
120122
elseif stmt.head === :foreigncall && scope isa Method
121123
# Call via `invokelatest` to avoid compiling it until we need it
122-
Base.invokelatest(build_compiled_foreigncall!, stmt, code, sparams, evalmod)
124+
@invokelatest build_compiled_foreigncall!(stmt, code, sparams, evalmod)
123125
methodtables[idx] = Compiled()
124126
end
125127
end

0 commit comments

Comments
 (0)