Skip to content

Commit

Permalink
Merge pull request #118 from JuliaDebug/teh/fix_113c
Browse files Browse the repository at this point in the history
 Fix handling of kwargs in atsign-interpret
  • Loading branch information
timholy authored Mar 7, 2019
2 parents 0ab4fe4 + 44b6ec6 commit a1b0efd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
28 changes: 12 additions & 16 deletions src/JuliaInterpreter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ else
const specialize_method = Core.Compiler.specialize_method
end

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

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

# This is a version of gen_call_with_extracted_types, except that is passes back the call expression
# for further processing.
separate_kwargs(args...; kwargs...) = (args, kwargs.data)

# This is a version of InteractiveUtils.gen_call_with_extracted_types, except that is passes back the
# call expression for further processing.
function extract_args(__module__, ex0)
if isa(ex0, Expr)
kws = collect(filter(x->isexpr(x,:kw),ex0.args))
if !isempty(kws)
names = []
values = Tuple(map(x-> begin
push!(names,x.args[1])
x.args[2]
end,kws))
names = Tuple(names)
return Expr(:tuple,:(Core.kwfunc($(ex0.args[1]))),
Expr(:call, NamedTuple{names,typeof(values)}, values),
map(x->isexpr(x, :parameters) ? QuoteNode(x) : x,
filter(x->!isexpr(x, :kw),ex0.args))...)
if any(a->(Meta.isexpr(a, :kw) || Meta.isexpr(a, :parameters)), ex0.args)
return quote
local arg1 = $(ex0.args[1])
local args, kwargs = $separate_kwargs($(ex0.args[2:end]...))
tuple(Core.kwfunc(arg1), kwargs, arg1, args...)
end
elseif ex0.head == :.
return Expr(:tuple, :getproperty, ex0.args...)
elseif ex0.head == :(<:)
Expand Down
5 changes: 4 additions & 1 deletion src/precompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ function _precompile_()
precompile(Tuple{typeof(f), Vector{JuliaStackFrame}, JuliaStackFrame, JuliaProgramCounter, Bool})
end
precompile(Tuple{typeof(split_expressions), Module, Expr})
precompile(Tuple{typeof(split_expressions!), Vector{Tuple{Module,Expr}}, Dict{Module,Vector{Expr}}, Expr, Module, Expr})
precompile(Tuple{typeof(prepare_thunk), Module, Expr})
precompile(Tuple{typeof(prepare_thunk), Module, Expr, Bool})
precompile(Tuple{typeof(prepare_locals), JuliaFrameCode, Vector{Any}})
precompile(Tuple{typeof(prepare_args), Any, Vector{Any}, Vector{Any}})
precompile(Tuple{typeof(prepare_call), Any, Vector{Any}})
precompile(Tuple{typeof(Core.kwfunc(prepare_call)), NamedTuple{(:enter_generated,),Tuple{Bool}}, typeof(JuliaInterpreter.prepare_call), Function, Vector{Any}})
precompile(Tuple{typeof(Core.kwfunc(prepare_call)), NamedTuple{(:enter_generated,),Tuple{Bool}}, typeof(prepare_call), Function, Vector{Any}})
precompile(Tuple{typeof(Core.kwfunc(prepare_framecode)), NamedTuple{(:enter_generated,),Tuple{Bool}}, typeof(prepare_framecode), Method, Type})
precompile(Tuple{typeof(build_frame), JuliaFrameCode, Vector{Any}, Core.SimpleVector})
precompile(Tuple{typeof(extract_args), Module, Expr})
precompile(Tuple{typeof(enter_call), Int, Int})
Expand Down
4 changes: 4 additions & 0 deletions test/interpret.jl
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,10 @@ end
@interpret f106c()
@interpret f106d()

# issue #113
f113(;x) = x
@test @interpret(f113(;x=[1,2,3])) == f113(;x=[1,2,3])

# Some expression can appear nontrivial but lower to nothing
@test isa(JuliaInterpreter.prepare_thunk(Main, :(@static if ccall(:jl_get_UNAME, Any, ()) == :NoOS 1+1 end)), Nothing)
@test isa(JuliaInterpreter.prepare_thunk(Main, :(Base.BaseDocs.@kw_str "using")), Nothing)
Expand Down

0 comments on commit a1b0efd

Please sign in to comment.