TypeRestriction

class TypeRestriction

This mechanism describes a restriction of a type without saying what it's to be applied to.

We capture an Avail A_Type, and an optional exactly known value, so that we can represent something that avoids the metacovariance weakness of metatypes.

We also capture negative type and negative instance information, to leverage more advantage from the failure paths of type tests like L2_JUMP_IF_KIND_OF_CONSTANT and L2_JUMP_IF_EQUALS_CONSTANT.

Author

Mark van Gulik

Todd L Smith

Types

Link copied to clipboard
object Companion
Link copied to clipboard

An enumeration used to interpret the flags of a TypeRestriction. The sense of the flags is such that a bit-wise and can be used

Link copied to clipboard
data class RestrictionGroup(    val constants: Set<A_BasicObject>?,     val types: Set<A_Type>,     val objectVariants: Set<ObjectLayoutVariant>?,     val objectTypeVariants: Set<ObjectLayoutVariant>?,     val tags: Set<TypeTag>?)

A collection of all positive or all negative constraints. A TypeRestriction uses one for positive constraints, and one for negative constraints, and canonicalization keeps them from being contradictory or nonsensical.

Functions

Link copied to clipboard
fun containedByType(testType: A_Type): Boolean

Answer true if this TypeRestriction only contains values that are within the given testType.

Link copied to clipboard
fun containsEntireType(testType: A_Type): Boolean

Answer true if this TypeRestriction contains every possible element of the given type.

Link copied to clipboard
fun enumerationValuesOrNull(maximumCount: Int): A_Set?

If this restriction has only a finite set of possible values, and the number of such values is no more than the given maximum, answer an A_Set of them, otherwise null.

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard
fun forBoxed(): TypeRestriction

Answer a restriction like the receiver, but for a boxed, mutable object. If the restriction is already for boxed objects, return the receiver, whether it's also marked with the immutable flag or not.

Link copied to clipboard
fun forUnboxedFloat(): TypeRestriction

Answer a restriction like the receiver, but for unboxed floats. If the restriction is already for unboxed floats, return the receiver.

Link copied to clipboard
fun forUnboxedInt(): TypeRestriction

Answer a restriction like the receiver, but for unboxed ints. If the restriction is already for unboxed ints, return the receiver.

Link copied to clipboard
fun hasFlag(restrictionFlag: TypeRestriction.RestrictionFlagEncoding): Boolean

Answer whether the specified flag is set.

Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
fun intersection(other: TypeRestriction): TypeRestriction

Create the intersection of the receiver and the other TypeRestriction. This is the restriction that a register would have if it were already known to have the first restriction, and has been tested positively against the second restriction.

Link copied to clipboard
fun intersectionWithObjectTypeVariant(variantToIntersect: ObjectLayoutVariant): TypeRestriction

Create the intersection of the receiver with the given object type variant ObjectLayoutVariant. This is the restriction that a register would have if it were already known to satisfy the receiver restriction, and has had its object type variant tested positively against the given variant.

Link copied to clipboard
fun intersectionWithObjectVariant(variantToIntersect: ObjectLayoutVariant): TypeRestriction

Create the intersection of the receiver with the given object variant ObjectLayoutVariant. This is the restriction that a register would have if it were already known to satisfy the receiver restriction, and has had its variant tested positively against the given variant.

Link copied to clipboard
fun intersectionWithType(typeToIntersect: A_Type): TypeRestriction

Create the intersection of the receiver with the given A_Type. This is the restriction that a register would have if it were already known to satisfy the receiver restriction, and has been tested positively against the given type.

Link copied to clipboard
fun intersectsType(testType: A_Type): Boolean

Answer true if this TypeRestriction contains any values in common with the given type. It uses the A_Type.isVacuousType test to determine whether any instances exist in the intersection.

Link copied to clipboard
fun isStrongerThan(other: TypeRestriction): Boolean

Answer whether this TypeRestriction is a specialization of the given one. That means every value that satisfies the receiver will also satisfy the argument.

Link copied to clipboard
fun kinds(): EnumSet<L2Register.RegisterKind>

Answer an EnumSet indicating which RegisterKinds are present in this restriction.

Link copied to clipboard
fun makeShared()

Ensure all referenced AvailObjects are Shared.

Link copied to clipboard
fun metaRestriction(): TypeRestriction

The receiver is a restriction for a register holding some value. Answer the restriction for a register holding that value's type.

Link copied to clipboard
fun minusObjectTypeVariant(variantToRemove: ObjectLayoutVariant): TypeRestriction

Create the difference between the receiver and the given object type variant ObjectLayoutVariant. This is the restriction that a register would have if it were already known to satisfy the receiver restriction, and has had its variant tested negatively against the supplied variant.

Link copied to clipboard
fun minusObjectVariant(variantToRemove: ObjectLayoutVariant): TypeRestriction

Create the difference between the receiver and the given object variant ObjectLayoutVariant. This is the restriction that a register would have if it were already known to satisfy the receiver restriction, and has had its variant tested negatively against the supplied variant.

Link copied to clipboard
fun minusType(typeToExclude: A_Type): TypeRestriction

Create the asymmetric difference of the receiver and the given A_Type. This is the restriction that a register would have if it held a value that satisfied the receiver, but failed a test against the given type.

Link copied to clipboard
fun minusValue(valueToExclude: A_BasicObject): TypeRestriction

Create the asymmetric difference of the receiver and the given exact value. This is the restriction that a register would have if it held a value that satisfied the receiver, but failed a value comparison against the given value.

Link copied to clipboard
fun minusValues(valuesToExclude: Iterable<A_BasicObject>): TypeRestriction

Create the asymmetric difference of the receiver and each of the given exact values. This is the restriction that a register would have if it held a value that satisfied the receiver, but failed a value comparison against each of the given values.

Link copied to clipboard
fun restrictingKindsTo(kinds: EnumSet<L2Register.RegisterKind>): TypeRestriction
fun restrictingKindsTo(kindFlagEncoding: Int): TypeRestriction

Answer a restriction like the receiver, but excluding RegisterKind-related flags that aren't set in the given kindFlagEncoding.

Link copied to clipboard
fun suffixString(): String

Answer a String, possibly empty, suitable for displaying after a register, after a read/write of a register, or after any other place that this restriction might be applied.

Link copied to clipboard
open override fun toString(): String
Link copied to clipboard
fun union(other: TypeRestriction): TypeRestriction

Create the union of the receiver and the other TypeRestriction. This is the restriction that a register would have if it were assigned from one of two sources, each having one of the restrictions.

Link copied to clipboard
fun withFlag(flagEncoding: TypeRestriction.RestrictionFlagEncoding): TypeRestriction

Answer a restriction like the receiver, but with an additional flag set. If the flag is already set, answer the receiver.

Link copied to clipboard
fun withoutFlag(flagEncoding: TypeRestriction.RestrictionFlagEncoding): TypeRestriction

Answer a restriction like the receiver, but with a flag cleared. If the flag is already clear, answer the receiver.

Properties

Link copied to clipboard
val constantOrNull: AvailObject?

Answer either the exact value, if known, or null.

Link copied to clipboard
val excludedTypes: Set<A_Type>

The set of types that are specifically excluded. A value that satisfies one of these types does not satisfy this type restriction. For the purpose of canonicalization, these types are all proper subtypes of the restriction's type.

Link copied to clipboard
val excludedValues: Set<A_BasicObject>

The set of values that are specifically excluded. A value in this set does not satisfy this type restriction. For the purpose of canonicalization, these values must all be members of the restriction's type.

Link copied to clipboard
val flags: Int

An Int that encodes RestrictionFlagEncodings.

Link copied to clipboard
val isBoxed: Boolean

Answer whether the restricted value is known to be boxed in an L2BoxedRegister.

Link copied to clipboard
val isImmutable: Boolean

Answer whether the restricted value is known to be immutable.

Link copied to clipboard
val isUnboxedFloat: Boolean

Answer whether the restricted value is known to be unboxed in an L2FloatRegister.

Link copied to clipboard
val isUnboxedInt: Boolean

Answer whether the restricted value is known to be unboxed in an L2IntRegister.

Link copied to clipboard
val negativeGroup: TypeRestriction.RestrictionGroup

The negative aspects of this restriction, generally consisting of sets of constraints that must not hold for the value under test.

Link copied to clipboard
val positiveGroup: TypeRestriction.RestrictionGroup

The positive aspects of this restriction, indicating an upper bound type, a constant if available, and other sets of constraints which the value under test are constrained to comply with.

Link copied to clipboard
val type: A_Type

Answer the base type of this restriction.