Skip to content

Commit 17e8e1f

Browse files
committed
Only perform reference checks on debug builds.
1 parent f7e5f62 commit 17e8e1f

File tree

5 files changed

+26
-14
lines changed

5 files changed

+26
-14
lines changed

src/core/instructions.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ end
1515

1616
@inline function refcheck(::Type{T}, ref::API.LLVMValueRef) where T<:Instruction
1717
ref==C_NULL && throw(UndefRefError())
18-
T′ = identify(Instruction, ref)
19-
if T != T′
20-
error("invalid conversion of $T′ instruction reference to $T")
18+
@static if Base.JLOptions().debug_level >= 2
19+
T′ = identify(Instruction, ref)
20+
if T != T′
21+
error("invalid conversion of $T′ instruction reference to $T")
22+
end
2123
end
2224
end
2325

src/core/metadata.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ end
1414

1515
@inline function refcheck(::Type{T}, ref::API.LLVMMetadataRef) where T<:Metadata
1616
ref==C_NULL && throw(UndefRefError())
17-
T′ = identify(Metadata, ref)
18-
if T != T′
19-
error("invalid conversion of $T′ metadata reference to $T")
17+
@static if Base.JLOptions().debug_level >= 2
18+
T′ = identify(Metadata, ref)
19+
if T != T′
20+
error("invalid conversion of $T′ metadata reference to $T")
21+
end
2022
end
2123
end
2224

src/core/type.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ end
1616

1717
@inline function refcheck(::Type{T}, ref::API.LLVMTypeRef) where T<:LLVMType
1818
ref==C_NULL && throw(UndefRefError())
19-
T′ = identify(LLVMType, ref)
20-
if T != T′
21-
error("invalid conversion of $T′ type reference to $T")
19+
@static if Base.JLOptions().debug_level >= 2
20+
T′ = identify(LLVMType, ref)
21+
if T != T′
22+
error("invalid conversion of $T′ type reference to $T")
23+
end
2224
end
2325
end
2426

src/core/value.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ end
1717

1818
@inline function refcheck(::Type{T}, ref::API.LLVMValueRef) where T<:Value
1919
ref==C_NULL && throw(UndefRefError())
20-
T′ = identify(Value, ref)
21-
if T != T′
22-
error("invalid conversion of $T′ value reference to $T")
20+
@static if Base.JLOptions().debug_level >= 2
21+
T′ = identify(Value, ref)
22+
if T != T′
23+
error("invalid conversion of $T′ value reference to $T")
24+
end
2325
end
2426
end
2527

test/core.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ Context() do ctx
3333
@test typeof(typ.ref) == LLVM.API.LLVMTypeRef # untyped
3434

3535
@test typeof(LLVM.IntegerType(typ.ref)) == LLVM.IntegerType # type reconstructed
36-
@test_throws ErrorException LLVM.FunctionType(typ.ref) # wrong type
36+
if Base.JLOptions().debug_level >= 2
37+
@test_throws ErrorException LLVM.FunctionType(typ.ref) # wrong type
38+
end
3739
@test_throws UndefRefError LLVM.FunctionType(LLVM.API.LLVMTypeRef(C_NULL))
3840

3941
@test typeof(typ.ref) == LLVM.API.LLVMTypeRef
@@ -202,7 +204,9 @@ LLVM.Module("SomeModule"; ctx) do mod
202204
@test typeof(val.ref) == LLVM.API.LLVMValueRef # untyped
203205

204206
@test typeof(LLVM.Instruction(val.ref)) == LLVM.AllocaInst # type reconstructed
205-
@test_throws ErrorException LLVM.Function(val.ref) # wrong
207+
if Base.JLOptions().debug_level >= 2
208+
@test_throws ErrorException LLVM.Function(val.ref) # wrong
209+
end
206210
@test_throws UndefRefError LLVM.Function(LLVM.API.LLVMValueRef(C_NULL))
207211

208212
@test typeof(Value(val.ref)) == LLVM.AllocaInst # type reconstructed

0 commit comments

Comments
 (0)