trait TypeOps

Constructors

Members

class AsSeenFromMap

The TypeMap handling the asSeenFrom in more complicated cases

The TypeMap handling the asSeenFrom in more complicated cases

class SimplifyMap
final object deskolemize

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

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 violate...

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

[+] 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 aspec...

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.

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.

The list of violations where arguments are not within bounds.

def canAutoTuple : Boolean

Is auto-tupling enabled?

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 rename...

    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 forwardRef ( argSym: Symbol , from: Symbol , to: TypeBounds , cls: ClassSymbol , decls: Scope ) : Unit

    If we have member definitions

    type argSym v= from type from v= to

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

    type argSym...

    If we have member definitions

    type argSym v= from type from v= to

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

    type argSym v= to

    unless a definition for argSym already exists in the current scope.

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

    Given a disjunction T1 | ... | Tn of types with potentially embedded type variables, constrain type variables further if this eliminates some of the bra...

    ArrayBuffer[Int] | ArrayBuffer[A]
    

    Given a disjunction T1 | ... | Tn of types with potentially embedded type variables, constrain type variables further if this eliminates some of the branches of the disjunction. Do this also for disjunctions embedded in intersections, as parents in refinements, and in recursive types.

    For instance, if A is an unconstrained type variable, then

    ArrayBuffer[Int] | ArrayBuffer[A]
    

    is approximated by constraining A to be =:= to Int and returning ArrayBuffer[Int] instead of ArrayBuffer[_ >: Int | A <: Int & A]

    private def isLegalPrefix ( pre: Type ) ( implicit ctx: Context ) : Boolean
    private def joinIfScala2 ( tp: Type ) : Type

    Under -language:Scala2: Replace or-types with their joins

    Under -language:Scala2: Replace or-types with their joins

    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
    

    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...

    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 in...

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

    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

    Implementation of Types#simplified

    def testScala2Mode ( msg: => String , pos: Position ) : Boolean