Skip to content

Commit 87b35b4

Browse files
committed
update for 1.8
- 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
1 parent d172be1 commit 87b35b4

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

src/optimize.jl

+13-9
Original file line numberDiff line numberDiff line change
@@ -279,19 +279,23 @@ function build_compiled_call!(stmt::Expr, fcall, code, idx, nargs::Int, sparams:
279279
if arg isa SSAValue
280280
unsafe_convert_expr = code.code[arg.id]::Expr
281281
push!(delete_idx, arg.id) # delete the unsafe_convert
282-
cconvert_stmt = unsafe_convert_expr.args[3]::SSAValue
283-
push!(delete_idx, cconvert_stmt.id) # delete the cconvert
284-
cconvert_expr = code.code[cconvert_stmt.id]::Expr
285-
push!(args, cconvert_expr.args[3])
282+
cconvert_val = unsafe_convert_expr.args[3]
283+
if isa(cconvert_val, SSAValue)
284+
push!(delete_idx, cconvert_val.id) # delete the cconvert
285+
newarg = (code.code[cconvert_val.id]::Expr).args[3]
286+
push!(args, newarg)
287+
else
288+
@assert isa(cconvert_val, SlotNumber)
289+
push!(args, cconvert_val)
290+
end
286291
elseif arg isa SlotNumber
287-
index = findfirst(code.code) do expr
292+
idx = findfirst(code.code) do expr
288293
Meta.isexpr(expr, :(=)) || return false
289294
lhs = expr.args[1]
290295
return lhs isa SlotNumber && lhs.id === arg.id
291-
end
292-
index = index::Int
293-
unsafe_convert_expr = code.code[index]::Expr
294-
push!(delete_idx, index) # delete the unsafe_convert
296+
end::Int
297+
unsafe_convert_expr = code.code[idx]::Expr
298+
push!(delete_idx, idx) # delete the unsafe_convert
295299
push!(args, unsafe_convert_expr.args[2])
296300
else
297301
error("unexpected foreigncall argument type encountered: $(typeof(arg))")

test/interpret.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@ end
848848
src = lwr.args[1]::Core.CodeInfo
849849
frame = Frame(M, src; optimize=false)
850850
@test length(frame.framecode.src.code) == length(src.code)
851-
@test JuliaInterpreter.finish_and_return!(frame, true)
851+
@test JuliaInterpreter.finish_and_return!(frame, true)
852852

853853
M = Module()
854854
lwr = Meta.@lower M begin
@@ -868,7 +868,7 @@ end
868868
src = lwr.args[1]::Core.CodeInfo
869869
frame = Frame(M, src; optimize=false)
870870
@test length(frame.framecode.src.code) == length(src.code)
871-
@test JuliaInterpreter.finish_and_return!(frame, true)
871+
@test JuliaInterpreter.finish_and_return!(frame, true)
872872
end
873873

874874
iscallexpr(ex::Expr) = ex.head === :call

test/limits.jl

+6-2
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,11 @@ module EvalLimited end
8585
insert!(ex.args, 1, LineNumberNode(1, Symbol("fake.jl")))
8686
end
8787
modexs = collect(ExprSplitter(EvalLimited, ex))
88-
nstmts = 100 # enough to ensure it gets into the loop but doesn't finish
88+
@static if isdefined(Core, :get_binding_type)
89+
nstmts = 10*12 + 20 # 10 * 12 statements per iteration + α
90+
else
91+
nstmts = 9*12 + 20 # 10 * 9 statements per iteration + α
92+
end
8993
for (mod, ex) in modexs
9094
frame = Frame(mod, ex)
9195
@test isa(frame, Frame)
@@ -96,7 +100,7 @@ module EvalLimited end
96100
isa(ret, Aborted) && (push!(aborts, ret); break)
97101
end
98102
end
99-
@test 8 < EvalLimited.s < 50 # with Compiled(), 9 statements per iteration
103+
@test 10 EvalLimited.s < 50
100104
@test length(aborts) == 1
101105
@test aborts[1].at.line (2, 3, 4, 5) # 2 corresponds to lowering of the for loop
102106

0 commit comments

Comments
 (0)