CaptureChecker

dotty.tools.dotc.cc.CheckCaptures.CaptureChecker
class CaptureChecker(ictx: Context) extends Rechecker

Attributes

Graph
Supertypes
class Rechecker
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

def adaptBoxed(actual: Type, expected: Type, pos: SrcPos, alwaysConst: Boolean)(using Context): Type

Adapt actual type to expected type by inserting boxing and unboxing conversions

Adapt actual type to expected type by inserting boxing and unboxing conversions

Value parameters

alwaysConst

always make capture set variables constant after adaptation

Attributes

def assertSub(cs1: CaptureSet, cs2: CaptureSet)(using Context): Unit

Assert subcapturing cs1 <: cs2

Assert subcapturing cs1 <: cs2

Attributes

If sym is a class or method nested inside a term, a capture set variable representing the captured variables of the environment associated with sym.

If sym is a class or method nested inside a term, a capture set variable representing the captured variables of the environment associated with sym.

Attributes

override def checkConformsExpr(actual: Type, expected: Type, tree: Tree)(using Context): Unit

Massage actual and expected types using the methods below before checking conformance

Massage actual and expected types using the methods below before checking conformance

Attributes

Definition Classes
def checkElem(elem: CaptureRef, cs: CaptureSet, pos: SrcPos)(using Context): Unit

Check subcapturing {elem} <: cs, report error on failure

Check subcapturing {elem} <: cs, report error on failure

Attributes

Check overrides again, taking capture sets into account. TODO: Can we avoid doing overrides checks twice? We need to do them here since only at this phase CaptureTypes are relevant But maybe we can then elide the check during the RefChecks phase under captureChecking?

Check overrides again, taking capture sets into account. TODO: Can we avoid doing overrides checks twice? We need to do them here since only at this phase CaptureTypes are relevant But maybe we can then elide the check during the RefChecks phase under captureChecking?

Attributes

def checkSelfTypes(unit: Tree)(using Context): Unit

Check that self types of subclasses conform to self types of super classes. (See comment below how this is achieved). The check assumes that classes without an explicit self type have the universal capture set {cap} on the self type. If a class without explicit self type is not effectivelyFinal it is checked that the inferred self type is universal, in order to assure that joint and separate compilation give the same result.

Check that self types of subclasses conform to self types of super classes. (See comment below how this is achieved). The check assumes that classes without an explicit self type have the universal capture set {cap} on the self type. If a class without explicit self type is not effectivelyFinal it is checked that the inferred self type is universal, in order to assure that joint and separate compilation give the same result.

Attributes

def checkSubset(cs1: CaptureSet, cs2: CaptureSet, pos: SrcPos)(using Context): Unit

Check subcapturing cs1 <: cs2, report error on failure

Check subcapturing cs1 <: cs2, report error on failure

Attributes

override def checkUnit(unit: CompilationUnit)(using Context): Unit

Attributes

Definition Classes
def forallOuterEnvsUpTo(limit: Symbol)(op: Env => Unit)(using Context): Unit

For all nested environments up to limit or a closed environment perform op, but skip environmenrts directly enclosing environments of kind ClosureResult.

For all nested environments up to limit or a closed environment perform op, but skip environmenrts directly enclosing environments of kind ClosureResult.

Attributes

def includeCallCaptures(sym: Symbol, pos: SrcPos)(using Context): Unit

Include references captured by the called method in the current environment stack

Include references captured by the called method in the current environment stack

Attributes

override def instantiate(mt: MethodType, argTypes: List[Type], sym: Symbol)(using Context): Type

Handle an application of method sym with type mt to arguments of types argTypes. This means:

Handle an application of method sym with type mt to arguments of types argTypes. This means:

  • Instantiate result type with actual arguments
  • If call is to a constructor:
    • remember types of arguments corresponding to tracked parameters in refinements.
    • add capture set of instantiated class to capture set of result type.

Attributes

Definition Classes
override def keepType(tree: Tree): Boolean

Should type of tree be kept in an attachment so that it can be retrieved with knownType? By default true only is keepAllTypes hold, but can be overridden.

Should type of tree be kept in an attachment so that it can be retrieved with knownType? By default true only is keepAllTypes hold, but can be overridden.

Attributes

Definition Classes
def markFree(sym: Symbol, pos: SrcPos)(using Context): Unit

Include sym in the capture sets of all enclosing environments nested in the the environment in which sym is defined.

Include sym in the capture sets of all enclosing environments nested in the the environment in which sym is defined.

Attributes

def markFree(cs: CaptureSet, pos: SrcPos)(using Context): Unit

Make sure (projected) cs is a subset of the capture sets of all enclosing environments. At each stage, only include references from cs that are outside the environment's owner

Make sure (projected) cs is a subset of the capture sets of all enclosing environments. At each stage, only include references from cs that are outside the environment's owner

Attributes

def postCheck(unit: Tree)(using Context): Unit

Perform the following kinds of checks

Perform the following kinds of checks

  • Check all explicitly written capturing types for well-formedness using checkWellFormedPost.
  • Check that externally visible vals or defs have empty capture sets. If not, suggest an explicit type. This is so that separate compilation (where external symbols have empty capture sets) gives the same results as joint compilation.
  • Check that arguments of TypeApplys and AppliedTypes conform to their bounds.
  • Heal ill-formed capture sets of type parameters. See healTypeParam.

Attributes

override def recheck(tree: Tree, pt: Type)(using Context): Type

If expected type pt is boxed and the tree is a function or a reference, don't propagate free variables. Otherwise, if the result type is boxed, simulate an unboxing by adding all references in the boxed capture set to the current environment.

If expected type pt is boxed and the tree is a function or a reference, don't propagate free variables. Otherwise, if the result type is boxed, simulate an unboxing by adding all references in the boxed capture set to the current environment.

Attributes

Definition Classes
override def recheckApply(tree: Apply, pt: Type)(using Context): Type

A specialized implementation of the apply rule.

A specialized implementation of the apply rule.

E |- f: Ra ->Cf Rr^Cr E |- a: Ra^Ca

E |- f a: Rr^C

The implementation picks as C one of {f, a} or Cr, depending on the outcome of a mightSubcapture test. It picks {f, a} if this might subcapture Cr and Cr otherwise.

Attributes

Definition Classes
override def recheckBlock(block: Block, pt: Type)(using Context): Type

Additionally to normal processing, update types of closures if the expected type is a function with only pure parameters. In that case, make the anonymous function also have the same parameters as the prototype. TODO: Develop a clearer rationale for this. TODO: Can we generalize this to arbitrary parameters? Currently some tests fail if we do this. (e.g. neg.../stackAlloc.scala, others)

Additionally to normal processing, update types of closures if the expected type is a function with only pure parameters. In that case, make the anonymous function also have the same parameters as the prototype. TODO: Develop a clearer rationale for this. TODO: Can we generalize this to arbitrary parameters? Currently some tests fail if we do this. (e.g. neg.../stackAlloc.scala, others)

Attributes

Definition Classes
override def recheckClassDef(tree: TypeDef, impl: Template, cls: ClassSymbol)(using Context): Type

Class-specific capture set relations:

Class-specific capture set relations:

  1. The capture set of a class includes the capture sets of its parents.
  2. The capture set of the self type of a class includes the capture set of the class.
  3. The capture set of the self type of a class includes the capture set of every class parameter, unless the parameter is marked @constructorOnly.
  4. If the class extends a pure base class, the capture set of the self type must be empty.

Attributes

Definition Classes
override def recheckClosure(tree: Closure, pt: Type)(using Context): Type

Attributes

Definition Classes
override def recheckDefDef(tree: DefDef, sym: Symbol)(using Context): Unit

Attributes

Definition Classes
override def recheckFinish(tpe: Type, tree: Tree, pt: Type)(using Context): Type

If tree is a reference or an application where the result type refers to an enclosing class or method parameter of the reference, check that the result type does not capture the universal capability. This is justified since the result type would have to be implicitly unboxed. TODO: Can we find a cleaner way to achieve this? Logically, this should be part of simulated boxing and unboxing.

If tree is a reference or an application where the result type refers to an enclosing class or method parameter of the reference, check that the result type does not capture the universal capability. This is justified since the result type would have to be implicitly unboxed. TODO: Can we find a cleaner way to achieve this? Logically, this should be part of simulated boxing and unboxing.

Attributes

Definition Classes
override def recheckIdent(tree: Ident)(using Context): Type

Attributes

Definition Classes
override def recheckSelection(tree: Select, qualType: Type, name: Name, pt: Type)(using Context): Type

A specialized implementation of the selection rule.

A specialized implementation of the selection rule.

E |- f: f{ m: Cr R }^Cf

E |- f.m: R^C

The implementation picks as C one of {f} or Cr, depending on the outcome of a mightSubcapture test. It picks {f} if this might subcapture Cr and Cr otherwise.

Attributes

Definition Classes
override def recheckTry(tree: Try, pt: Type)(using Context): Type

Attributes

Definition Classes
override def recheckTyped(tree: Typed)(using Context): Type

If type is of the form T @requiresCapability(x), mark x as free in the current environment. This is used to require the correct CanThrow capability when encountering a throw.

If type is of the form T @requiresCapability(x), mark x as free in the current environment. This is used to require the correct CanThrow capability when encountering a throw.

Attributes

Definition Classes
override def recheckValDef(tree: ValDef, sym: Symbol)(using Context): Unit

Attributes

Definition Classes

Inherited methods

def checkConforms(tpe: Type, pt: Type, tree: Tree)(using Context): Unit

Check that widened types of tpe and pt are compatible.

Check that widened types of tpe and pt are compatible.

Attributes

Inherited from:
Rechecker

When we select the apply of a function with type such as (=> A) => B, we need to convert the parameter type => A to () ?=> A. See doc comment of mapExprType.

When we select the apply of a function with type such as (=> A) => B, we need to convert the parameter type => A to () ?=> A. See doc comment of mapExprType.

Attributes

Inherited from:
Rechecker
def recheckAlternative(tree: Alternative, pt: Type)(using Context): Type

Attributes

Inherited from:
Rechecker
def recheckAnnotated(tree: Annotated)(using Context): Type

Attributes

Inherited from:
Rechecker
def recheckAssign(tree: Assign)(using Context): Type

Attributes

Inherited from:
Rechecker
def recheckBind(tree: Bind, pt: Type)(using Context): Type

Attributes

Inherited from:
Rechecker
def recheckBlock(stats: List[Tree], expr: Tree, pt: Type)(using Context): Type

Attributes

Inherited from:
Rechecker
def recheckCase(tree: CaseDef, selType: Type, pt: Type)(using Context): Type

Attributes

Inherited from:
Rechecker
def recheckDef(tree: ValOrDefDef, sym: Symbol)(using Context): Unit

Attributes

Inherited from:
Rechecker
def recheckIf(tree: If, pt: Type)(using Context): Type

Attributes

Inherited from:
Rechecker
def recheckInlined(tree: Inlined, pt: Type)(using Context): Type

Attributes

Inherited from:
Rechecker
def recheckLabeled(tree: Labeled, pt: Type)(using Context): Type

Attributes

Inherited from:
Rechecker
def recheckMatch(tree: Match, pt: Type)(using Context): Type

Attributes

Inherited from:
Rechecker

Attributes

Inherited from:
Rechecker
def recheckReturn(tree: Return)(using Context): Type

Attributes

Inherited from:
Rechecker
def recheckSelect(tree: Select, pt: Type)(using Context): Type

Attributes

Inherited from:
Rechecker
def recheckSelection(tree: Select, qualType: Type, name: Name, sharpen: Denotation => Denotation)(using Context): Type

Attributes

Inherited from:
Rechecker
def recheckSeqLiteral(tree: SeqLiteral, pt: Type)(using Context): Type

Attributes

Inherited from:
Rechecker
def recheckStart(tree: Tree, pt: Type)(using Context): Type

Recheck tree without adapting it, returning its new type.

Recheck tree without adapting it, returning its new type.

Value parameters

pt

the expected result type

tree

the original tree

Attributes

Inherited from:
Rechecker
def recheckStats(stats: List[Tree])(using Context): Unit

Attributes

Inherited from:
Rechecker
def recheckTypeApply(tree: TypeApply, pt: Type)(using Context): Type

Attributes

Inherited from:
Rechecker
def recheckTypeDef(tree: TypeDef, sym: Symbol)(using Context): Type

Attributes

Inherited from:
Rechecker
def recheckTypeTree(tree: TypeTree)(using Context): Type

Attributes

Inherited from:
Rechecker
def recheckWhileDo(tree: WhileDo)(using Context): Type

Attributes

Inherited from:
Rechecker
def reset()(using Context): Unit

Reset all references in prevSelDenots to the denotations they had before this phase.

Reset all references in prevSelDenots to the denotations they had before this phase.

Attributes

Inherited from:
Rechecker
def widenSkolems(tp: Type)(using Context): Type

Typing and previous transforms sometimes leaves skolem types in prefixes of NamedTypes in expected that do not match the actual Type. -Ycheck does not complain (need to find out why), but a full recheck does. We compensate by de-skolemizing everywhere in expected except when variance is negative.

Typing and previous transforms sometimes leaves skolem types in prefixes of NamedTypes in expected that do not match the actual Type. -Ycheck does not complain (need to find out why), but a full recheck does. We compensate by de-skolemizing everywhere in expected except when variance is negative.

Attributes

Returns

If tp contains SkolemTypes in covariant or invariant positions, the type where these SkolemTypes are mapped to their underlying type. Otherwise, tp itself

Inherited from:
Rechecker