Skip to content

Commit 22f186b

Browse files
authored
Fix llvmcall/ccall and OpaqueClosure on nightly (#665)
* Lowering has been changed again * The `inferred` field of `CodeInfo` has been removed
1 parent 2bbcead commit 22f186b

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

src/construct.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,8 @@ function prepare_call(@nospecialize(f), allargs; enter_generated = false)
236236
if f isa Core.OpaqueClosure
237237
method = f.source
238238
# don't try to interpret optimized ir
239-
if Base.uncompressed_ir(method).inferred
239+
src = Base.uncompressed_ir(method)
240+
if hasfield(CodeInfo, :inferred) && src.inferred # xref https://github.com/JuliaLang/julia/pull/53219
240241
@debug "not interpreting opaque closure $f since it contains inferred code"
241242
return nothing
242243
end

src/interpret.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,9 @@ function evaluate_foreigncall(@nospecialize(recurse), frame::Frame, call_expr::E
181181
args[i] = isa(arg, Symbol) ? QuoteNode(arg) : arg
182182
end
183183
head === :cfunction && (args[2] = QuoteNode(args[2]))
184+
if head === :foreigncall && !isa(args[5], QuoteNode)
185+
args[5] = QuoteNode(args[5])
186+
end
184187
scope = frame.framecode.scope
185188
data = frame.framedata
186189
if !isempty(data.sparams) && scope isa Method

src/optimize.jl

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,21 @@ function lookup_stmt(stmts::Vector{Any}, @nospecialize arg)
77
end
88
if isa(arg, QuoteNode)
99
return arg.value
10+
elseif isexpr(arg, :call, 3) && is_global_ref(arg.args[1], Base, :getproperty)
11+
# Starting with Julia 1.12, llvmcall looks like this:
12+
# julia> src.code[1:3]
13+
# 3-element Vector{Any}:
14+
# :(TheModule.Core) # GlobalRef
15+
# :(Base.getproperty(%1, :Intrinsics))
16+
# :(Base.getproperty(%2, :llvmcall))
17+
q = arg.args[3]
18+
if isa(q, QuoteNode) && isa(q.value, Symbol)
19+
mod = lookup_stmt(stmts, arg.args[2])
20+
if isa(mod, GlobalRef)
21+
mod = getproperty(mod.mod, mod.name)
22+
end
23+
isa(mod, Module) && return getproperty(mod, q.value)
24+
end
1025
end
1126
return arg
1227
end
@@ -116,7 +131,8 @@ function optimize!(code::CodeInfo, scope)
116131
if stmt.head === :call
117132
# Check for :llvmcall
118133
arg1 = stmt.args[1]
119-
if (arg1 === :llvmcall || lookup_stmt(code.code, arg1) === Base.llvmcall) && isempty(sparams) && scope isa Method
134+
larg1 = lookup_stmt(code.code, arg1)
135+
if (arg1 === :llvmcall || larg1 === Base.llvmcall || is_global_ref(larg1, Base, :llvmcall)) && isempty(sparams) && scope isa Method
120136
# Call via `invokelatest` to avoid compiling it until we need it
121137
@invokelatest build_compiled_llvmcall!(stmt, code, idx, evalmod)
122138
methodtables[idx] = Compiled()
@@ -193,7 +209,7 @@ function build_compiled_foreigncall!(stmt::Expr, code::CodeInfo, sparams::Vector
193209
TVal = evalmod == Core.Compiler ? Core.Compiler.Val : Val
194210
cfuncarg = stmt.args[1]
195211
while isa(cfuncarg, SSAValue)
196-
cfuncarg = code.code[cfuncarg.id]
212+
cfuncarg = lookup_stmt(code.code, cfuncarg)
197213
end
198214
RetType, ArgType = stmt.args[2], stmt.args[3]::SimpleVector
199215

test/interpret.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ end
258258

259259
# llvmcall
260260
function add1234(x::Tuple{Int32,Int32,Int32,Int32})
261-
Base.llvmcall("""%3 = extractvalue [4 x i32] %0, 0
261+
Core.Intrinsics.llvmcall("""%3 = extractvalue [4 x i32] %0, 0
262262
%4 = extractvalue [4 x i32] %0, 1
263263
%5 = extractvalue [4 x i32] %0, 2
264264
%6 = extractvalue [4 x i32] %0, 3

0 commit comments

Comments
 (0)