Skip to content

Commit 4fada2c

Browse files
authored
fix for change in Julia foreigncall (#322)
1 parent 4773269 commit 4fada2c

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/interpret.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# Implements a simple interpreter for julia's lowered AST
2-
31
isassign(frame) = isassign(frame, frame.pc)
42
isassign(frame, pc) = (pc in frame.framecode.used)
53

src/optimize.jl

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ function lookup_global_refs!(ex::Expr)
116116
return nothing
117117
end
118118

119-
const rng = MersenneTwister()
119+
# See https://github.com/JuliaLang/julia/pull/32800
120+
const foreigncall_version = VERSION < v"1.3.0-alpha.108" ? 0 : 1
120121

121122
"""
122123
optimize!(code::CodeInfo, mod::Module)
@@ -164,13 +165,13 @@ function optimize!(code::CodeInfo, scope)
164165
arg1 = stmt.args[1]
165166
if (arg1 == :llvmcall || lookup_stmt(code.code, arg1) == Base.llvmcall) && isempty(sparams) && scope isa Method
166167
nargs = length(stmt.args)-4
167-
delete_idx = build_compiled_call!(stmt, Base.llvmcall, stmt.args[2:4], code, idx, nargs, sparams, evalmod)
168+
delete_idx = build_compiled_call!(stmt, Base.llvmcall, code, idx, nargs, sparams, evalmod)
168169
push!(foreigncalls_idx, idx)
169170
append!(delete_idxs, delete_idx)
170171
end
171172
elseif isexpr(stmt, :foreigncall) && scope isa Method
172-
nargs = stmt.args[5]
173-
delete_idx = build_compiled_call!(stmt, :ccall, stmt.args[1:3], code, idx, nargs, sparams, evalmod)
173+
nargs = foreigncall_version == 0 ? stmt.args[5] : length(stmt.args[3])
174+
delete_idx = build_compiled_call!(stmt, :ccall, code, idx, nargs, sparams, evalmod)
174175
push!(foreigncalls_idx, idx)
175176
append!(delete_idxs, delete_idx)
176177
end
@@ -227,9 +228,8 @@ function parametric_type_to_expr(t::Type)
227228
end
228229

229230
# Handle :llvmcall & :foreigncall (issue #28)
230-
function build_compiled_call!(stmt, fcall, typargs, code, idx, nargs, sparams, evalmod)
231+
function build_compiled_call!(stmt, fcall, code, idx, nargs, sparams, evalmod)
231232
TVal = evalmod == Core.Compiler ? Core.Compiler.Val : Val
232-
argnames = Any[Symbol("arg", string(i)) for i = 1:nargs]
233233
delete_idx = Int[]
234234
if fcall == :ccall
235235
cfunc, RetType, ArgType = lookup_stmt(code.code, stmt.args[1]), stmt.args[2], stmt.args[3]
@@ -289,6 +289,7 @@ function build_compiled_call!(stmt, fcall, typargs, code, idx, nargs, sparams, e
289289
# When the ccall is dynamic we pass the pointer as an argument so can reuse the function
290290
cc_key = (dynamic_ccall ? :ptr : cfunc, RetType, ArgType, evalmod) # compiled call key
291291
f = get(compiled_calls, cc_key, nothing)
292+
argnames = Any[Symbol("arg", string(i)) for i = 1:nargs]
292293
if f === nothing
293294
if fcall == :ccall
294295
ArgType = Expr(:tuple, [parametric_type_to_expr(t) for t in ArgType]...)
@@ -302,12 +303,13 @@ function build_compiled_call!(stmt, fcall, typargs, code, idx, nargs, sparams, e
302303
push!(wrapargs, :(::$TVal{$sparam}))
303304
end
304305
methname = gensym("compiledcall")
305-
if stmt.args[4] == :(:llvmcall)
306+
calling_convention = stmt.args[foreigncall_version == 0 ? 4 : 5]
307+
if calling_convention == :(:llvmcall)
306308
def = :(
307309
function $methname($(wrapargs...)) where {$(sparams...)}
308310
return $fcall($cfunc, llvmcall, $RetType, $ArgType, $(argnames...))
309311
end)
310-
elseif stmt.args[4] == :(:stdcall)
312+
elseif calling_convention == :(:stdcall)
311313
def = :(
312314
function $methname($(wrapargs...)) where {$(sparams...)}
313315
return $fcall($cfunc, stdcall, $RetType, $ArgType, $(argnames...))

0 commit comments

Comments
 (0)