Skip to content

Commit

Permalink
update for 1.8
Browse files Browse the repository at this point in the history
- it seems like `:ccall` preserves may now include `SlotNumber` objects,
  and so we need to update `build_compiled_call!` accordingly
- JuliaLang/julia#43671 increased the number of
  statements of code that involves assignment to a global variable
  • Loading branch information
aviatesk committed Feb 18, 2022
1 parent d172be1 commit 87b35b4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
22 changes: 13 additions & 9 deletions src/optimize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -279,19 +279,23 @@ function build_compiled_call!(stmt::Expr, fcall, code, idx, nargs::Int, sparams:
if arg isa SSAValue
unsafe_convert_expr = code.code[arg.id]::Expr
push!(delete_idx, arg.id) # delete the unsafe_convert
cconvert_stmt = unsafe_convert_expr.args[3]::SSAValue
push!(delete_idx, cconvert_stmt.id) # delete the cconvert
cconvert_expr = code.code[cconvert_stmt.id]::Expr
push!(args, cconvert_expr.args[3])
cconvert_val = unsafe_convert_expr.args[3]
if isa(cconvert_val, SSAValue)
push!(delete_idx, cconvert_val.id) # delete the cconvert
newarg = (code.code[cconvert_val.id]::Expr).args[3]
push!(args, newarg)
else
@assert isa(cconvert_val, SlotNumber)
push!(args, cconvert_val)
end
elseif arg isa SlotNumber
index = findfirst(code.code) do expr
idx = findfirst(code.code) do expr
Meta.isexpr(expr, :(=)) || return false
lhs = expr.args[1]
return lhs isa SlotNumber && lhs.id === arg.id
end
index = index::Int
unsafe_convert_expr = code.code[index]::Expr
push!(delete_idx, index) # delete the unsafe_convert
end::Int
unsafe_convert_expr = code.code[idx]::Expr
push!(delete_idx, idx) # delete the unsafe_convert
push!(args, unsafe_convert_expr.args[2])
else
error("unexpected foreigncall argument type encountered: $(typeof(arg))")
Expand Down
4 changes: 2 additions & 2 deletions test/interpret.jl
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ end
src = lwr.args[1]::Core.CodeInfo
frame = Frame(M, src; optimize=false)
@test length(frame.framecode.src.code) == length(src.code)
@test JuliaInterpreter.finish_and_return!(frame, true)
@test JuliaInterpreter.finish_and_return!(frame, true)

M = Module()
lwr = Meta.@lower M begin
Expand All @@ -868,7 +868,7 @@ end
src = lwr.args[1]::Core.CodeInfo
frame = Frame(M, src; optimize=false)
@test length(frame.framecode.src.code) == length(src.code)
@test JuliaInterpreter.finish_and_return!(frame, true)
@test JuliaInterpreter.finish_and_return!(frame, true)
end

iscallexpr(ex::Expr) = ex.head === :call
Expand Down
8 changes: 6 additions & 2 deletions test/limits.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ module EvalLimited end
insert!(ex.args, 1, LineNumberNode(1, Symbol("fake.jl")))
end
modexs = collect(ExprSplitter(EvalLimited, ex))
nstmts = 100 # enough to ensure it gets into the loop but doesn't finish
@static if isdefined(Core, :get_binding_type)
nstmts = 10*12 + 20 # 10 * 12 statements per iteration + α
else
nstmts = 9*12 + 20 # 10 * 9 statements per iteration + α
end
for (mod, ex) in modexs
frame = Frame(mod, ex)
@test isa(frame, Frame)
Expand All @@ -96,7 +100,7 @@ module EvalLimited end
isa(ret, Aborted) && (push!(aborts, ret); break)
end
end
@test 8 < EvalLimited.s < 50 # with Compiled(), 9 statements per iteration
@test 10 EvalLimited.s < 50
@test length(aborts) == 1
@test aborts[1].at.line (2, 3, 4, 5) # 2 corresponds to lowering of the for loop

Expand Down

0 comments on commit 87b35b4

Please sign in to comment.