Performance option used by cmdline driver.
If the diagnostics option is not already set, gives a message explaining this option.
Begins with a \n\n, so an error message can look like m!"some error occurred{useDiagnosticMsg}".
The double newline gives better visual separation from the main error message
Instances For
Creates a user-accessible unique name of the following structure:
<name prefix>.<infix>_<numeric components>_...
Uniqueness is guaranteed for the current branch of elaboration. When entering parallelism and other
branching elaboration steps, mkChild must be used (automatically done in wrapAsync*).
Instances For
Instances For
- getDeclNGen : m DeclNameGenerator
- setDeclNGen : DeclNameGenerator → m Unit
Instances
Creates a new name for use as an auxiliary declaration that can be assumed to be globally unique.
Uniqueness is guaranteed for the current branch of elaboration. When entering parallelism and other
branching elaboration steps, mkChild must be used (automatically done in wrapAsync*).
Instances For
Adjusts the namePrefix of getDeclNGen to the given name and resets the nested counter.
Instances For
Boolean options resolved eagerly into a single word, so that hot paths test a bit instead of looking
the option up in a KVMap. The word is recomputed wherever the options change (withOptions and
Core.Context.setOptions) and defaulted from them at construction; Core.Context.optionFlags_eq
guarantees that it always agrees with the options in scope.
Bits 0 to 8 are the definitional-equality and unfolding compatibility flags read on every step of
isDefEq and whnf. Bit 9 is diagnostics.
- bits : UInt16
Instances For
Instances For
Resolves the flags from opts.
The definitional-equality options are read by name because their declarations live in modules this one does not import.
Instances For
The dependencies observed by a recording computation, accumulated in Core.State.recordedDeps.
A result cached by the computation stays valid as long as they give the same answers. Currently used
by type class resolution, see Lean.Meta.SynthInstance.
The names of the options looked up, deduplicated.
- base : Options
The options in effect when recording started, against which a cached entry is later validated. A lookup answering differently was served by a write inside the computation (
Lean.withSetOption), so it does not depend on the ambient options and is not recorded. The recorded answers are read from it, so a stored entry keeps it, restricted to the looked-up names. The generation-tracked extensions read, as
EnvExtension.genIdx?and observed generation.- baseTrackedGen : Nat
Environment.trackedGenwhen recording started, or when the dependencies were last validated. Together withbaseChangeLogPosit is the stamp of the dependencies: as long as the environment'strackedGenand change log length still equal the stamp, none of the environment dependencies can have changed since then. - baseChangeLogPos : Nat
Length of
Environment.declChangeLogwhen recording started, or when the dependencies were last validated; seebaseTrackedGen. - baseConstGen : Nat
Environment.constGenwhen recording started.Environment.checkDeclChangeLogignores the changes logged sincebaseChangeLogPosto declarations added after recording started, as the recorded computation cannot have observed them.
Instances For
Cache for the CoreM monad
- instLevelType : InstantiateLevelCache
- instLevelValue : InstantiateLevelCache
Instances For
State for the CoreM monad.
- env : Environment
Current environment.
- nextMacroScope : MacroScope
Next macro scope. We use macro scopes to avoid accidental name capture.
- ngen : NameGenerator
Name generator for producing unique
FVarIds,MVarIds, andLMVarIds - auxDeclNGen : DeclNameGenerator
Name generator for creating persistent auxiliary declarations. Separate from
ngento keep numbers smaller and create user-accessible names. - traceState : TraceState
Trace messages
- cache : Cache
Cache for instantiating universe polymorphic declarations.
- recordedDeps : RecordedDeps
The dependencies observed by the recording computation, if enabled (
Core.Context.isRecordingDeps); they become the dependency log of the cache entry it produces, seeLean.Meta.SynthInstanceCache. Not restored bySavedState.restore, so that dependencies observed on a rolled-back path are kept. - messages : MessageLog
Message log.
- infoState : Elab.InfoState
Info tree. We have the info tree here because we want to update it while adding attributes.
- snapshotTasks : Array (Language.SnapshotTask Language.SnapshotTree)
Snapshot trees of asynchronous subtasks. As these are untyped and reported only at the end of the command's main elaboration thread, they are only useful for basic message log reporting; for incremental reporting and reuse within a long-running elaboration thread, types rooted in
CommandParsedSnapshotneed to be adjusted.
Instances For
The pointer-typed fields of Core.Context that are not updated on a recursion or withRef step.
withReader can never reuse the Context record, so every withIncRecDepth and withRef pays one
reference count increment per pointer field. Grouping the remaining fields into a subobject makes
them cost a single increment together.
Rarely-updated fields in particular tend to be MT during async elaboration, which makes RC traffic elisions on them even more valueable, explaining an outsized task-clock vs instrs impact of this optimization.
- fileName : String
Name of the file being compiled.
- fileMap : FileMap
Auxiliary datastructure for converting
String.Posinto Line/Column number. - options : Options
- maxRecDepth : Nat
- currNamespace : Name
- initHeartbeats : Nat
- maxHeartbeats : Nat
- quotContext : Name
- currMacroScope : MacroScope
- cancelTk? : Option IO.CancelToken
If set, used to cancel elaboration from outside when results are not needed anymore.
- inheritedTraceOptions : Std.HashSet Name
Cache of
Lean.inheritedTraceOptions.
Instances For
Context for the CoreM monad.
- currRecDepth : Nat
- ref : Syntax
- optionFlags : OptionFlags
Boolean options resolved from
options; seeLean.OptionFlags. Enforces that
optionFlagsis always consistent withoptions.- suppressElabErrors : Bool
If set (when
showPartialSyntaxErrorsis not set and parsing failed), suppresses most elaboration errors; see alsologMessagebelow. - isRecordingDeps : Bool
Whether the current computation records its dependencies into
Core.State.recordedDeps. While set, reading state that is not recorded panics, see instanceMonadOptions CoreM.
Instances For
Replaces the options, re-resolving the fields derived from them. Changing options directly leaves
optionFlags behind, which optionFlags_eq rejects; use this instead.
Instances For
CoreM is a monad for manipulating the Lean environment.
It is the base monad for MetaM.
The main features it provides are:
- name generator state
- environment state
- Lean options context
- the current open namespace
Instances For
The options of ctx, panicking inside a recording computation. Out of line, as getOptions is
inlined at every call site.
Instances For
Applies f to the options in scope of x, without the recording check of withOptions. Each use
must argue that f's result on an option read through Lean.getRecordedOption does not depend on
the ambient options; Lean.withSetOption does so by construction.
Instances For
Reports a withOptions call inside a recording computation and leaves the options unchanged.
Out of line, as withOptions is inlined at every call site; it takes no argument so that f
stays a known function there.
Instances For
Instances For
Instances For
Instances For
Instances For
Instances For
- passedHeartbeats : Nat
Number of heartbeats passed inside
withRestoreOrSaveFull, not used otherwise.
Instances For
Incremental reuse primitive: if reusableResult? is none, runs act and returns its result
together with the saved monadic state after act including the heartbeats used by it. If
reusableResult? on the other hand is some (a, state), restores full state including heartbeats
used and returns (a, state).
The intention is for steps that support incremental reuse to initially pass none as
reusableResult? and store the result and state in a snapshot. In a further run, if reuse is
possible, reusableResult? should be set to the previous result and state, ensuring that the state
after running withRestoreOrSaveFull is identical in both runs. Note however that necessarily this
is only an approximation in the case of heartbeats as heartbeats used by withRestoreOrSaveFull
itself after calling act as well as by reuse-handling code such as the one supplying
reusableResult? are not accounted for.
Instances For
Restore backtrackable parts of the state.
Instances For
Creates a name from n that is guaranteed to be unique.
This is intended to be used for creating inaccessible user names for free variables and constants.
It works by adding a fresh macro scope to n.
Applying Lean.Name.eraseMacroScopes to the resulting name yields n.
See also Lean.LocalContext.getUnusedName (for creating a new accessible user name that is
unused in the local context) and Lean.Meta.mkFreshBinderNameForTactic (for creating names
that are conditionally inaccessible, depending on the current value of the tactic.hygiene option).
Instances For
Run a CoreM monad in IO.
Note that the value of ctx.initHeartbeats is ignored and replaced with IO.getNumHeartbeats.
Instances For
Throws an internal interrupt exception if cancellation has been requested. The exception is not
caught by try catch but is intended to be caught by Command.withLoggingExceptions at the top
level of elaboration. In particular, we want to skip producing further incremental snapshots after
the exception has been thrown.
Like checkSystem but without the global heartbeat check, for callers that have their own
heartbeat tracking (e.g. SynthInstance).
Instances For
withIncRecDepth for a monad m such that [MonadControlT CoreM n].
Also checks for cancellation, so that recursive elaboration functions
(inferType, whnf, isDefEq, …) respond promptly to interrupt requests.
Instances For
Instances For
Returns the current log and then resets its messages while adjusting MessageLog.hadErrors. Used
for incremental reporting during elaboration of a single command.
Instances For
Returns the current set of tasks added by logSnapshotTask and then resets it. When
saving/restoring state of an action that may have logged such tasks during incremental reuse, this
function must be used to store them in the corresponding snapshot tree; otherwise, they will leak
outside and may be cancelled by a later step, potentially leading to inconsistent state being
reused.
Instances For
Includes a given task (such as from wrapAsyncAsSnapshot) in the overall snapshot tree for this
command's elaboration, making its result available to reporting and the language server. The
reporter will not know about this snapshot tree node until the main elaboration thread for this
command has finished so this function is not useful for incremental reporting within a longer
elaboration thread but only for tasks that outlive it such as background kernel checking or proof
elaboration.
Instances For
Wraps the given action for use in EIO.asTask etc., discarding its final monadic state.
Instances For
Option for capturing output to stderr during elaboration.
Creates snapshot reporting given withIsolatedStreams output and diagnostics and traces from the
given state.
Instances For
Wraps the given action for use in BaseIO.asTask etc., discarding its final state except for
logSnapshotTask tasks, which are reported as part of the returned tree. The given cancellation
token, if any, should be stored in a SnapshotTask for the server to trigger it when the result is
no longer needed.
Instances For
Instances For
Runs the given computation with the option name set to v. Unlike withOptions, this is allowed
inside a computation recording its dependencies: v does not depend on the ambient options, so a
recorded read of name in this scope observes v in every context.
Instances For
withSetOptionByName for an option given as a Lean.Option.
Instances For
Instances For
Instances For
Return true if ex was generated by throwMaxHeartbeat.
This function is a bit hackish. The heartbeat exception should probably be an internal exception.
We used a similar hack at Exception.isMaxRecDepth
Instances For
This ref exists to break a linking cycle that goes as follows:
- We start in
Environment.lean, there we have functions referencing the compiler such asevalConst - This pulls in the entire compiler transitively as well as all of its dependents
- The compiler relies on things like WHNF to inspect types
- WHNF in turn imports Environment
On Windows this causes a large amount of symbols to be included in one DLL as everything that
imports the Environment instantly requires a large chunk of the Meta stack to be linked. This ref
breaks the cycle by making compileDeclsImpl a "dynamic" call through the ref that is not visible
to the linker. In the compiler there is a matching builtin_initialize to set this ref to the
actual implementation of compileDeclsRef.
Inside a recording computation, records the current generation of the generation-tracked extension
ext in Core.State.recordedDeps. Callers then read the state with (genRecorded := true).
Instances For
Reads an option and, inside a recording computation, records the lookup in
Core.State.recordedDeps, see Lean.Meta.SynthInstanceCache. Outside a recording computation
this is Lean.Option.get.
Instances For
The boolean options in effect, resolved eagerly; see Lean.OptionFlags.
Instances For
Return true if diagnostic information collection is enabled.
Instances For
Return true if the exception was generated by one of our resource limits.
Instances For
Custom try-catch for all monads based on CoreM. We usually don't want to catch "runtime
exceptions" these monads, but on CommandElabM or, in specific cases, using tryCatchRuntimeEx.
See issues #2775 and #2744 as well as MonadAlwaysExcept. Also, we never want to catch interrupt
exceptions inside the elaborator.
Instances For
Returns true if the given message kind has not been reported in the message log,
and then mark it as logged. Otherwise, returns false.
We use this API to ensure we don't log the same kind of warning multiple times.
Instances For
Allows realizeConst calls for the given declaration in all derived environment branches.
Realizations will run using the given environment and options to ensure deterministic results. Note
that while we check that the function isn't called before the declaration is actually added to the
environment, we cannot automatically check that it isn't otherwise called too early in the sense
that helper declarations and environment extension state that may be relevant to realizations may
not have been added yet. We do check that we are not calling it from a different branch than c was
added on, which would be definitely too late. Thus, this function should generally be called in
elaborators calling addDecl (when that declaration is a plausible target for realization) at the
latest possible point, i.e. at the very end of the elaborator or just before a first realization may
be triggered if any.
Instances For
Execute x, and apply f to the produced error message
Instances For
Execute x. If it throws an error, indent and prepend msg to it.