-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
There are currently 98 LLVM attributes, and this number is expected to increase. LLVM::Attribute in Crystal maintains only a subset of these, but LLVM could e.g. attach them to intrinsics at will, in which case the corresponding enum member must be present (see Captures in #15771). Yet, since LLVM::Attribute is a 64-bit flags enum, by definition it cannot represent every possible attribute, and increasing the underlying type to a 128-bit integer merely delays the onset of the issue.
IMO we should first define the attribute kinds in a new non-flags enum:
enum LLVM::AttributeKind
Alignment
AllocSize
AlwaysInline
# ...
endThen the old LLVM::Attribute will be served by a new bitset type:
struct LLVM::AttributeSet
@set = uninitialized UInt8[16] # enough to hold all `AttributeKind`s
# this is the same as the one in `Attribute`
private def self.load_llvm_kinds_from_names
# `get_last_enum_attribute_kind` is one past the greatest valid index
unless sizeof(@set) * 8 >= LibLLVM.get_last_enum_attribute_kind
raise "BUG: AttributeSet is not large enough!"
end
# ...
end
endAlternatively, the set-like behavior of LLVM attribute kinds might not be needed at all, and there would be bindings for individual attributes instead (e.g. EnumAttribute, StringAttribute). In either case LLVM::Attribute will be deprecated.