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).
Attributes
- Graph
-
- Supertypes
- Known subtypes
-
class FreshContext
- Self type
Members list
Value members
Abstract methods
A map in which more contextual properties can be stored Typically used for attributes that are read and written only in special situations.
A map in which more contextual properties can be stored Typically used for attributes that are read and written only in special situations.
Attributes
Reuse this context as a fresh context nested inside outer
But keep the typerstate, this one has to be set explicitly if needed.
Reuse this context as a fresh context nested inside outer
But keep the typerstate, this one has to be set explicitly if needed.
Attributes
A store that can be used by sub-components. Typically used for attributes that are defined only once per compilation unit. Access to store entries is much faster than access to properties, and only slightly slower than a normal field access would be.
A store that can be used by sub-components. Typically used for attributes that are defined only once per compilation unit. Access to store entries is much faster than access to properties, and only slightly slower than a normal field access would be.
Attributes
Concrete methods
The current compilation unit
The current compilation unit
Attributes
The compiler callback implementation, or null if no callback will be called.
The compiler callback implementation, or null if no callback will be called.
Attributes
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.
Attributes
Does current phase use an erased types interpretation?
Does current phase use an erased types interpretation?
Attributes
Is the explicit nulls option set?
Is the explicit nulls option set?
Attributes
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
Attributes
A fresh clone of this context embedded in this context.
A fresh clone of this context embedded in this context.
Attributes
A fresh clone of this context embedded in the specified outer
context.
A fresh clone of this context embedded in the specified outer
context.
Attributes
AbstraFile with given path name, memoized
AbstraFile with given path name, memoized
Attributes
AbstractFile with given path, memoized
AbstractFile with given path, memoized
Attributes
Sourcefile corresponding to given abstract file, memoized
Sourcefile corresponding to given abstract file, memoized
Attributes
SourceFile with given path name, memoized
SourceFile with given path name, memoized
Attributes
SourceFile with given path, memoized
SourceFile with given path, memoized
Attributes
A new context that summarizes an import statement
A new context that summarizes an import statement
Attributes
The currently active import info
The currently active import info
Attributes
Is current phase after TyperPhase?
Is current phase after TyperPhase?
Attributes
Is this a context for the members of a class definition?
Is this a context for the members of a class definition?
Attributes
Is this a context that introduces an import clause?
Is this a context that introduces an import clause?
Attributes
Is this a context for typechecking an inlined body?
Is this a context for typechecking an inlined body?
Attributes
Are we in a Java compilation unit?
Are we in a Java compilation unit?
Attributes
Is this a context that introduces a non-empty scope?
Is this a context that introduces a non-empty scope?
Attributes
The paths currently known to be not null
The paths currently known to be not null
Attributes
All outer contexts, ending in base.initialCtx
and then NoContext
All outer contexts, ending in base.initialCtx
and then NoContext
Attributes
The current compiler-run profiler
The current compiler-run profiler
Attributes
The sbt callback implementation if we are run from sbt, null otherwise
The sbt callback implementation if we are run from sbt, null otherwise
Attributes
The current settings values
The current settings values
Attributes
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.
Attributes
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.
Attributes
Returns a string representation of the object.
Returns a string representation of the object.
The default representation is platform dependent.
Attributes
- Returns
-
a string representation of the object.
- Definition Classes
-
Any
The current type assigner or typer
The current type assigner or typer