Dotty Documentation

0.4.0-bin-SNAPSHOT

class OrderingConstraint
extends Constraint

Constraint over undetermined type parameters that keeps separate maps to reflect parameter orderings.

[-] Constructors

OrderingConstraint ( boundsMap: ParamBounds , lowerMap: ParamOrdering , upperMap: ParamOrdering )

[-] Members

[+] type This = OrderingConstraint
[+] private val boundsMap : ParamBounds
[+] private val lowerMap : ParamOrdering
[+] private var myUninstVars : ArrayBuffer [ TypeVar ]
[+] private val upperMap : ParamOrdering
[+] def & ( other: Constraint ) ( implicit ctx: Context ) : Constraint

The weakest constraint that subsumes both this constraint and other

[+] def add ( poly: TypeLambda , tvars: List [ TypeVar ] ) ( implicit ctx: Context ) : This

A new constraint which is derived from this constraint by adding entries for all type parameters of poly.

[+] def addLess ( param1: TypeParamRef , param2: TypeParamRef ) ( implicit ctx: Context ) : This

A constraint that includes the relationship p1 <: p2. <: relationships between parameters ("edges") are propagated, but non-parameter bounds are left alone.

[+] override def checkClosed ( ) ( implicit ctx: Context ) : Unit

Check that constraint only refers to TypeParamRefs bound by itself

[+] def checkNonCyclic ( ) ( implicit ctx: Context ) : Unit

Check that no constrained parameter contains itself as a bound

[+] private def checkNonCyclic ( param: TypeParamRef ) ( implicit ctx: Context ) : Unit
[+] def contains ( pt: TypeLambda ) : Boolean

Does the constraint's domain contain the type parameters of pt?

[+] def contains ( param: TypeParamRef ) : Boolean

Does the constraint's domain contain the type parameter param?

[+] def contains ( tvar: TypeVar ) : Boolean

Does this constraint contain the type variable tvar and is it uninstantiated?

[+] def dependentParams ( tp: Type , isUpper: Boolean ) : List [ TypeParamRef ]

The list of parameters P such that, for a fresh type parameter Q:

Q <: tp implies Q <: P and isUpper = true, or tp <: Q implies P <: Q and isUpper = false

[+] def domainLambdas : List [ TypeLambda ]

The type lambdas constrained by this constraint

[+] def domainParams : List [ TypeParamRef ]

The type lambda parameters constrained by this constraint

[+] def entry ( param: TypeParamRef ) : Type

The boundsMap entry corresponding to param

[+] def exclusiveLower ( param: TypeParamRef , butNot: TypeParamRef ) : List [ TypeParamRef ]

lower(param) \ lower(butNot)

[+] def exclusiveUpper ( param: TypeParamRef , butNot: TypeParamRef ) : List [ TypeParamRef ]

upper(param) \ upper(butNot)

[+] def forallParams ( p: TypeParamRef => Boolean ) : Boolean

Check whether predicate holds for all parameters in constraint

[+] def foreachParam ( p: (TypeLambda, Int) => Unit ) : Unit
[+] def foreachTypeVar ( op: TypeVar => Unit ) : Unit

Perform operation op on all typevars, or only on uninstantiated typevars, depending on whether uninstOnly is set or not.

[+] def fullBounds ( param: TypeParamRef ) ( implicit ctx: Context ) : TypeBounds

The bounds of param including all known-to-be-smaller and -greater parameters

[+] def fullLowerBound ( param: TypeParamRef ) ( implicit ctx: Context ) : Type

The lower bound of param including all known-to-be-smaller parameters

[+] def fullUpperBound ( param: TypeParamRef ) ( implicit ctx: Context ) : Type

The upper bound of param including all known-to-be-greater parameters

[+] private def init ( poly: TypeLambda ) ( implicit ctx: Context ) : This

Split dependent parameters off the bounds for parameters in poly. Update all bounds to be normalized and update ordering to account for dependent parameters.

[+] private def isBounds ( tp: Type ) : Boolean
[+] def isLess ( param1: TypeParamRef , param2: TypeParamRef ) : Boolean

Is it known that param1 <:< param2?

[+] def isRemovable ( pt: TypeLambda ) : Boolean

Is entry associated with pt removable? This is the case if all type parameters of the entry are associated with type variables which have their inst fields set.

[+] def lower ( param: TypeParamRef ) : List [ TypeParamRef ]

The parameters that are known to be smaller wrt <: than param

[+] def minLower ( param: TypeParamRef ) : List [ TypeParamRef ]
[+] def minUpper ( param: TypeParamRef ) : List [ TypeParamRef ]
[+] private def myUninstVars_= ( x$1: ArrayBuffer [ TypeVar ] ) : Unit
[+] def nonParamBounds ( param: TypeParamRef ) : TypeBounds

The constraint bounds for given type parameter param. Poly params that are known to be smaller or greater than param are not contained in the return bounds.

[+] private def normalizedType ( tp: Type , paramBuf: ListBuffer [ TypeParamRef ] , isUpper: Boolean ) ( implicit ctx: Context ) : Type

The bound type tp without clearly dependent parameters. A top or bottom type if type consists only of dependent parameters.

[+] private def order ( current: This , param1: TypeParamRef , param2: TypeParamRef ) ( implicit ctx: Context ) : This

Add the fact param1 <: param2 to the constraint current and propagate <:< relationships between parameters ("edges") but not bounds.

[+] private def paramCount ( entries: Array [ Type ] ) : Int

The number of type parameters in the given entry array

[+] def remove ( pt: TypeLambda ) ( implicit ctx: Context ) : This

A new constraint with all entries coming from pt removed.

[+] def replace ( param: TypeParamRef , tp: Type ) ( implicit ctx: Context ) : OrderingConstraint

A new constraint which is derived from this constraint by removing the type parameter param from the domain and replacing all top-level occurrences of the parameter elsewhere in the constraint by type tp, or a conservative approximation of it if that is needed to avoid cycles. Occurrences nested inside a refinement or prefix are not affected.

The reason we need to substitute top-level occurrences of the parameter is to deal with situations like the following. Say we have in the constraint

P <: Q & String
Q

and we replace Q with P. Then substitution gives

P <: P & String

this would be a cyclic constraint is therefore changed by normalize and recombine below to

P <: String

approximating the RHS occurrence of P with Any. Without the substitution we would not find out where we need to approximate. Occurrences of parameters that are not top-level are not affected.

[+] private def stripParams ( tp: Type , paramBuf: ListBuffer [ TypeParamRef ] , isUpper: Boolean ) ( implicit ctx: Context ) : Type

The bound type tp without constrained parameters which are clearly dependent. A parameter in an upper bound is clearly dependent if it appears in a hole of a context H given by:

H = []
    H & T
    T & H

(the idea is that a parameter P in a H context is guaranteed to be a supertype of the bounded parameter.) Analogously, a parameter in a lower bound is clearly dependent if it appears in a hole of a context H given by:

L = []
    L | T
    T | L

"Clearly dependent" is not synonymous with "dependent" in the sense it is defined in dependentParams. Dependent parameters are handled in updateEntry. The idea of stripping off clearly dependent parameters and to handle them separately is for efficiency, so that type expressions used as bounds become smaller.

[+] override def toString : String
[+] override def toText ( printer: Printer ) : Text

The text representation of this showable element. This normally dispatches to a pattern matching method in Printers.

[+] private def typeVar ( entries: Array [ Type ] , n: Int ) : Type

The type variable corresponding to parameter numbered n, null if none was created

[+] def typeVarOfParam ( param: TypeParamRef ) : Type

The type variable corresponding to parameter param, or NoType, if param is not in constrained or is not paired with a type variable.

[+] def unify ( p1: TypeParamRef , p2: TypeParamRef ) ( implicit ctx: Context ) : This

A constraint resulting from adding p2 = p1 to this constraint, and at the same time transferring all bounds of p2 to p1

[+] def uninstVars : Seq [ TypeVar ]

The uninstantiated typevars of this constraint

[+] def updateEntry ( current: This , param: TypeParamRef , tp: Type ) ( implicit ctx: Context ) : This
[+] def updateEntry ( param: TypeParamRef , tp: Type ) ( implicit ctx: Context ) : This

A new constraint which is derived from this constraint by updating the entry for parameter param to tp. tp can be one of the following:

  • A TypeBounds value, indicating new constraint bounds
  • Another type, indicating a solution for the parameter
[+] def upper ( param: TypeParamRef ) : List [ TypeParamRef ]

The parameters that are known to be greater wrt <: than param