Dotty Documentation

0.2.0-bin-SNAPSHOT

trait TypeOps

[-] Constructors

[-] Members

[+] class AsSeenFromMap

The TypeMap handling the asSeenFrom in more complicated cases

[+] class SimplifyMap
[+] object deskolemize

Approximate a type tp with a type that does not contain skolem types.

[+] type BoundsViolation = ( Tree, String, Type )

An argument bounds violation is a triple consisting of - the argument tree - a string "upper" or "lower" indicating which bound is violated - the violated bound

[+] def allBaseTypeArgs ( cls: ClassSymbol ) ( implicit ctx: Context ) : List [ Symbol ]

Used only for debugging: All BaseTypeArg definitions in cls and all its base classes.

[+] final def asSeenFrom ( tp: Type , pre: Type , cls: Symbol ) : Type

The type tp as seen from prefix pre and owner cls. See the spec for what this means. Called very often, so the code is optimized heavily.

A tricky aspect is what to do with unstable prefixes. E.g. say we have a class

class C { type T; def f(x: T): T }

and an expression e of type C. Then computing the type of e.f leads to the query asSeenFrom(C, (x: T)T). What should its result be? The naive answer (x: C#T)C#T is incorrect given that we treat C#T as the existential exists(c: C)c.T. What we need to do instead is to skolemize the existential. So the answer would be (x: c.T)c.T for some (unknown) value c of type C. c.T is expressed in the compiler as a skolem type Skolem(C).

Now, skolemization is messy and expensive, so we want to do it only if we absolutely must. Also, skolemizing immediately would mean that asSeenFrom was no longer idempotent - each call would return a type with a different skolem. Instead we produce an annotated type that marks the prefix as unsafe:

(x: (C @ UnsafeNonvariant)#T)C#T

We also set a global state flag unsafeNonvariant to the current run. When typing a Select node, typer will check that flag, and if it points to the current run will scan the result type of the select for

[+] private def asSeenFrom ( tp: Type , pre: Type , cls: Symbol , theMap: AsSeenFromMap ) : Type

Helper method, taking a map argument which is instantiated only for more complicated cases of asSeenFrom.

[+] def boundsViolations ( args: List [ Tree ] , boundss: List [ TypeBounds ] , instantiate: (Type, List [ Type ]) => Type ) ( implicit ctx: Context ) : List [ BoundsViolation ]

The list of violations where arguments are not within bounds.

[+] def canAutoTuple : Boolean

Is auto-tupling enabled?

[+] def dynamicsEnabled : Boolean
[+] private def enterArgBinding ( formal: Symbol , info: Type , cls: ClassSymbol , decls: Scope ) : Unit
[+] def featureEnabled ( owner: ClassSymbol , feature: TermName ) : Boolean

Is feature enabled in class owner? This is the case if one of the following two alternatives holds:

  1. The feature is imported by a named import

    import owner.feature

(the feature may be bunched with others, or renamed, but wildcard imports don't count).

  1. The feature is enabled by a compiler option

    • language:feature

where is the full name of the owner followed by a "." minus the prefix "dotty.language.".

[+] def forwardParamBindings ( parentRefs: List [ TypeRef ] , paramBindings: SimpleMap [ TypeName, Type ] , cls: ClassSymbol , decls: Scope ) ( implicit ctx: Context ) : Unit

Forward parameter bindings in baseclasses to argument types of class cls if possible. If there have member definitions

type param v= middle type middle v= to

where the variances of both alias are the same, then enter a new definition

type param v= to

If multiple forwarders would be generated, join their to types with an &.

[+] private def isLegalPrefix ( pre: Type ) ( implicit ctx: Context ) : Boolean
[+] def makePackageObjPrefixExplicit ( tpe: NamedType ) : Type

If tpe is of the form p.x where p refers to a package but x is not owned by a package, expand it to

p.package.x
[+] def normalizeToClassRefs ( parents: List [ Type ] , cls: ClassSymbol , decls: Scope ) : List [ TypeRef ]

Normalize a list of parent types of class cls that may contain refinements to a list of typerefs referring to classes, by converting all refinements to member definitions in scope decls. Can add members to decls as a side-effect.

[+] def orDominator ( tp: Type ) : Type

Approximate union type by intersection of its dominators. That is, replace a union type Tn | ... | Tn by the smallest intersection type of base-class instances of T1,...,Tn. Example: Given

trait C[+T]
trait D
class A extends C[A] with D
class B extends C[B] with D with E

we approximate A | B by C[A | B] with D

[+] def scala2Mode : Boolean
[+] final def simplify ( tp: Type , theMap: SimplifyMap ) : Type

Implementation of Types#simplified

[+] def testScala2Mode ( msg: => String , pos: Position , rewrite: => Unit ) : Boolean