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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic EnumOptimizationInfo
Create enum optimization info for a dense, exhaustive switch.static EnumOptimizationInfo
Create enum optimization info for a dense switch with default case.static EnumOptimizationInfo
Create enum optimization info for a sparse switch with default case.Returns the value of theenumOrdinals
record component.enumType()
Returns the value of theenumType
record component.Returns the value of theenumValues
record component.final boolean
Indicates whether some other object is "equal to" this one.double
Calculate the density ratio of this enum switch.int
Get the maximum ordinal value in this switch.int
Get the minimum ordinal value in this switch.int
Get the ordinal range span (max - min + 1).final int
hashCode()
Returns a hash code value for this object.boolean
isDense()
Returns the value of theisDense
record component.boolean
Returns the value of theisExhaustive
record component.boolean
Determine if this enum switch is suitable for jump table optimization.toString()
IR-optimized toString following EK9's bracket-only, no-indentation format.
-
Constructor Details
-
EnumOptimizationInfo
public EnumOptimizationInfo(String enumType, List<String> enumValues, List<Integer> enumOrdinals, boolean isExhaustive, boolean isDense) Creates an instance of aEnumOptimizationInfo
record class.- Parameters:
enumType
- the value for theenumType
record componentenumValues
- the value for theenumValues
record componentenumOrdinals
- the value for theenumOrdinals
record componentisExhaustive
- the value for theisExhaustive
record componentisDense
- the value for theisDense
record 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 thecompare
method from their corresponding wrapper classes. -
enumType
Returns the value of theenumType
record component.- Returns:
- the value of the
enumType
record component
-
enumValues
-
enumOrdinals
-
isExhaustive
public boolean isExhaustive()Returns the value of theisExhaustive
record component.- Returns:
- the value of the
isExhaustive
record component
-
isDense
public boolean isDense()Returns the value of theisDense
record component.- Returns:
- the value of the
isDense
record component
-