Skip to content

Commit a1b0efd

Browse files
authored
Merge pull request #118 from JuliaDebug/teh/fix_113c
Fix handling of kwargs in atsign-interpret
2 parents 0ab4fe4 + 44b6ec6 commit a1b0efd

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

src/JuliaInterpreter.jl

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ else
354354
const specialize_method = Core.Compiler.specialize_method
355355
end
356356

357-
function prepare_framecode(method::Method, argtypes; enter_generated=false)
357+
function prepare_framecode(method::Method, @nospecialize(argtypes); enter_generated=false)
358358
sig = method.sig
359359
if method.module == Core.Compiler || method.module == Base.Threads || method compiled_methods
360360
return Compiled()
@@ -485,7 +485,7 @@ end
485485
Prepare `expr` for evaluation in `mod`. `expr` should be a "straightforward" expression,
486486
one that does not require special top-level handling (see [`JuliaInterpreter.split_expressions`](@ref)).
487487
"""
488-
function prepare_thunk(mod::Module, thunk::Expr, recursive=false)
488+
function prepare_thunk(mod::Module, thunk::Expr, recursive::Bool=false)
489489
if isexpr(thunk, :thunk)
490490
framecode = JuliaFrameCode(mod, thunk.args[1])
491491
elseif isexpr(thunk, :error) || isexpr(thunk, :incomplete)
@@ -1038,22 +1038,18 @@ end
10381038

10391039
lower(mod, arg) = false ? expand(arg) : Meta.lower(mod, arg)
10401040

1041-
# This is a version of gen_call_with_extracted_types, except that is passes back the call expression
1042-
# for further processing.
1041+
separate_kwargs(args...; kwargs...) = (args, kwargs.data)
1042+
1043+
# This is a version of InteractiveUtils.gen_call_with_extracted_types, except that is passes back the
1044+
# call expression for further processing.
10431045
function extract_args(__module__, ex0)
10441046
if isa(ex0, Expr)
1045-
kws = collect(filter(x->isexpr(x,:kw),ex0.args))
1046-
if !isempty(kws)
1047-
names = []
1048-
values = Tuple(map(x-> begin
1049-
push!(names,x.args[1])
1050-
x.args[2]
1051-
end,kws))
1052-
names = Tuple(names)
1053-
return Expr(:tuple,:(Core.kwfunc($(ex0.args[1]))),
1054-
Expr(:call, NamedTuple{names,typeof(values)}, values),
1055-
map(x->isexpr(x, :parameters) ? QuoteNode(x) : x,
1056-
filter(x->!isexpr(x, :kw),ex0.args))...)
1047+
if any(a->(Meta.isexpr(a, :kw) || Meta.isexpr(a, :parameters)), ex0.args)
1048+
return quote
1049+
local arg1 = $(ex0.args[1])
1050+
local args, kwargs = $separate_kwargs($(ex0.args[2:end]...))
1051+
tuple(Core.kwfunc(arg1), kwargs, arg1, args...)
1052+
end
10571053
elseif ex0.head == :.
10581054
return Expr(:tuple, :getproperty, ex0.args...)
10591055
elseif ex0.head == :(<:)

src/precompile.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,14 @@ function _precompile_()
2424
precompile(Tuple{typeof(f), Vector{JuliaStackFrame}, JuliaStackFrame, JuliaProgramCounter, Bool})
2525
end
2626
precompile(Tuple{typeof(split_expressions), Module, Expr})
27+
precompile(Tuple{typeof(split_expressions!), Vector{Tuple{Module,Expr}}, Dict{Module,Vector{Expr}}, Expr, Module, Expr})
2728
precompile(Tuple{typeof(prepare_thunk), Module, Expr})
29+
precompile(Tuple{typeof(prepare_thunk), Module, Expr, Bool})
2830
precompile(Tuple{typeof(prepare_locals), JuliaFrameCode, Vector{Any}})
2931
precompile(Tuple{typeof(prepare_args), Any, Vector{Any}, Vector{Any}})
3032
precompile(Tuple{typeof(prepare_call), Any, Vector{Any}})
31-
precompile(Tuple{typeof(Core.kwfunc(prepare_call)), NamedTuple{(:enter_generated,),Tuple{Bool}}, typeof(JuliaInterpreter.prepare_call), Function, Vector{Any}})
33+
precompile(Tuple{typeof(Core.kwfunc(prepare_call)), NamedTuple{(:enter_generated,),Tuple{Bool}}, typeof(prepare_call), Function, Vector{Any}})
34+
precompile(Tuple{typeof(Core.kwfunc(prepare_framecode)), NamedTuple{(:enter_generated,),Tuple{Bool}}, typeof(prepare_framecode), Method, Type})
3235
precompile(Tuple{typeof(build_frame), JuliaFrameCode, Vector{Any}, Core.SimpleVector})
3336
precompile(Tuple{typeof(extract_args), Module, Expr})
3437
precompile(Tuple{typeof(enter_call), Int, Int})

test/interpret.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,10 @@ end
314314
@interpret f106c()
315315
@interpret f106d()
316316

317+
# issue #113
318+
f113(;x) = x
319+
@test @interpret(f113(;x=[1,2,3])) == f113(;x=[1,2,3])
320+
317321
# Some expression can appear nontrivial but lower to nothing
318322
@test isa(JuliaInterpreter.prepare_thunk(Main, :(@static if ccall(:jl_get_UNAME, Any, ()) == :NoOS 1+1 end)), Nothing)
319323
@test isa(JuliaInterpreter.prepare_thunk(Main, :(Base.BaseDocs.@kw_str "using")), Nothing)

0 commit comments

Comments
 (0)