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

Members

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

The current tree

private var _compilerCallback : CompilerCallback

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

private var _diagnostics : Option

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

private var _gadt : GADTMap

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

private var _importInfo : ImportInfo

The currently active import info

private var _mode : Mode

The scope nesting level

private var _moreProperties : Map

A map in which more contextual properties can be stored

var _nextId : Int

A counter for unique ids

private var _outer : Context

The outer context

private var _owner : Symbol

The current owner symbol

private var _period : Period

The current context

private var _printerFn :

The current plain printer

private var _runInfo : RunInfo

The current compiler-run specific Info

private var _sbtCallback : AnalysisCallback

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

private var _scope : Scope

The current scope

private var _searchHistory : SearchHistory

The history of implicit searches that are currently active

private var _sstate : SettingsState

The current settings values

private var _tree : Tree

The current tree

private var _typeAssigner : TypeAssigner

The current type assigner or typer

private var _typeComparer : TypeComparer
private var _typerState : TyperState

The current type comparer

val base : ContextBase

The context base at the root

var classOfId : Array

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

private var creationTrace : Array

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

val definitions : Definitions

The standard definitions

var denotTransformers : Array
var findMemberCount : Int

Number of findMember calls on stack

private var implicitsCache : ContextualImplicits

The new implicit references that are introduced by this scope

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

The initial context

var lastSuperId : Int

The last allocated superclass id

val loaders : SymbolLoaders

The symbol loaders

var nextDenotTransformerId : Array

Next denotation transformer id

var pendingMemberSearches : List

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

val pendingUnderlying : HashSet

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

private var phasedCtxs : Array
var phases : Array

Phases by id

var phasesPlan : List
val settings : ScalaSettings

The applicable settings

var squashedPhases : Array

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

val superIdOfClass : AnyRefMap

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

var underlyingRecursions : Int

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

val uniqueRefinedTypes : RefinedUniques

A table for hash consing unique refined types

val uniqueTypeAliases : TypeAliasUniques

A table for hash consing unique type bounds

val uniques : HashSet

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.

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.

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

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

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

A counter for unique ids

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

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.

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.

def checkSingleThreaded ( ) : Unit

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

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.

implicit def ctx : Context
def currentPrecedence : Precedence

The current precedence level

def dclText ( sd: SingleDenotation ) : Text

Textual representation of single denotation's declaration

def dclText ( sym: Symbol ) : Text

Textual representation of symbol's declaration

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

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

def debug : Boolean

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

def diagnostics : Option
protected def diagnostics_= ( diagnostics: Option [ StringBuilder ] ) : Unit
def docCtx : Option
def docbase : ContextDottydoc
def elimErasedValueTypePhase : Phase
def elimRepeatedPhase : Phase
def enclTemplate : Context

The next outer context whose tree is a template or package definition

def eq ( x$0: Object ) : Boolean
def erasedTypes : Boolean

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

def extendedLocationText ( sym: Symbol ) : Text

A description of sym's location

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

Number of findMember calls on stack

def flattenPhase : Phase
def fresh : FreshContext

A fresh clone of this context.

def freshName ( prefix: String ) : String
def freshName ( prefix: Name ) : String
def freshName$default$1 : String
def freshNames : FreshNameCreator
protected def freshNames_= ( freshNames: FreshNameCreator ) : Unit
def fullNameString ( sym: Symbol ) : String

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
private def implicitsCache_= ( x$1: ContextualImplicits ) : Unit

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

A condensed context containing essential information of this but no outer contexts except the initial context. private var _condensed: CondensedContext...

def initialize ( ) ( implicit ctx: Context ) : Unit

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?

def isImportContext : Boolean

Is this a context that introduces an import clause?

def isNonEmptyScopeContext : Boolean

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

def kindString ( sym: Symbol ) : String

The kind of the symbol

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

The last allocated superclass id

def locatedText ( sym: Symbol ) : Text

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 ""

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.

def mode : Mode
protected def mode_= ( mode: Mode ) : Unit
def moreProperties : Map
protected def moreProperties_= ( moreProperties: Map [ Key [ Any ], Any ] ) : Unit
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...

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

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

Next denotation transformer id

def nextId : Int
def nextSuperId : Int

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

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.

def period : Period
protected def period_= ( period: Period ) : Unit
def phaseOfClass ( pclass: Class [ Nothing <: Any ] ) : A
def phasePlan : List
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...

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

def picklerPhase : Phase
def plain : Printer

A plain printer without any embellishments

def platform : Platform

The platform

def printCreationTraces ( ) : Unit

Print all enclosing context's creation stacktraces

def printerFn :
protected def printerFn_= ( printerFn: Context => Printer ) : Unit
def property ( key: Key [ T ] ) : Option
def refchecksPhase : Phase
def reporter : 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

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.

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

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

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

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

def summarized ( depth: Int ) ( op: => T ) : [T] => (depth: Int)(op: => T)T (not handled)

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

      private def superOrThisCallContext ( owner: Symbol , locals: Scope ) : FreshContext

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

      def synchronized ( x$0: X0 ) : [X0] => (x$0: X0)X0 (not handled)
      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.
      override def toString : String
      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...

      def toText ( const: Constant ) : Text

      Textual representation of constant

      def toText ( tree: Tree [ T ] ) : [T >: dotty.tools.dotc.ast.Trees.Untyped] => (tree: dotty.tools.dotc.ast.Trees.Tree[T])dotty.tools.dotc.printing.Texts.Text (not handled)

      Textual representation of tree

      def toText ( name: Name ) : Text

      The name as a text

      def toText ( annot: Annotation ) : Text

      Textual representation of annotation

      def toText ( denot: Denotation ) : Text

      Textual representation of denotation

      def toText ( sc: Scope ) : Text

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

      def toText ( tp: Type ) : Text

      Textual representation of type

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

      Number of recursive invocations of a show method on current stack

      def tree : Tree
      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.

      def uniquesSizes : Map

      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.

      def useColors : Boolean

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

      def verbose : Boolean

      Is the verbose option set?

      def wait ( x$0: Long , x$1: Int ) : Unit
      def wait ( x$0: Long ) : Unit
      def wait ( ) : 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

      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