docs/analyzers/Analyzer Actions Semantics.md
Definitions:
DiagnosticAnalyzer.IOperation APIs.IOperation API for semantic analysis of executable code for improved performance and simpler, language-agnostic implementation.ISymbol. For a namespace or type symbol, these are the members returned by INamespaceOrTypeSymbol.GetMembers API, which include nested symbols. Method, field, event and property symbols have no member symbols.Axioms:
DiagnosticAnalyzer.Initialize method by invoking AnalysisContext.EnableConcurrentExecution. Actions of different analyzers may execute concurrently. (This is likely to be refined as we develop more sophisticated concurrency strategies, but it will remain true that actions will generally not require locks to avoid races.)Ordering of actions:
The DiagnosticAnalyzer.Initialize method of an analyzer is invoked before any actions of an analyzer can be applied. The actions registered by Initialize methods form the initial set of actions used for each compilation. Initialize method may be invoked multiple times on an analyzer instance in a session, but is guaranteed to be invoked only once for any given compilation.
The following rules related to action invocation apply per compilation or per any environmental change that invalidates prior analysis (e.g. changes to analyzer options or changes to non-compiled documents used by analyzers). For purposes of this specification, such environmental changes act as if they create a new compilation.
There are no ordering constraints for the invocations of any actions, except those introduced by start and end actions (compilation start, compilation end, symbol start, symbol end, operation block start, operation block end, code bock start, and code block end actions). Invocations of actions of one kind may be interleaved with invocations of actions of another kind. A given host environment might appear to provide a predictable order—for example, invoking syntax tree actions before semantic model actions, or symbol actions before code block actions, but depending on such an ordering is not safe.
SymbolKind, before any of the analyzer’s other kinds of actions are invoked on the symbol or the symbol's members. A symbol start action can register following actions:
Summarizing the ordering rules:
Implementation freedom:
If an implementation determines that a given action will have equivalent effects in two compilations within a session, it can omit invoking the action for the second compilation and instead retain the effects of invoking it for the first compilation. For example, in an IDE, edits to a source document will not necessarily cause actions to be invoked for unrelated symbols etc. defined in other documents.
A host environment may delay invocation of actions arbitrarily and indefinitely. For example, an IDE might delay invoking some actions until a significant pause in editing activity, during which time several compilations might be initiated. Some actions might not execute at all for the interim compilations, because they will be cancelled when the next compilation begins. In such cases, it is possible for a compilation start action to run without its corresponding compilation end actions ever running for a given compilation, and likewise a code block start action can run without its corresponding code block end actions ever running. Therefore, end actions cannot be relied upon to free resources acquired by start actions.