Record Class EnumOptimizationDetails
java.lang.Object
java.lang.Record
org.ek9lang.compiler.ir.data.EnumOptimizationDetails
public record EnumOptimizationDetails(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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic EnumOptimizationDetailsCreate enum optimization info for a dense, exhaustive switch.static EnumOptimizationDetailsCreate enum optimization info for a dense switch with default case.static EnumOptimizationDetailsCreate enum optimization info for a sparse switch with default case.Returns the value of theenumOrdinalsrecord component.enumType()Returns the value of theenumTyperecord component.Returns the value of theenumValuesrecord component.final booleanIndicates whether some other object is "equal to" this one.doubleCalculate the density ratio of this enum switch.intGet the maximum ordinal value in this switch.intGet the minimum ordinal value in this switch.intGet the ordinal range span (max - min + 1).final inthashCode()Returns a hash code value for this object.booleanisDense()Returns the value of theisDenserecord component.booleanReturns the value of theisExhaustiverecord component.booleanDetermine if this enum switch is suitable for jump table optimization.toString()IR-optimized toString following EK9's bracket-only, no-indentation format.
-
Constructor Details
-
EnumOptimizationDetails
public EnumOptimizationDetails(String enumType, List<String> enumValues, List<Integer> enumOrdinals, boolean isExhaustive, boolean isDense) Creates an instance of aEnumOptimizationDetailsrecord class.- Parameters:
enumType- the value for theenumTyperecord componentenumValues- the value for theenumValuesrecord componentenumOrdinals- the value for theenumOrdinalsrecord componentisExhaustive- the value for theisExhaustiverecord componentisDense- the value for theisDenserecord component
-
-
Method Details
-
createDenseExhaustive
-
createSparseWithDefault
-
createDenseWithDefault
-
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
-
hashCode
-
equals
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 withObjects::equals(Object,Object); primitive components are compared with thecomparemethod from their corresponding wrapper classes. -
enumType
Returns the value of theenumTyperecord component.- Returns:
- the value of the
enumTyperecord component
-
enumValues
-
enumOrdinals
-
isExhaustive
public boolean isExhaustive()Returns the value of theisExhaustiverecord component.- Returns:
- the value of the
isExhaustiverecord component
-
isDense
public boolean isDense()Returns the value of theisDenserecord component.- Returns:
- the value of the
isDenserecord component
-