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
The current tree
The compiler callback implementation, or null if no callback will be called.
An optional diagostics buffer than is used by some checking code to provide more information in the buffer if it exists.
The current fresh name creator
The current bounds in force for type parameters appearing in a GADT
The currently active import info
The scope nesting level
A map in which more contextual properties can be stored
A counter for unique ids
The outer context
The current owner symbol
The current context
The current plain printer
The current compiler-run specific Info
The sbt callback implementation if we are run from sbt, null otherwise
The current scope
The history of implicit searches that are currently active
The current settings values
The current tree
The current type assigner or typer
The current type comparer
The context base at the root
A map from a superclass id to the typeref of the class that has it
If -Ydebug is on, the top of the stack trace where this context
was created, otherwise null
.
The standard definitions
Number of findMember calls on stack
The new implicit references that are introduced by this scope
The initial context
The last allocated superclass id
The symbol loaders
Next denotation transformer id
List of names which have a findMemberCall on stack, after Config.LogPendingFindMemberThreshold is reached.
The set of named types on which a currently active invocation of underlying during a controlled operation exists.
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...
Phases by id
The applicable settings
Phases with consecutive Transforms grouped into a single phase, Empty array if squashing is disabled
A map from a the typeref of a class to its superclass id
Number of recursive invocations of a show method on current stack
The number of recursive invocation of underlying on a NamedType during a controlled operation.
A table for hash consing unique named types
A table for hash consing unique refined types
A table for hash consing unique type bounds
A table for hash consing unique types
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.
An optional diagostics buffer than is used by some checking code to provide more information in the buffer if it exists.
The current bounds in force for type parameters appearing in a GADT
A map in which more contextual properties can be stored
A counter for unique ids
The history of implicit searches that are currently active
Generate text using op
, assuming a given precedence level prec
.
Generate text using op
, assuming a given precedence level prec
.
If new level prec
is lower than previous level, put text in parentheses.
Check that we are on the same thread as before
A map from a superclass id to the typeref of the class that has it
If -Ydebug is on, the top of the stack trace where this context
was created, otherwise null
.
The current precedence level
Textual representation of single denotation's declaration
Textual representation of symbol's declaration
Textual representation of all symbols in given list,
using dclText
for displaying each.
Is the debug option set?
Leave message in diagnostics buffer if it exists
The next outer context whose tree is a template or package definition
Does current phase use an erased types interpretation?
The context of expression expr
seen as a member of a statement sequence
A description of sym's location
Number of findMember calls on stack
A fresh clone of this context.
The fully qualified name of the symbol
The new implicit references that are introduced by this scope
A condensed context containing essential information of this but no outer contexts except the initial context. private var _condensed: CondensedContext...
Initializes the ContextBase
with a starting context.
This initializes the platform
and the definitions
.
Is this a context for the members of a class definition?
Is this a context that introduces an import clause?
Is this a context that introduces a non-empty scope?
The kind of the symbol
The last allocated superclass id
Textual representation of symbol and its location
If symbol's owner is a printable class C, the text "in C", otherwise ""
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.
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, possibley with with namespace suffix if debugNames is set: /L for local names, /V for other term names, /T for type names
Next denotation transformer id
Allocate and return next free superclass id
All outer contexts, ending in base.initialCtx
and then NoContext
List of names which have a findMemberCall on stack, after Config.LogPendingFindMemberThreshold is reached.
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...
Phases by id
A plain printer without any embellishments
The platform
Print all enclosing context's creation stacktraces
The current reporter
The loader that loads the members of root
The current source file; will be derived from current compilation unit.
Squash TreeTransform's beloning to same sublist to a single TreeTransformer Each TreeTransform gets own period, whereas a combined TreeTransformer gets...
Phases with consecutive Transforms grouped into a single phase, Empty array if squashing is disabled
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...
Perform string or text-producing operation op
so that only a
summarized text with given recursion depth is shown
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 super- or this-call context with given owner and locals.
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 name as a text
Textual representation of annotation
Textual representation of tree
Textual representation of all definitions in a scope using dclText
for each
Textual representation of constant
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 of denotation
Textual representation of type
Number of recursive invocations of a show method on current stack
The number of recursive invocation of underlying on a NamedType during a controlled operation.
A map that associates label and size of all uniques sets
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.
Should use colors when printing?
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...
Is the verbose option set?
This context at given phase. This method will always return a phase period equal to phaseId, thus will never return squashed phases