Dotty Documentation


object Contexts
extends Object with Serializable

[-] Constructors

[-] Members

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

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

[+] class ContextState

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

[+] @sharable object EmptyGADTMap
[+] class FreshContext

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

[+] final class FreshModeChanges
[+] object FreshModeChanges
[+] @Child @Child sealed abstract class GADTMap
[+] private class InitialContext

A class defining the initial context with given context base and set of possible settings.

[+] final class ModeChanges
[+] object ModeChanges
[+] @sharable object NoContext
[+] final class SmartGADTMap
[+] private val compilationUnitLoc : Location [ CompilationUnit ]
[+] private val compilerCallbackLoc : Location [ CompilerCallback ]
[+] private val freshNamesLoc : Location [ FreshNameCreator ]
[+] private val initialStore : Store
[+] private val printerFnLoc : Location [ Context => Printer ]
[+] private val profilerLoc : Location [ Profiler ]
[+] private val runLoc : Location [ Run ]
[+] private val sbtCallbackLoc : Location [ AnalysisCallback ]
[+] private val settingsStateLoc : Location [ SettingsState ]
[+] private val store1 : Store
[+] private val store2 : Store
[+] private val store3 : Store
[+] private val store4 : Store
[+] private val store5 : Store
[+] private val store6 : Store
[+] private val store7 : Store
[+] private val store8 : Store