Record Class EnumOptimizationInfo

java.lang.Object
java.lang.Record
org.ek9lang.compiler.ir.EnumOptimizationInfo

public record EnumOptimizationInfo(String enumType, List<String> enumValues, List<Integer> enumOrdinals, boolean isExhaustive, boolean isDense) extends Record
Record containing optimization information for enum-based switch statements.

Provides backends with comprehensive metadata to enable aggressive optimizations: - Jump table generation for dense enum ranges - Binary search for sparse enum cases - Bounds checking optimization for exhaustive switches - Dead code elimination for unreachable cases

This information enables backends to choose optimal code generation strategies while preserving the sequential evaluation semantics of EK9 switch statements.

  • Constructor Details

    • EnumOptimizationInfo

      public EnumOptimizationInfo(String enumType, List<String> enumValues, List<Integer> enumOrdinals, boolean isExhaustive, boolean isDense)
      Creates an instance of a EnumOptimizationInfo record class.
      Parameters:
      enumType - the value for the enumType record component
      enumValues - the value for the enumValues record component
      enumOrdinals - the value for the enumOrdinals record component
      isExhaustive - the value for the isExhaustive record component
      isDense - the value for the isDense record component
  • Method Details

    • createDenseExhaustive

      public static EnumOptimizationInfo createDenseExhaustive(String enumType, List<String> enumValues, List<Integer> enumOrdinals)
      Create enum optimization info for a dense, exhaustive switch. Optimal case for jump table generation.
    • createSparseWithDefault

      public static EnumOptimizationInfo createSparseWithDefault(String enumType, List<String> enumValues, List<Integer> enumOrdinals)
      Create enum optimization info for a sparse switch with default case. Better suited for sequential evaluation or binary search.
    • createDenseWithDefault

      public static EnumOptimizationInfo createDenseWithDefault(String enumType, List<String> enumValues, List<Integer> enumOrdinals)
      Create enum optimization info for a dense switch with default case. Could benefit from jump table with bounds check for default.
    • isJumpTableCandidate

      public boolean isJumpTableCandidate()
      Determine if this enum switch is suitable for jump table optimization. Considers both density and the number of cases.
    • getDensityRatio

      public double getDensityRatio()
      Calculate the density ratio of this enum switch. Returns percentage of ordinal range that is covered by cases.
    • getMinOrdinal

      public int getMinOrdinal()
      Get the minimum ordinal value in this switch.
    • getMaxOrdinal

      public int getMaxOrdinal()
      Get the maximum ordinal value in this switch.
    • getOrdinalRange

      public int getOrdinalRange()
      Get the ordinal range span (max - min + 1).
    • toString

      public String toString()
      IR-optimized toString following EK9's bracket-only, no-indentation format.
      Specified by:
      toString in class Record
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • enumType

      public String enumType()
      Returns the value of the enumType record component.
      Returns:
      the value of the enumType record component
    • enumValues

      public List<String> enumValues()
      Returns the value of the enumValues record component.
      Returns:
      the value of the enumValues record component
    • enumOrdinals

      public List<Integer> enumOrdinals()
      Returns the value of the enumOrdinals record component.
      Returns:
      the value of the enumOrdinals record component
    • isExhaustive

      public boolean isExhaustive()
      Returns the value of the isExhaustive record component.
      Returns:
      the value of the isExhaustive record component
    • isDense

      public boolean isDense()
      Returns the value of the isDense record component.
      Returns:
      the value of the isDense record component