Dotty Documentation

0.14.0-bin-SNAPSHOT

abstract class Context
extends Periods with Substituters with TypeOps with Phases with Printers with Symbols with SymDenotations with Reporting with NamerContextOps with Plugins 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 ( base: ContextBase )
Context ( ctx: Context )
Context ( file: AbstractFile , codec: Codec )
Context ( c: Context )
Context ( ctx: Context )
Context ( file: AbstractFile , computeContent: => Array [ Char ] )
Context ( c: Context )

[-] Members

[+] 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 [ 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.

[+] private var _outer : Context

The outer context

[+] private var _owner : Symbol

The current owner symbol

[+] private var _period : Period

The current context

[+] private var _scope : Scope

The current scope

[+] private var _searchHistory : SearchHistory

The history of implicit searches that are currently active

[+] private var _source : SourceFile

The current source file

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

[+] private var _tree : Tree [ Untyped <: Any ]

The current tree

[+] private var _typeAssigner : TypeAssigner

The current type assigner or typer

[+] private var _typeComparer : TypeComparer

The current type comparer. This ones updates itself automatically for each new context.

[+] private var _typerState : TyperState

The current type comparer

[+] val base : ContextBase
[+] protected var implicitsCache : ContextualImplicits

The new implicit references that are introduced by this scope

[+] 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 phaseId's as indexes, contexts are created only on request and cached in this array

[+] private var phasedCtxs : Array [ Context ]
[+] private var sourceCtx : SimpleIdentityMap [ SourceFile, Context ]
[+] private def _store_= ( x$1: Store ) : Unit

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.

[+] def addMode ( mode: Mode ) : Context
[+] def apply ( idx: Int ) : Char
[+] def atSpan ( span: Span ) : SourcePosition
[+] def clone ( ) : Object
[+] def column ( offset: Int ) : Int

The column corresponding to offset, starting at 0

[+] def compilationUnit : CompilationUnit

The current compilation unit

[+] def compilerCallback : CompilerCallback

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

[+] def content ( ) : Array [ Char ]
[+] implicit def ctx : Context
[+] def debug : Boolean

Is the debug option set?

[+] def definitions : Definitions
[+] def docCtx : Option [ ContextDocstrings ]
[+] def docbase : ContextDottydoc
[+] def elimErasedValueTypePhase : Phase
[+] def elimRepeatedPhase : Phase
[+] def eq ( x$0: Object ) : Boolean
[+] def equals ( that: Any ) : Boolean
[+] def erasedTypes : Boolean

Does current phase use an erased types interpretation?

[+] def erasurePhase : Phase
[+] def exists : Boolean

true for all source files except NoSource

[+] 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 extensionMethodsPhase : Phase
[+] def finalize ( ) : Unit
[+] def flattenPhase : Phase
[+] def fresh : FreshContext

A fresh clone of this context.

[+] def freshNames : FreshNameCreator

The current fresh name creator

[+] final def gadt : GADTMap
[+] protected def gadt_= ( gadt: GADTMap ) : Unit
[+] def genBCodePhase : Phase
[+] def getSource ( file: AbstractFile , codec: => Codec ) : SourceFile

Sourcefile corresponding to given abstract file, memoized

[+] def getSource ( path: PathName ) : SourceFile

Sourcefile with given path name, memoized

[+] def getSource ( path: String ) : SourceFile

Sourcefile with given path, memoized

[+] def getSource$default$2 : Codec

Sourcefile corresponding to given abstract file, memoized

[+] def gettersPhase : Phase
[+] def hashCode : Int
[+] def implicits : ContextualImplicits
[+] protected def implicitsCache_= ( x$1: ContextualImplicits ) : Unit

The new implicit references that are introduced by this scope

[+] def importContext ( imp: Import [ Nothing <: Any ] , sym: Symbol ) : FreshContext

A new context that summarizes an import statement

[+] final def importInfo : ImportInfo
[+] protected def importInfo_= ( importInfo: ImportInfo ) : Unit
[+] protected def init ( outer: Context ) : Context & Context
[+] def initialize ( ) ( implicit ctx: Context ) : Unit
[+] 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 isInlineContext : Boolean

Is this a context for typechecking an inlined body?

[+] def isNonEmptyScopeContext : Boolean

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

[+] def isSelfContained : Boolean
[+] def jfile : Optional [ JFile ]
[+] def lambdaLiftPhase : Phase
[+] def length : Int
[+] def lineContent ( offset: Int ) : String

The content of the line containing position offset

[+] def lineToOffset ( index: Int ) : Int

Map line to offset of first character in line

[+] def lineToOffsetOpt ( index: Int ) : Option [ Int ]

Like lineToOffset, but doesn't crash if the index is out of bounds.

[+] def maskMode ( mode: Mode ) : Context
[+] 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
[+] def name : String
[+] def ne ( x$0: Object ) : Boolean
[+] def nextId : Int
[+] def nextLine ( offset: Int ) : Int

The start index of the line following the one containing position offset

[+] def nextSymId : Int
[+] def notify ( ) : Unit
[+] def notifyAll ( ) : Unit
[+] def offsetToLine ( offset: Int ) : Int

Convert offset to line in this source file Lines are numbered from 0

[+] final def outer : Context
[+] protected def outer_= ( outer: Context ) : Unit
[+] def outersIterator : Iterator [ Context ]

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

[+] final def owner : Symbol
[+] protected def owner_= ( owner: Symbol ) : Unit
[+] def path : String
[+] def pathName : PathName
[+] def patmatPhase : Phase
[+] def pendingUnderlying : HashSet [ Type ]
[+] final def period : Period
[+] protected def period_= ( period: Period ) : Unit
[+] def phases : Array [ Phase ]
[+] def picklerPhase : Phase
[+] def platform : Platform
[+] def positionInUltimateSource ( position: SourcePosition ) : SourcePosition

Map a position to a position in the underlying source file. For regular source files, simply return the argument.

[+] def postTyperPhase : Phase
[+] def printerFn : Context => Printer

The current plain printer

[+] def profiler : Profiler

The current compiler-run profiler

[+] def property ( key: Key [ T ] ) : Option [ T ]
[+] def refchecksPhase : Phase
[+] def reifyQuotesPhase : Phase
[+] def reporter : Reporter

The current reporter

[+] def retractMode ( mode: Mode ) : Context
[+] def run : Run

The current compiler-run

[+] def sbtCallback : AnalysisCallback

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

[+] def sbtExtractDependenciesPhase : Phase
[+] final def scope : Scope
[+] protected def scope_= ( scope: Scope ) : Unit
[+] final def searchHistory : SearchHistory
[+] protected def searchHistory_= ( searchHistory: SearchHistory ) : Unit
[+] def settings : ScalaSettings
[+] def settingsState : SettingsState

The current settings values

[+] def shouldExplain ( cont: MessageContainer ) : Boolean
[+] final def source : SourceFile
[+] private def sourceCtx_= ( x$1: SimpleIdentityMap [ SourceFile, Context ] ) : Unit
[+] protected def source_= ( source: SourceFile ) : Unit
[+] def start : Int

The start of this file in the underlying source file

[+] def startColumnPadding ( offset: Int ) : String

The padding of the column corresponding to offset, includes tabs

[+] def startOfLine ( offset: Int ) : Int

The index of the first character of the line containing position offset

[+] final def store : Store
[+] protected def store_= ( store: Store ) : Unit
[+] 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 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.

[+] def synchronized ( x$0: X0 ) : X0
[+] def tabInc : Int

Tab increment; can be overridden

[+] final def test ( op: Context => T ) : T

Run op as if it was run in a fresh explore typer state, but possibly optimized to re-use the current typer state.

[+] 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 toString : String
[+] final def tree : Tree [ Untyped <: Any ]
[+] protected def tree_= ( tree: Tree [ Untyped <: Any ] ) : Unit
[+] final def typeAssigner : TypeAssigner
[+] protected def typeAssigner_= ( typeAssigner: TypeAssigner ) : Unit
[+] final def typeComparer : TypeComparer
[+] protected def typeComparer_= ( typeComparer: TypeComparer ) : Unit
[+] def typerPhase : Phase
[+] final def typerState : TyperState
[+] protected def typerState_= ( typerState: TyperState ) : Unit
[+] def underlying : SourceFile

The underlying source file

[+] def uniqueNamedTypes : NamedTypeUniques
[+] def uniques : HashSet [ Type ]
[+] def useColors : Boolean

Should use colors when printing?

[+] def verbose : Boolean

Is the verbose option set?

[+] def wait ( ) : Unit
[+] def wait ( x$0: Long , x$1: Int ) : Unit
[+] def wait ( x$0: Long ) : 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
[+] final def withSource ( source: SourceFile ) : Context