Contexts

dotty.tools.dotc.core.Contexts
object Contexts

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Self type
Contexts.type

Members list

Type members

Classlikes

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:

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

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

A context base defines state and associated methods that exist once per compiler run.

A context base defines state and associated methods that exist once per compiler run.

Attributes

Supertypes
trait Plugins
trait PhasesBase
class ContextState
class Object
trait Matchable
class Any
Show all
class ContextPool

Attributes

Supertypes
class Object
trait Matchable
class Any
Known subtypes
class ContextState

The essential mutable state of a context base, collected into a common class

The essential mutable state of a context base, collected into a common class

Attributes

Supertypes
class Object
trait Matchable
class Any
Known subtypes
class ContextBase

Attributes

Supertypes
class ContextPool
class Object
trait Matchable
class Any
class FreshContext(base: ContextBase) extends Context

A fresh context allows selective modification of its attributes using the with... methods.

A fresh context allows selective modification of its attributes using the with... methods.

Attributes

Companion
object
Supertypes
class Context
class Object
trait Matchable
class Any
object FreshContext

Attributes

Companion
class
Supertypes
class Object
trait Matchable
class Any
Self type

Attributes

Supertypes
class ContextPool
class Object
trait Matchable
class Any
class TSContextPool extends ContextPool

Attributes

Supertypes
class ContextPool
class Object
trait Matchable
class Any
Known subtypes
object ops

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
ops.type

Value members

Concrete methods

inline def atNextPhase[T](inline op: Context ?=> T)(using Context): T
inline def atPeriod[T](pd: Period)(inline op: Context ?=> T)(using Context): T

Execute op at given period

Execute op at given period

Attributes

inline def atPhase[T](pid: PhaseId)(inline op: Context ?=> T)(using Context): T

Execute op at given phase id

Execute op at given phase id

Attributes

inline def atPhase[T](phase: Phase)(inline op: Context ?=> T)(using Context): T

Execute op at given phase

Execute op at given phase

Attributes

inline def atPhaseBeforeTransforms[T](inline op: Context ?=> T)(using Context): T

Execute op at the current phase if it's before the first transform phase, otherwise at the last phase before the first transform phase.

Execute op at the current phase if it's before the first transform phase, otherwise at the last phase before the first transform phase.

Note: this should be used instead of atPhaseNoLater(ctx.picklerPhase) because the later won't work if the Pickler phase is not present (for example, when using QuoteCompiler).

Attributes

inline def atPhaseNoEarlier[T](limit: Phase)(inline op: Context ?=> T)(using Context): T
inline def atPhaseNoLater[T](limit: Phase)(inline op: Context ?=> T)(using Context): T
inline def comparing[T](inline op: TypeComparer => T)(using Context): T
inline def ctx(using ctx: Context): Context

The current context

The current context

Attributes

inline def explore[T](inline op: Context ?=> T)(using Context): T

Run op with a pool-allocated context that has an ExporeTyperState.

Run op with a pool-allocated context that has an ExporeTyperState.

Attributes

inline def exploreInFreshCtx[T](inline op: FreshContext ?=> T)(using Context): T

Run op with a pool-allocated FreshContext that has an ExporeTyperState.

Run op with a pool-allocated FreshContext that has an ExporeTyperState.

Attributes

inline def inContext[T](c: Context)(inline op: Context ?=> T): T

Run op with given context

Run op with given context

Attributes

inline def inMode[T](mode: Mode)(inline op: Context ?=> T)(using ctx: Context): T
inline def runWithOwner[T](owner: Symbol)(inline op: Context ?=> T)(using Context): T

Run op with a pool-allocated context that has the given owner.

Run op with a pool-allocated context that has the given owner.

Attributes

inline def withFreshTyperState[T](inline op: Context ?=> T, inline commit: T => Context ?=> Boolean)(using Context): T

Run op with a pool-allocated context that has a fresh typer state. Commit the typer state if commit applied to op's result returns true.

Run op with a pool-allocated context that has a fresh typer state. Commit the typer state if commit applied to op's result returns true.

Attributes

inline def withMode[T](mode: Mode)(inline op: Context ?=> T)(using ctx: Context): T
inline def withoutMode[T](mode: Mode)(inline op: Context ?=> T)(using ctx: Context): T

Concrete fields

Givens

Givens

given ops: ops.type

Extensions

Extensions

extension (c: Context)
final def addMode(mode: Mode): Context
final def retractMode(mode: Mode): Context
final def withModeBits(mode: Mode): Context
extension (c: FreshContext)
final def addMode(mode: Mode): FreshContext
final def retractMode(mode: Mode): FreshContext