Skip to content

Commit 638cd84

Browse files
authored
Merge pull request #297 from pchintalapudi/pc/jl_type_to_llvm
Update jl_type_to_llvm to require a context in >= v1.9
2 parents 790e189 + fcc74b9 commit 638cd84

File tree

2 files changed

+32
-13
lines changed

2 files changed

+32
-13
lines changed

src/interop/base.jl

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,35 +47,53 @@ function call_function(llvmf::LLVM.Function, rettyp::Type=Nothing, argtyp::Type=
4747
end
4848
end
4949

50+
5051
"""
51-
isboxed(typ::Type)
52+
isboxed(typ::Type; [ctx::Context])
5253
5354
Return if a type would be boxed when instantiated in the code generator.
5455
"""
55-
function isboxed(typ::Type)
56+
function isboxed(typ::Type; ctx::Union{Nothing,Context}=nothing)
5657
isboxed_ref = Ref{Bool}()
57-
ccall(:jl_type_to_llvm, LLVM.API.LLVMTypeRef, (Any, Ptr{Bool}), typ, isboxed_ref)
58+
if VERSION >= v"1.9.0-DEV.115"
59+
if ctx === nothing
60+
Context() do ctx
61+
ccall(:jl_type_to_llvm, LLVM.API.LLVMTypeRef,
62+
(Any, LLVM.API.LLVMContextRef, Ptr{Bool}), typ, ctx, isboxed_ref)
63+
end
64+
else
65+
ccall(:jl_type_to_llvm, LLVM.API.LLVMTypeRef,
66+
(Any, LLVM.API.LLVMContextRef, Ptr{Bool}), typ, ctx, isboxed_ref)
67+
end
68+
else
69+
ccall(:jl_type_to_llvm, LLVM.API.LLVMTypeRef,
70+
(Any, Ptr{Bool}), typ, isboxed_ref)
71+
end
5872
return isboxed_ref[]
5973
end
6074

6175
"""
62-
convert(LLVMType, typ::Type, [ctx::Context]; allow_boxed=true)
76+
convert(LLVMType, typ::Type, ctx::Context; allow_boxed=true)
6377
64-
Convert a Julia type `typ` to its LLVM representation. Fails if the type would be boxed.
65-
If `ctx` is specified, the returned LLVM type will be valid in that context.
78+
Convert a Julia type `typ` to its LLVM representation in context `ctx`.
79+
The `allow_boxed` argument determines whether boxed types are allowed.
6680
"""
67-
function Base.convert(::Type{LLVMType}, typ::Type; ctx::Union{Nothing,Context}=nothing,
81+
function Base.convert(::Type{LLVMType}, typ::Type; ctx::Context,
6882
allow_boxed::Bool=false)
6983
isboxed_ref = Ref{Bool}()
70-
llvmtyp = LLVMType(ccall(:jl_type_to_llvm, LLVM.API.LLVMTypeRef,
71-
(Any, Ptr{Bool}), typ, isboxed_ref))
84+
llvmtyp = if VERSION >= v"1.9.0-DEV.115"
85+
LLVMType(ccall(:jl_type_to_llvm, LLVM.API.LLVMTypeRef,
86+
(Any, Context, Ptr{Bool}), typ, ctx, isboxed_ref))
87+
else
88+
LLVMType(ccall(:jl_type_to_llvm, LLVM.API.LLVMTypeRef,
89+
(Any, Ptr{Bool}), typ, isboxed_ref))
90+
end
7291
if !allow_boxed && isboxed_ref[]
7392
error("Conversion of boxed type $typ is not allowed")
7493
end
7594

76-
if ctx !== nothing && ctx != context(llvmtyp)
77-
# FIXME: Julia currently doesn't offer an API to fetch types in a specific context
78-
95+
# HACK: older versions of Julia don't offer an API to fetch types in a specific context
96+
if VERSION < v"1.9.0-DEV.115" && ctx != context(llvmtyp)
7997
if llvmtyp == LLVM.VoidType(context(llvmtyp))
8098
return LLVM.VoidType(ctx)
8199
end

test/interop.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,13 @@ end
3232
end
3333
@eval mutable struct NonGhostType2 end
3434

35+
@test isboxed(NonGhostType2)
3536
@test isghosttype(GhostType)
3637
@test !isghosttype(NonGhostType1)
3738
@test !isghosttype(NonGhostType2)
38-
@test isboxed(NonGhostType2)
3939

4040
Context() do ctx
41+
@test isboxed(NonGhostType2; ctx)
4142
@test isghosttype(GhostType; ctx)
4243
@test !isghosttype(NonGhostType1; ctx)
4344
@test !isghosttype(NonGhostType2; ctx)

0 commit comments

Comments
 (0)