Skip to content

Commit

Permalink
Only initialize LLVM::Attribute's class variables on demand
Browse files Browse the repository at this point in the history
  • Loading branch information
HertzDevil committed Feb 28, 2025
1 parent 07552f6 commit a843606
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/llvm/enums.cr
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,24 @@ module LLVM
WriteOnly
ZExt

@@kind_ids = load_llvm_kinds_from_names.as(Hash(Attribute, UInt32))
@@typed_attrs = load_llvm_typed_attributes.as(Array(Attribute))
# NOTE: enum body does not allow `class_getter` or `TypeDeclaration`, hence
# the nil cast
@@kind_ids = nil.as(Hash(Attribute, UInt32)?)

private def self.kind_ids
@@kind_ids ||= load_llvm_kinds_from_names
end

@@typed_attrs = nil.as(Array(Attribute)?)

private def self.typed_attrs
@@typed_attrs ||= load_llvm_typed_attributes
end

def each_kind(& : UInt32 ->)
kind_ids = self.kind_ids

Check failure on line 76 in src/llvm/enums.cr

View workflow job for this annotation

GitHub Actions / LLVM 13

undefined method 'kind_ids' for LLVM::Attribute

Check failure on line 76 in src/llvm/enums.cr

View workflow job for this annotation

GitHub Actions / LLVM 14

undefined method 'kind_ids' for LLVM::Attribute

Check failure on line 76 in src/llvm/enums.cr

View workflow job for this annotation

GitHub Actions / LLVM 15

undefined method 'kind_ids' for LLVM::Attribute

Check failure on line 76 in src/llvm/enums.cr

View workflow job for this annotation

GitHub Actions / LLVM 16

undefined method 'kind_ids' for LLVM::Attribute

Check failure on line 76 in src/llvm/enums.cr

View workflow job for this annotation

GitHub Actions / LLVM 17

undefined method 'kind_ids' for LLVM::Attribute

Check failure on line 76 in src/llvm/enums.cr

View workflow job for this annotation

GitHub Actions / LLVM 18

undefined method 'kind_ids' for LLVM::Attribute

Check failure on line 76 in src/llvm/enums.cr

View workflow job for this annotation

GitHub Actions / LLVM 19

undefined method 'kind_ids' for LLVM::Attribute

Check failure on line 76 in src/llvm/enums.cr

View workflow job for this annotation

GitHub Actions / LLVM 20

undefined method 'kind_ids' for LLVM::Attribute

Check failure on line 76 in src/llvm/enums.cr

View workflow job for this annotation

GitHub Actions / x86_64-windows-release / build

undefined method 'kind_ids' for LLVM::Attribute
each do |member|
yield @@kind_ids[member]
yield kind_ids[member]
end
end

Expand Down Expand Up @@ -150,16 +162,16 @@ module LLVM
end

def self.kind_for(member)
@@kind_ids[member]
kind_ids[member]
end

def self.from_kind(kind)
@@kind_ids.key_for(kind)
kind_ids.key_for(kind)
end

def self.requires_type?(kind)
member = from_kind(kind)
@@typed_attrs.includes?(member)
typed_attrs.includes?(member)
end
end

Expand Down

0 comments on commit a843606

Please sign in to comment.