Context

dotty.tools.dotc.core.Contexts.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).

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class FreshContext
Self type

Members list

Value members

Abstract methods

def mode: Mode
def moreProperties: Map[Key[Any], Any]

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

def outer: Context
def owner: Symbol
def period: Period
def reuseIn(outer: Context): Context.this.type

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

def scope: Scope
def store: Store

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

def tree: Tree[_]

Concrete methods

final def addMode(mode: Mode): Context
Extension method from Contexts

The current compilation unit

The current compilation unit

Attributes

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.

Attributes

def debug: Boolean

Is the debug option set?

Is the debug option set?

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

final def erasedTypes: Boolean

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

def exprContext(stat: Tree[_], 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

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

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

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

def importContext(imp: Import[_], sym: Symbol): FreshContext

A new context that summarizes an import statement

A new context that summarizes an import statement

Attributes

def importInfo: ImportInfo | Null

The currently active import info

The currently active import info

Attributes

def initialize()(using Context): Unit
final def isAfterTyper: Boolean

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

final def isJava: Boolean

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

final def isTyper: Boolean
final def lastPhaseId: Int

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

final def phase: Phase
final def phaseId: PhaseId

A function creating a printer

A function creating a printer

Attributes

The current plain printer

The current plain printer

Attributes

The current compiler-run profiler

The current compiler-run profiler

Attributes

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

The current reporter

The current reporter

Attributes

protected def resetCaches(): Unit
final def retractMode(mode: Mode): Context
Extension method from Contexts
def run: Run | Null

The current compiler-run

The current compiler-run

Attributes

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

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

override def toString: String

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

Attributes

def typer: Typer

Should use colors when printing?

Should use colors when printing?

Attributes

Is the verbose option set?

Is the verbose option set?

Attributes

final def withModeBits(mode: Mode): Context
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
final def withTyperState(typerState: TyperState): Context

Concrete fields

Givens

Givens

protected given given_Context: Context