Context

abstract class Context(val base: ContextBase)

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).
class Object
trait Matchable
class Any

Value members

Concrete methods

final def addMode: Context
Extension method from Contexts

The current compilation unit

The current compilation unit

def compilerCallback: CompilerCallback

The compiler callback implementation, or null if no callback will be called.

The compiler callback implementation, or null if no callback will be called.

Is the debug option set?

Is the debug option set?

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.

final def erasedTypes: Boolean

Does current phase use an erased types interpretation?

Does current phase use an erased types interpretation?

Is the explicit nulls option set?

Is the explicit nulls option set?

def exprContext(stat: Tree[_ >: Untyped], exprOwner: Symbol): Context

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.

final def gadt: GadtConstraint
protected def gadt_=(gadt: GadtConstraint): Unit

AbstraFile with given path name, memoized

AbstraFile with given path name, memoized

AbstractFile with given path, memoized

AbstractFile with given path, memoized

def getSource(file: AbstractFile, codec: => Codec): SourceFile

Sourcefile corresponding to given abstract file, memoized

Sourcefile corresponding to given abstract file, memoized

SourceFile with given path name, memoized

SourceFile with given path name, memoized

SourceFile with given path, memoized

SourceFile with given path, memoized

A new context that summarizes an import statement

A new context that summarizes an import statement

The currently active import info

The currently active import info

def initialize(using Context): Unit

Is current phase after FrontEnd?

Is current phase after FrontEnd?

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?

final def isJava: Boolean

Are we in a Java compilation unit?

Are we in a Java compilation unit?

Is this a context that introduces a non-empty scope?

Is this a context that introduces a non-empty scope?

final def lastPhaseId: Int
final def mode: Mode
protected def mode_=(mode: Mode): Unit
final def moreProperties: Map[Key[Any], Any]
protected def moreProperties_=(moreProperties: Map[Key[Any], Any]): Unit

The paths currently known to be not null

The paths currently known to be not null

final def outer: Context
protected def outer_=(outer: Context): Unit

All outer contexts, ending in base.initialCtx and then NoContext

All outer contexts, ending in base.initialCtx and then NoContext

final def owner: Symbol
protected def owner_=(owner: Symbol): Unit
final def period: Period
protected def period_=(period: Period): Unit
final def phase: Phase
final def phaseId: PhaseId

A function creating a printer

A function creating a printer

The current plain printer

The current plain printer

The current compiler-run profiler

The current compiler-run profiler

def property[T](key: Key[T]): Option[T]

The current reporter

The current reporter

final def retractMode: Context
Extension method from Contexts
def reuseIn(outer: Context): Context
def run: Run

The current compiler-run

The current compiler-run

final def runId: RunId
def sbtCallback: AnalysisCallback

The sbt callback implementation if we are run from sbt, null otherwise

The sbt callback implementation if we are run from sbt, null otherwise

final def scope: Scope
protected def scope_=(scope: Scope): Unit
protected def searchHistory_=(searchHistory: SearchHistory): Unit

The current settings values

The current settings values

final def source: SourceFile
protected def source_=(source: SourceFile): Unit
final def store: Store
protected def store_=(store: Store): Unit

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.
override def toString: String
Definition Classes
Any
final def tree: Tree[_ >: Untyped]
protected def tree_=(tree: Tree[_ >: Untyped]): Unit

The current type assigner or typer

The current type assigner or typer

def typer: Typer
protected def typerState_=(typerState: TyperState): Unit

Should use colors when printing?

Should use colors when printing?

Is the verbose option set?

Is the verbose option set?

Extension method from Contexts
final def withOwner(owner: Symbol): Context
final def withPhase(phase: Phase): Context
final def withPhase(pid: PhaseId): Context
final def withProperty[T](key: Key[T], value: Option[T]): Context
final def withSource(source: SourceFile): Context

Concrete fields

final lazy val Context: Context

The new implicit references that are introduced by this scope

The new implicit references that are introduced by this scope