Skip to content

Commit 1cf66a5

Browse files
committed
Replace reftype lookup with hard-coded types.
1 parent 632e02c commit 1cf66a5

22 files changed

+39
-63
lines changed

src/buffer.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ export MemoryBuffer, MemoryBufferFile, dispose
33
@checked struct MemoryBuffer
44
ref::API.LLVMMemoryBufferRef
55
end
6-
reftype(::Type{MemoryBuffer}) = API.LLVMMemoryBufferRef
76

87
Base.unsafe_convert(::Type{API.LLVMMemoryBufferRef}, membuf::MemoryBuffer) = membuf.ref
98

src/core/attributes.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,18 @@ export Attribute,
66
kind, value
77

88
abstract type Attribute end
9-
reftype(::Type{T}) where {T<:Attribute} = API.LLVMAttributeRef
109

1110
Base.unsafe_convert(::Type{API.LLVMAttributeRef}, attr::Attribute) = attr.ref
1211

1312
@checked struct EnumAttribute <: Attribute
14-
ref::reftype(Attribute)
13+
ref::API.LLVMAttributeRef
1514
end
1615

1716
@checked struct StringAttribute <: Attribute
18-
ref::reftype(Attribute)
17+
ref::API.LLVMAttributeRef
1918
end
2019

21-
# TODO: make @reftype's identify mechanism flexible enough to cover cases like this one,
20+
# TODO: make the identify mechanism flexible enough to cover cases like this one,
2221
# and not only Value and Type
2322

2423
function Attribute(ref::API.LLVMAttributeRef)

src/core/basicblock.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export BasicBlock, unsafe_delete!,
33
move_before, move_after
44

55
@checked struct BasicBlock <: Value
6-
ref::reftype(Value)
6+
ref::API.LLVMValueRef
77
end
88
identify(::Type{Value}, ::Val{API.LLVMBasicBlockValueKind}) = BasicBlock
99

@@ -12,7 +12,7 @@ Base.unsafe_convert(::Type{API.LLVMBasicBlockRef}, bb::BasicBlock) = API.LLVMVal
1212

1313
# forward declarations
1414
@checked struct Function <: GlobalObject
15-
ref::reftype(GlobalObject)
15+
ref::API.LLVMValueRef
1616
end
1717

1818
BasicBlock(f::Function, name::String) =

src/core/context.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ export Context, dispose, GlobalContext
55
@checked struct Context
66
ref::API.LLVMContextRef
77
end
8-
reftype(::Type{Context}) = API.LLVMContextRef
98

109
Base.unsafe_convert(::Type{API.LLVMContextRef}, ctx::Context) = ctx.ref
1110

@@ -49,7 +48,6 @@ export DiagnosticInfo, severity, message
4948
@checked struct DiagnosticInfo
5049
ref::API.LLVMDiagnosticInfoRef
5150
end
52-
reftype(::Type{DiagnosticInfo}) = API.LLVMDiagnosticInfoRef
5351

5452
Base.unsafe_convert(::Type{API.LLVMDiagnosticInfoRef}, di::DiagnosticInfo) = di.ref
5553

src/core/function.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ end
7474
export Argument, parameters
7575

7676
@checked struct Argument <: Value
77-
ref::reftype(Value)
77+
ref::API.LLVMValueRef
7878
end
7979
identify(::Type{Value}, ::Val{API.LLVMArgumentValueKind}) = Argument
8080

src/core/instructions.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ Base.setindex!(md::InstructionMetadataDict, node::MetadataAsValue, kind::MD) =
9595
API.LLVMSetMetadata(md.inst, kind, node)
9696

9797
Base.delete!(md::InstructionMetadataDict, kind::MD) =
98-
API.LLVMSetMetadata(md.inst, kind,
99-
convert(reftype(MetadataAsValue), C_NULL))
98+
API.LLVMSetMetadata(md.inst, kind, C_NULL)
10099

101100

102101
## instruction types
@@ -116,7 +115,7 @@ for op in opcodes
116115
enum = Symbol(:LLVM, op)
117116
@eval begin
118117
@checked struct $typename <: Instruction
119-
ref::reftype(Instruction)
118+
ref::API.LLVMValueRef
120119
end
121120
identify(::Type{Instruction}, ::Val{API.$enum}) = $typename
122121
end

src/core/metadata.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export MDString, MDNode, operands, Metadata
22

33
@checked struct MetadataAsValue <: Value
4-
ref::reftype(Value)
4+
ref::API.LLVMValueRef
55
end
66
identify(::Type{Value}, ::Val{API.LLVMMetadataAsValueValueKind}) = MetadataAsValue
77

@@ -42,7 +42,6 @@ end
4242
@checked struct Metadata
4343
ref::API.LLVMMetadataRef
4444
end
45-
reftype(::Type{Metadata}) = API.LLVMMetadataRef
4645

4746
Base.unsafe_convert(::Type{API.LLVMMetadataRef}, md::Metadata) = md.ref
4847

src/core/module.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ export dispose,
88
set_used!, set_compiler_used!
99

1010
# forward definition of Module in src/core/value/constant.jl
11-
reftype(::Type{Module}) = API.LLVMModuleRef
1211

1312
Base.unsafe_convert(::Type{API.LLVMModuleRef}, mod::Module) = mod.ref
1413

src/core/type.jl

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ export LLVMType, issized, context, show
22

33
# subtypes are expected to have a 'ref::API.LLVMTypeRef' field
44
abstract type LLVMType end
5-
reftype(::Type{T}) where {T<:LLVMType} = API.LLVMTypeRef
65

76
Base.unsafe_convert(::Type{API.LLVMTypeRef}, typ::LLVMType) = typ.ref
87

@@ -44,7 +43,7 @@ Base.isempty(@nospecialize(T::LLVMType)) = false
4443
export width
4544

4645
@checked struct IntegerType <: LLVMType
47-
ref::reftype(LLVMType)
46+
ref::API.LLVMTypeRef
4847
end
4948
identify(::Type{LLVMType}, ::Val{API.LLVMIntegerTypeKind}) = IntegerType
5049

@@ -81,7 +80,7 @@ for T in [:Half, :Float, :Double]
8180
enumkind = Symbol(:LLVM, T, :TypeKind)
8281
@eval begin
8382
@checked struct $api_typename <: FloatingPointType
84-
ref::reftype(FloatingPointType)
83+
ref::API.LLVMTypeRef
8584
end
8685
identify(::Type{LLVMType}, ::Val{API.$enumkind}) = $api_typename
8786

@@ -97,7 +96,7 @@ end
9796
export isvararg, return_type, parameters
9897

9998
@checked struct FunctionType <: LLVMType
100-
ref::reftype(LLVMType)
99+
ref::API.LLVMTypeRef
101100
end
102101
identify(::Type{LLVMType}, ::Val{API.LLVMFunctionTypeKind}) = FunctionType
103102

@@ -136,7 +135,7 @@ Base.eltype(typ::SequentialType) = LLVMType(API.LLVMGetElementType(typ))
136135

137136

138137
@checked struct PointerType <: SequentialType
139-
ref::reftype(SequentialType)
138+
ref::API.LLVMTypeRef
140139
end
141140
identify(::Type{LLVMType}, ::Val{API.LLVMPointerTypeKind}) = PointerType
142141

@@ -149,7 +148,7 @@ addrspace(ptrtyp::PointerType) =
149148

150149

151150
@checked struct ArrayType <: SequentialType
152-
ref::reftype(SequentialType)
151+
ref::API.LLVMTypeRef
153152
end
154153
identify(::Type{LLVMType}, ::Val{API.LLVMArrayTypeKind}) = ArrayType
155154

@@ -163,7 +162,7 @@ Base.isempty(@nospecialize(T::ArrayType)) = length(T) == 0 || isempty(eltype(T))
163162

164163

165164
@checked struct VectorType <: SequentialType
166-
ref::reftype(SequentialType)
165+
ref::API.LLVMTypeRef
167166
end
168167
identify(::Type{LLVMType}, ::Val{API.LLVMVectorTypeKind}) = VectorType
169168

@@ -179,7 +178,7 @@ Base.size(vectyp::VectorType) = API.LLVMGetVectorSize(vectyp)
179178
export name, ispacked, isopaque, elements!
180179

181180
@checked struct StructType <: SequentialType
182-
ref::reftype(SequentialType)
181+
ref::API.LLVMTypeRef
183182
end
184183
identify(::Type{LLVMType}, ::Val{API.LLVMStructTypeKind}) = StructType
185184

@@ -243,7 +242,7 @@ end
243242
## other
244243

245244
@checked struct VoidType <: LLVMType
246-
ref::reftype(LLVMType)
245+
ref::API.LLVMTypeRef
247246
end
248247
identify(::Type{LLVMType}, ::Val{API.LLVMVoidTypeKind}) = VoidType
249248

@@ -252,7 +251,7 @@ VoidType(ctx::Context) =
252251
VoidType(API.LLVMVoidTypeInContext(ctx))
253252

254253
@checked struct LabelType <: LLVMType
255-
ref::reftype(LLVMType)
254+
ref::API.LLVMTypeRef
256255
end
257256
identify(::Type{LLVMType}, ::Val{API.LLVMLabelTypeKind}) = LabelType
258257

@@ -261,15 +260,15 @@ LabelType(ctx::Context) =
261260
LabelType(API.LLVMLabelTypeInContext(ctx))
262261

263262
@checked struct MetadataType <: LLVMType
264-
ref::reftype(LLVMType)
263+
ref::API.LLVMTypeRef
265264
end
266265
identify(::Type{LLVMType}, ::Val{API.LLVMMetadataTypeKind}) = MetadataType
267266

268267
MetadataType(ctx::Context) =
269268
MetadataType(API.LLVMMetadataTypeInContext(ctx))
270269

271270
@checked struct TokenType <: LLVMType
272-
ref::reftype(LLVMType)
271+
ref::API.LLVMTypeRef
273272
end
274273
identify(::Type{LLVMType}, ::Val{API.LLVMTokenTypeKind}) = TokenType
275274

src/core/value.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ export Value
55

66
# subtypes are expected to have a 'ref::API.LLVMValueRef' field
77
abstract type Value end
8-
reftype(::Type{T}) where {T<:Value} = API.LLVMValueRef
98

109
Base.unsafe_convert(::Type{API.LLVMValueRef}, val::Value) = val.ref
1110

@@ -72,7 +71,6 @@ export Use, user, value
7271
@checked struct Use
7372
ref::API.LLVMUseRef
7473
end
75-
reftype(::Type{Use}) = API.LLVMUseRef
7674

7775
Base.unsafe_convert(::Type{API.LLVMUseRef}, use::Use) = use.ref
7876

0 commit comments

Comments
 (0)