Skip to content

class Crystal::LLVMId
inherits Reference

This class assigns a pair of IDs {min, max} to every type in the program.

For a regular class or struct (not metaclass), this pair of ids is such that min is the minimum ID of its subtypes, and max is 1 + the maximum ID of its subtypes. In this way we can quickly know if a type implements another type: its ID must be between {min, max} of such type.

For example, ids could be assigned like this:

  • Foo: {1, 8}
  • Bar: {1, 2}
    • Baz: {1, 1}
  • Qux: {3, 3}
  • Gen(T): {5, 7}
    • Gen(Int32): {4, 4}
    • Gen2(T): {5, 6}
    • Gen2(Char): {5, 5}

Note that generic instances and generic subtypes are considered as subtypes of a generic type.

For metaclasses IDs are assigned sequentially as they are needed, because dispatch on metaclasses is less often.

Class methods

.new(program)

View source

Methods

#id_to_metaclass : Hash(Int32, Int32)

View source

#min_max_type_id(type)

View source

#type_id(type : TypeDefType)

View source

#type_id(type)

View source