Skip to content

Commit 2ada170

Browse files
committed
Try harder to find llvmcalls
One can use `llvmcall` without scoping it as `Base.llvmcall`. Thus we need a reliable way to find it independently of the GlobalRef module.
1 parent 890cae3 commit 2ada170

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

src/construct.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ function prepare_framecode(method::Method, @nospecialize(argtypes); enter_genera
166166
# Currenly, our strategy to deal with llvmcall can't handle parametric functions
167167
# (the "mini interpreter" runs in module scope, not method scope)
168168
if (!isempty(lenv) && (hasarg(isidentical(:llvmcall), code.code) ||
169-
hasarg(isidentical(Base.llvmcall), code.code) ||
170-
hasarg(a->is_global_ref(a, Base, :llvmcall), code.code))) ||
169+
hasarg(isidentical(Core.Intrinsics.llvmcall), code.code) ||
170+
hasarg(a->is_global_ref_egal(a, :llvmcall, Core.Intrinsics.llvmcall), code.code))) ||
171171
hasarg(isidentical(:iolock_begin), code.code)
172172
return Compiled()
173173
end

src/optimize.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ function optimize!(code::CodeInfo, scope)
131131
# Check for :llvmcall
132132
arg1 = stmt.args[1]
133133
larg1 = lookup_stmt(code.code, arg1)
134-
if (arg1 === :llvmcall || larg1 === Base.llvmcall || is_global_ref(larg1, Base, :llvmcall)) && isempty(sparams) && scope isa Method
134+
if (arg1 === :llvmcall || larg1 === Base.llvmcall || is_global_ref_egal(larg1, :llvmcall, Core.Intrinsics.llvmcall)) && isempty(sparams) && scope isa Method
135135
# Call via `invokelatest` to avoid compiling it until we need it
136136
@invokelatest build_compiled_llvmcall!(stmt, code, idx, evalmod)
137137
methodtables[idx] = Compiled()

src/utils.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,14 @@ Tests whether `g` is equal to `GlobalRef(mod, name)`.
140140
"""
141141
is_global_ref(@nospecialize(g), mod::Module, name::Symbol) = isa(g, GlobalRef) && g.mod === mod && g.name == name
142142

143+
function is_global_ref_egal(@nospecialize(g), name::Symbol, @nospecialize(ref))
144+
# Identifying GlobalRefs regardless of how the caller scopes them
145+
isa(g, GlobalRef) || return false
146+
g.name === name || return false
147+
gref = getglobal(g.mod, g.name)
148+
return gref === ref
149+
end
150+
143151
is_quotenode(@nospecialize(q), @nospecialize(val)) = isa(q, QuoteNode) && q.value == val
144152
is_quotenode_egal(@nospecialize(q), @nospecialize(val)) = isa(q, QuoteNode) && q.value === val
145153

0 commit comments

Comments
 (0)