Context
A context is passed basically everywhere in dotc. This is convenient but carries the risk of captured contexts in objects that turn into space leaks. To combat this risk, here are some conventions to follow:
- Never let an implicit context be an argument of a class whose instances live longer than the context.
- Classes that need contexts for their initialization take an explicit parameter
named
initctx
. They pass initctx to all positions where it is needed (and these positions should all be part of the intialization sequence of the class). - Classes that need contexts that survive initialization are instead passed
a "condensed context", typically named
cctx
(or they create one). Condensed contexts just add some basic information to the context base without the risk of capturing complete trees. - To make sure these rules are kept, it would be good to do a sanity check using bytecode inspection with javap or scalap: Keep track of all class fields of type context; allow them only in whitelisted classes (which should be short-lived).
Value members
Concrete methods
The compiler callback implementation, or null if no callback will be called.
The compiler callback implementation, or null if no callback will be called.
Either the current scope, or, if the current context owner is a class, the declarations of the current class.
Either the current scope, or, if the current context owner is a class, the declarations of the current class.
Does current phase use an erased types interpretation?
Does current phase use an erased types interpretation?
The context of expression expr
seen as a member of a statement sequence
The context of expression expr
seen as a member of a statement sequence
A fresh clone of this context embedded in this context.
A fresh clone of this context embedded in this context.
A fresh clone of this context embedded in the specified outer
context.
A fresh clone of this context embedded in the specified outer
context.
Sourcefile corresponding to given abstract file, memoized
Sourcefile corresponding to given abstract file, memoized
Is this a context for the members of a class definition?
Is this a context for the members of a class definition?
Is this a context that introduces an import clause?
Is this a context that introduces an import clause?
Is this a context for typechecking an inlined body?
Is this a context for typechecking an inlined body?
Is this a context that introduces a non-empty scope?
Is this a context that introduces a non-empty scope?
All outer contexts, ending in base.initialCtx
and then NoContext
All outer contexts, ending in base.initialCtx
and then NoContext
The sbt callback implementation if we are run from sbt, null otherwise
The sbt callback implementation if we are run from sbt, null otherwise
The context for a supercall. This context is used for elaborating the parents of a class and their arguments. The context is computed from the current class context. It has
The context for a supercall. This context is used for elaborating the parents of a class and their arguments. The context is computed from the current class context. It has
- as owner: The primary constructor of the class
- as outer context: The context enclosing the class context
- as scope: The parameter accessors in the class context
The reasons for this peculiar choice of attributes are as follows:
- The constructor must be the owner, because that's where any local methods or closures should go.
- The context may not see any class members (inherited or defined), and should instead see definitions defined in the outer context which might be shadowed by such class members. That's why the outer context must be the outer context of the class.
- At the same time the context should see the parameter accessors of the current class, that's why they get added to the local scope. An alternative would have been to have the context see the constructor parameters instead, but then we'd need a final substitution step from constructor parameters to class parameter accessors.
The context for the arguments of a this(...) constructor call. The context is computed from the local auxiliary constructor context. It has
The context for the arguments of a this(...) constructor call. The context is computed from the local auxiliary constructor context. It has
- as owner: The auxiliary constructor
- as outer context: The context enclosing the enclosing class context
- as scope: The parameters of the auxiliary constructor.