Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-impose "no double lookup" for invoke #540

Merged
merged 3 commits into from
Jul 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions bin/generate_builtins.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const RECENTLY_ADDED = Core.Builtin[
Core.get_binding_type, Core.set_binding_type!,
Core.getglobal, Core.setglobal!,
Core.modifyfield!, Core.replacefield!, Core.swapfield!,
]
]
const kwinvoke = Core.kwfunc(Core.invoke)

function scopedname(f)
Expand Down Expand Up @@ -175,11 +175,13 @@ function maybe_evaluate_builtin(frame, call_expr, expand::Bool)
print(io,
"""
$head f === $fstr
argswrapped = getargs(args, frame)
if !expand
argswrapped = getargs(args, frame)
return Some{Any}($fstr(argswrapped...))
end
return Expr(:call, $fstr, argswrapped...)
# This uses the original arguments to avoid looking them up twice
# See #442
return Expr(:call, invoke, args[2:end]...)
""")
continue
elseif f === Core._call_latest
Expand Down
6 changes: 4 additions & 2 deletions src/builtins.jl
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,13 @@ function maybe_evaluate_builtin(frame, call_expr, expand::Bool)
return Some{Any}(getglobal(getargs(args, frame)...))
end
elseif f === invoke
argswrapped = getargs(args, frame)
if !expand
argswrapped = getargs(args, frame)
return Some{Any}(invoke(argswrapped...))
end
return Expr(:call, invoke, argswrapped...)
# This uses the original arguments to avoid looking them up twice
# See #442
return Expr(:call, invoke, args[2:end]...)
elseif f === isa
if nargs == 2
return Some{Any}(isa(@lookup(frame, args[2]), @lookup(frame, args[3])))
Expand Down
7 changes: 5 additions & 2 deletions test/interpret.jl
Original file line number Diff line number Diff line change
Expand Up @@ -727,9 +727,12 @@ end
D = Diagonal([1.0, 2.0])
@test @interpret(f(D)) === f(D)

# issue #441
# issue #441 & #535
flog() = @info "logging macros"
@test @interpret flog() === nothing
@test_logs (:info, "logging macros") @test @interpret flog() === nothing
flog2() = @error "this error is ok"
frame = JuliaInterpreter.enter_call(flog2)
@test_logs (:error, "this error is ok") @test debug_command(frame, :c) === nothing
end

struct A396
Expand Down