abstract class Context
extends Periods with Substituters with TypeOps with Phases with Printers with Symbols with SymDenotations with Reporting with NamerContextOps with Cloneable

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).

Constructors

Context ( )
Context ( )
Context ( c: Context )
Context ( ctx: Context )
Context ( )
Context ( c: Context )
Context ( ctx: Context )

Members

val NoPhase : NoPhase$
val SomePhase : SomePhase$
private var _compilationUnit : CompilationUnit

The current tree

The current tree

private var _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.

private var _diagnostics : Option [ StringBuilder ]

An optional diagostics buffer than is used by some checking code to provide more information in the buffer if it exists.

An optional diagostics buffer than is used by some checking code to provide more information in the buffer if it exists.

private var _freshNames : FreshNameCreator

The current fresh name creator

The current fresh name creator

private var _gadt : GADTMap

The current bounds in force for type parameters appearing in a GADT

The current bounds in force for type parameters appearing in a GADT

private var _importInfo : ImportInfo

The currently active import info

The currently active import info

private var _mode : Mode

The scope nesting level

The scope nesting level

private var _moreProperties : Map [ Key [ Any ], Any ]

A map in which more contextual properties can be stored

A map in which more contextual properties can be stored

var _nextId : Int

A counter for unique ids

A counter for unique ids

private var _outer : Context

The outer context

The outer context

private var _owner : Symbol

The current owner symbol

The current owner symbol

private var _period : Period

The current context

The current context

private var _printerFn : Context => Printer

The current plain printer

The current plain printer

private var _runInfo : RunInfo

The current compiler-run specific Info

The current compiler-run specific Info

private var _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

private var _scope : Scope

The current scope

The current scope

private var _searchHistory : SearchHistory

The history of implicit searches that are currently active

The history of implicit searches that are currently active

private var _sstate : SettingsState

The current settings values

The current settings values

private var _tree : Tree [ Untyped <: Any ]

The current tree

The current tree

private var _typeAssigner : TypeAssigner

The current type assigner or typer

The current type assigner or typer

private var _typeComparer : TypeComparer
private var _typerState : TyperState

The current type comparer

The current type comparer

val base : ContextBase

The context base at the root

The context base at the root

var classOfId : Array [ ClassSymbol ]

A map from a superclass id to the typeref of the class that has it

A map from a superclass id to the typeref of the class that has it

private var creationTrace : Array [ StackTraceElement ]

If -Ydebug is on, the top of the stack trace where this context was created, otherwise null.

If -Ydebug is on, the top of the stack trace where this context was created, otherwise null.

val definitions : Definitions

The standard definitions

The standard definitions

var denotTransformers : Array [ DenotTransformer ]
var findMemberCount : Int

Number of findMember calls on stack

Number of findMember calls on stack

protected var implicitsCache : ContextualImplicits

The new implicit references that are introduced by this scope

The new implicit references that are introduced by this scope

var indent : Int
val indentTab : String
val initialCtx : Context

The initial context

The initial context

var lastSuperId : Int

The last allocated superclass id

The last allocated superclass id

val loaders : SymbolLoaders

The symbol loaders

The symbol loaders

var nextDenotTransformerId : Array [ Int ]

Next denotation transformer id

Next denotation transformer id

var pendingMemberSearches : List [ Name ]

List of names which have a findMemberCall on stack, after Config.LogPendingFindMemberThreshold is reached.

List of names which have a findMemberCall on stack, after Config.LogPendingFindMemberThreshold is reached.

val pendingUnderlying : HashSet [ Type ]

The set of named types on which a currently active invocation of underlying during a controlled operation exists.

The set of named types on which a currently active invocation of underlying during a controlled operation exists.

[+] private var phasedCtx : Context

Those fields are used to cache phases created in withPhase. phasedCtx is first phase with altered phase ever requested. phasedCtxs is array that uses ph...

Those fields are used to cache phases created in withPhase. phasedCtx is first phase with altered phase ever requested. phasedCtxs is array that uses phaseId's as indexes, contexts are created only on request and cached in this array

private var phasedCtxs : Array [ Context ]
var phases : Array [ Phase ]

Phases by id

Phases by id

var phasesPlan : List [ List [ Phase ] ]
val settings : ScalaSettings

The applicable settings

The applicable settings

var squashedPhases : Array [ Phase ]

Phases with consecutive Transforms grouped into a single phase, Empty array if squashing is disabled

Phases with consecutive Transforms grouped into a single phase, Empty array if squashing is disabled

val superIdOfClass : AnyRefMap [ ClassSymbol, Int ]

A map from a the typeref of a class to its superclass id

A map from a the typeref of a class to its superclass id

var toTextRecursions : Int

Number of recursive invocations of a show method on current stack

Number of recursive invocations of a show method on current stack

var underlyingRecursions : Int

The number of recursive invocation of underlying on a NamedType during a controlled operation.

The number of recursive invocation of underlying on a NamedType during a controlled operation.

val uniqueNamedTypes : NamedTypeUniques

A table for hash consing unique named types

A table for hash consing unique named types

val uniqueRefinedTypes : RefinedUniques

A table for hash consing unique refined types

A table for hash consing unique refined types

val uniqueTypeAliases : TypeAliasUniques

A table for hash consing unique type bounds

A table for hash consing unique type bounds

val uniques : HashSet [ Type ]

A table for hash consing unique types

A table for hash consing unique types

var unsafeNonvariant : RunId

A flag that some unsafe nonvariant instantiation was encountered in this run. Used as a shortcut to a avoid scans of types in Typer.typedSelect.

A flag that some unsafe nonvariant instantiation was encountered in this run. Used as a shortcut to a avoid scans of types in Typer.typedSelect.

private def _diagnostics_= ( x$1: Option [ StringBuilder ] ) : Unit

An optional diagostics buffer than is used by some checking code to provide more information in the buffer if it exists.

An optional diagostics buffer than is used by some checking code to provide more information in the buffer if it exists.

private def _gadt_= ( x$1: GADTMap ) : Unit

The current bounds in force for type parameters appearing in a GADT

The current bounds in force for type parameters appearing in a GADT

private def _moreProperties_= ( x$1: Map [ Key [ Any ], Any ] ) : Unit

A map in which more contextual properties can be stored

A map in which more contextual properties can be stored

def _nextId_= ( x$1: Int ) : Unit

A counter for unique ids

A counter for unique ids

private def _searchHistory_= ( x$1: SearchHistory ) : Unit

The history of implicit searches that are currently active

The history of implicit searches that are currently active

private def _typeComparer_= ( x$1: TypeComparer ) : Unit
def addMode ( mode: Mode ) : Context
def allPhases : Repr
def atPrec ( prec: Precedence ) ( op: => Text ) : Text

Generate text using op, assuming a given precedence level prec.

Generate text using op, assuming a given precedence level prec.

def changePrec ( prec: Precedence ) ( op: => Text ) : Text

Generate text using op, assuming a given precedence level prec. If new level prec is lower than previous level, put text in parentheses.

Generate text using op, assuming a given precedence level prec. If new level prec is lower than previous level, put text in parentheses.

def checkSingleThreaded ( ) : Unit

Check that we are on the same thread as before

Check that we are on the same thread as before

def classOfId_= ( x$1: Array [ ClassSymbol ] ) : Unit

A map from a superclass id to the typeref of the class that has it

A map from a superclass id to the typeref of the class that has it

def clone ( ) : Object
def compilationUnit : CompilationUnit
protected def compilationUnit_= ( compilationUnit: CompilationUnit ) : Unit
def compilerCallback : CompilerCallback
protected def compilerCallback_= ( callback: CompilerCallback ) : Unit
private def creationTrace_= ( x$1: Array [ StackTraceElement ] ) : Unit

If -Ydebug is on, the top of the stack trace where this context was created, otherwise null.

If -Ydebug is on, the top of the stack trace where this context was created, otherwise null.

implicit def ctx : Context
def currentPrecedence : Precedence

The current precedence level

The current precedence level

def dclText ( sym: Symbol ) : Text

Textual representation of symbol's declaration

Textual representation of symbol's declaration

def dclText ( sd: SingleDenotation ) : Text

Textual representation of single denotation's declaration

Textual representation of single denotation's declaration

def dclsText ( syms: List [ Symbol ] , sep: String ) : Text

Textual representation of all symbols in given list, using dclText for displaying each.

Textual representation of all symbols in given list, using dclText for displaying each.

def debug : Boolean

Is the debug option set?

Is the debug option set?

def denotTransformers_= ( x$1: Array [ DenotTransformer ] ) : Unit
def diagnose ( str: => String ) : Unit

Leave message in diagnostics buffer if it exists

Leave message in diagnostics buffer if it exists

def diagnostics : Option [ StringBuilder ]
protected def diagnostics_= ( diagnostics: Option [ StringBuilder ] ) : Unit
def docCtx : Option [ ContextDocstrings ]
def docbase : ContextDottydoc
def elimErasedValueTypePhase : Phase
def elimRepeatedPhase : Phase
def eq ( x$0: Object ) : Boolean
def erasedTypes : Boolean

Does current phase use an erased types interpretation?

Does current phase use an erased types interpretation?

def erasurePhase : Phase
def explicitOuterPhase : Phase
def exprContext ( stat: Tree [ Untyped <: Any ] , 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

def extendedLocationText ( sym: Symbol ) : Text

A description of sym's location

A description of sym's location

def extensionMethodsPhase : Phase
def finalize ( ) : Unit
def findMemberCount_= ( x$1: Int ) : Unit

Number of findMember calls on stack

Number of findMember calls on stack

def flattenPhase : Phase
def fresh : FreshContext

A fresh clone of this context.

A fresh clone of this context.

def freshNames : FreshNameCreator
protected def freshNames_= ( freshNames: FreshNameCreator ) : Unit
def fullNameString ( sym: Symbol ) : String

The fully qualified name of the symbol

The fully qualified name of the symbol

def gadt : GADTMap
protected def gadt_= ( gadt: GADTMap ) : Unit
def genBCodePhase : Phase
def gettersPhase : Phase
def implicits : ContextualImplicits
protected def implicitsCache_= ( x$1: ContextualImplicits ) : Unit

The new implicit references that are introduced by this scope

The new implicit references that are introduced by this scope

def importInfo : ImportInfo
protected def importInfo_= ( importInfo: ImportInfo ) : Unit
def indent_= ( x$1: Int ) : Unit
protected def init ( outer: Context ) : Context & Context
def initialize ( ) ( implicit ctx: Context ) : Unit

Initializes the ContextBase with a starting context. This initializes the platform and the definitions.

Initializes the ContextBase with a starting context. This initializes the platform and the definitions.

def isAfterTyper ( phase: Phase ) : Boolean
def isClassDefContext : Boolean

Is this a context for the members of a class definition?

Is this a context for the members of a class definition?

def isImportContext : Boolean

Is this a context that introduces an import clause?

Is this a context that introduces an import clause?

def isNonEmptyScopeContext : Boolean

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

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

def kindString ( sym: Symbol ) : String

The kind of the symbol

The kind of the symbol

def lambdaLiftPhase : Phase
def lastSuperId_= ( x$1: Int ) : Unit

The last allocated superclass id

The last allocated superclass id

def locatedText ( sym: Symbol ) : Text

Textual representation of symbol and its location

Textual representation of symbol and its location

def locationText ( sym: Symbol ) : Text

If symbol's owner is a printable class C, the text "in C", otherwise ""

If symbol's owner is a printable class C, the text "in C", otherwise ""

def maskMode ( mode: Mode ) : Context
def missingHook ( owner: Symbol , name: Name ) ( implicit ctx: Context ) : Symbol

If we are looking for a non-existing term name in a package, assume it is a package for which we do not have a directory and enter it.

If we are looking for a non-existing term name in a package, assume it is a package for which we do not have a directory and enter it.

def mode : Mode
protected def mode_= ( mode: Mode ) : Unit
def moreProperties : Map [ Key [ Any ], Any ]
protected def moreProperties_= ( moreProperties: Map [ Key [ Any ], Any ] ) : Unit
def nameString ( name: Name ) : String

The name, possibley with with namespace suffix if debugNames is set: /L for local names, /V for other term names, /T for type names

The name, possibley with with namespace suffix if debugNames is set: /L for local names, /V for other term names, /T for type names

[+] def nameString ( sym: Symbol ) : String

The name of the given symbol. If !settings.debug, the original name where expansions of operators are translated back to operator symbol. E.g. $eq => =. I...

The name of the given symbol. If !settings.debug, the original name where expansions of operators are translated back to operator symbol. E.g. $eq => =. If settings.uniqid, adds id.

def ne ( x$0: Object ) : Boolean
def newPlatform ( implicit ctx: Context ) : Platform
def nextDenotTransformerId_= ( x$1: Array [ Int ] ) : Unit

Next denotation transformer id

Next denotation transformer id

def nextId : Int
def nextSuperId : Int

Allocate and return next free superclass id

Allocate and return next free superclass id

def notify ( ) : Unit
def notifyAll ( ) : Unit
def outer : Context
protected def outer_= ( outer: Context ) : Unit
def outersIterator : Iterator [ Context ]

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

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

def owner : Symbol
protected def owner_= ( owner: Symbol ) : Unit
def patmatPhase : Phase
def pendingMemberSearches_= ( x$1: List [ Name ] ) : Unit

List of names which have a findMemberCall on stack, after Config.LogPendingFindMemberThreshold is reached.

List of names which have a findMemberCall on stack, after Config.LogPendingFindMemberThreshold is reached.

def period : Period
protected def period_= ( period: Period ) : Unit
def phaseOfClass ( pclass: Class [ Nothing <: Any ] ) : A
def phasePlan : List [ List [ Phase ] ]
[+] private def phasedCtx_= ( x$1: Context ) : Unit

Those fields are used to cache phases created in withPhase. phasedCtx is first phase with altered phase ever requested. phasedCtxs is array that uses ph...

Those fields are used to cache phases created in withPhase. phasedCtx is first phase with altered phase ever requested. phasedCtxs is array that uses phaseId's as indexes, contexts are created only on request and cached in this array

private def phasedCtxs_= ( x$1: Array [ Context ] ) : Unit
def phasesPlan_= ( x$1: List [ List [ Phase ] ] ) : Unit
def phases_= ( x$1: Array [ Phase ] ) : Unit

Phases by id

Phases by id

def picklerPhase : Phase
def plain : Printer

A plain printer without any embellishments

A plain printer without any embellishments

def platform : Platform

The platform

The platform

def printCreationTraces ( ) : Unit

Print all enclosing context's creation stacktraces

Print all enclosing context's creation stacktraces

def printerFn : Context => Printer
protected def printerFn_= ( printerFn: Context => Printer ) : Unit
def property ( key: Key [ T ] ) : Option [ T ]
def refchecksPhase : Phase
def reporter : Reporter

The current reporter

The current reporter

def reset ( ) : Unit
def retractMode ( mode: Mode ) : Context
def rootLoader ( root: TermSymbol ) ( implicit ctx: Context ) : SymbolLoader

The loader that loads the members of root

The loader that loads the members of root

def runInfo : RunInfo
protected def runInfo_= ( runInfo: RunInfo ) : Unit
def sbtCallback : AnalysisCallback
protected def sbtCallback_= ( callback: AnalysisCallback ) : Unit
def scope : Scope
protected def scope_= ( scope: Scope ) : Unit
def searchHistory : SearchHistory
protected def searchHistory_= ( searchHistory: SearchHistory ) : Unit
private def setCreationTrace ( ) : Unit
def setPhasePlan ( phasess: List [ List [ Phase ] ] ) : Unit
def shouldExplain ( cont: MessageContainer ) : Boolean
def source : SourceFile

The current source file; will be derived from current compilation unit.

The current source file; will be derived from current compilation unit.

[+] def squashPhases ( phasess: List [ List [ Phase ] ] , phasesToSkip: List [ String ] , stopBeforePhases: List [ String ] , stopAfterPhases: List [ String ] , YCheckAfter: List [ String ] ) : List [ Phase ]

Squash TreeTransform's beloning to same sublist to a single TreeTransformer Each TreeTransform gets own period, whereas a combined TreeTransformer gets...

Squash TreeTransform's beloning to same sublist to a single TreeTransformer Each TreeTransform gets own period, whereas a combined TreeTransformer gets period equal to union of periods of it's TreeTransforms

def squashed ( p: Phase ) : Phase
def squashedPhases_= ( x$1: Array [ Phase ] ) : Unit

Phases with consecutive Transforms grouped into a single phase, Empty array if squashing is disabled

Phases with consecutive Transforms grouped into a single phase, Empty array if squashing is disabled

def sstate : SettingsState
protected def sstate_= ( sstate: SettingsState ) : Unit
[+] def staticRef ( path: Name , generateStubs: Boolean ) ( implicit ctx: Context ) : Denotation

The current denotation of the static reference given by path, or a MissingRef or NoQualifyingRef instance, if it does not exist. if generateStubs is set...

The current denotation of the static reference given by path, or a MissingRef or NoQualifyingRef instance, if it does not exist. if generateStubs is set, generates stubs for missing top-level symbols

def summarized ( depth: Int ) ( op: => T ) : T

Perform string or text-producing operation op so that only a summarized text with given recursion depth is shown

Perform string or text-producing operation op so that only a summarized text with given recursion depth is shown

[+] def superCallContext : Context

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 c...

      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
      • with additional mode: InSuperCall

      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.
      private def superOrThisCallContext ( owner: Symbol , locals: Scope ) : FreshContext

      The super- or this-call context with given owner and locals.

      The super- or this-call context with given owner and locals.

      def synchronized ( x$0: X0 ) : X0
      def thisCallArgContext : Context

      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.

      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
      def toText ( result: ImportInfo ) : Text

      Textual representation of info relating to an import clause

      Textual representation of info relating to an import clause

      def toText ( name: Name ) : Text

      The name as a text

      The name as a text

      [+] def toText ( sym: Symbol ) : Text

      Textual representation, including symbol's kind e.g., "class Foo", "method Bar". If hasMeaninglessName is true, uses the owner's name to disambiguate i...

      Textual representation, including symbol's kind e.g., "class Foo", "method Bar". If hasMeaninglessName is true, uses the owner's name to disambiguate identity.

      def toText ( const: Constant ) : Text

      Textual representation of constant

      Textual representation of constant

      def toText ( tp: Type ) : Text

      Textual representation of type

      Textual representation of type

      def toText ( sc: Scope ) : Text

      Textual representation of all definitions in a scope using dclText for each

      Textual representation of all definitions in a scope using dclText for each

      def toText ( tree: Tree [ T ] ) : Text

      Textual representation of tree

      Textual representation of tree

      def toText ( result: SearchResult ) : Text

      Textual representation of implicit search result

      Textual representation of implicit search result

      def toText ( annot: Annotation ) : Text

      Textual representation of annotation

      Textual representation of annotation

      def toText ( denot: Denotation ) : Text

      Textual representation of denotation

      Textual representation of denotation

      def toTextRecursions_= ( x$1: Int ) : Unit

      Number of recursive invocations of a show method on current stack

      Number of recursive invocations of a show method on current stack

      def tree : Tree [ Untyped <: Any ]
      protected def tree_= ( tree: Tree [ Untyped <: Any ] ) : Unit
      def typeAssigner : TypeAssigner
      protected def typeAssigner_= ( typeAssigner: TypeAssigner ) : Unit
      def typeComparer : TypeComparer
      protected def typeComparer_= ( typeComparer: TypeComparer ) : Unit
      def typer : Typer
      def typerPhase : Phase
      def typerState : TyperState
      protected def typerState_= ( typerState: TyperState ) : Unit
      def underlyingRecursions_= ( x$1: Int ) : Unit

      The number of recursive invocation of underlying on a NamedType during a controlled operation.

      The number of recursive invocation of underlying on a NamedType during a controlled operation.

      def uniquesSizes : Map [ String, Int ]

      A map that associates label and size of all uniques sets

      A map that associates label and size of all uniques sets

      def unsafeNonvariant_= ( x$1: RunId ) : Unit

      A flag that some unsafe nonvariant instantiation was encountered in this run. Used as a shortcut to a avoid scans of types in Typer.typedSelect.

      A flag that some unsafe nonvariant instantiation was encountered in this run. Used as a shortcut to a avoid scans of types in Typer.typedSelect.

      def useColors : Boolean

      Should use colors when printing?

      Should use colors when printing?

      [+] def usePhases ( phasess: List [ Phase ] , squash: Boolean ) : Unit

      Use the following phases in the order they are given. The list should never contain NoPhase. if squashing is enabled, phases in same subgroup will be sq...

      Use the following phases in the order they are given. The list should never contain NoPhase. if squashing is enabled, phases in same subgroup will be squashed to single phase.

      def verbose : Boolean

      Is the verbose option set?

      Is the verbose option set?

      def wait ( ) : Unit
      def wait ( x$0: Long ) : Unit
      def wait ( x$0: Long , x$1: Int ) : Unit
      def withModeBits ( mode: Mode ) : Context
      final def withOwner ( owner: Symbol ) : Context
      final def withPhase ( phaseId: PhaseId ) : Context

      This context at given phase. This method will always return a phase period equal to phaseId, thus will never return squashed phases

      This context at given phase. This method will always return a phase period equal to phaseId, thus will never return squashed phases

      final def withPhase ( phase: Phase ) : Context
      final def withPhaseNoEarlier ( phase: Phase ) : Context
      final def withPhaseNoLater ( phase: Phase ) : Context
      final def withProperty ( key: Key [ T ] , value: Option [ T ] ) : Context