Lean 4.9.0 (2024-07-01)
Language features, tactics, and metaprograms
-
Definition transparency
-
#4053 adds the
sealandunsealcommands, which make definitions locally be irreducible or semireducible. -
#4061 marks functions defined by well-founded recursion with
@[irreducible]by default, which should prevent the expensive and often unfruitful unfolding of such definitions (see breaking changes below).
-
-
Incrementality
-
#3940 extends incremental elaboration into various steps inside of declarations: definition headers, bodies, and tactics.
-
250994 and 67338b add
@[incremental]attribute to mark an elaborator as supporting incremental elaboration. -
#4259 improves resilience by ensuring incremental commands and tactics are reached only in supported ways.
-
#4268 adds special handling for
:= byso that stray tokens in tactic blocks do not inhibit incrementality. -
#4308 adds incremental
havetactic. -
#4340 fixes incorrect info tree reuse.
-
#4364 adds incrementality for careful command macros such as
set_option in theorem,theorem foo.bar, andlemma. -
#4395 adds conservative fix for whitespace handling to avoid incremental reuse leading to goals in front of the text cursor being shown.
-
#4407 fixes non-incremental commands in macros blocking further incremental reporting.
-
#4436 fixes incremental reporting when there are nested tactics in terms.
-
#4459 adds incrementality support for
nextandiftactics. -
#4554 disables incrementality for tactics in terms in tactics.
-
-
Functional induction
-
#4135 ensures that the names used for functional induction are reserved.
-
#4327 adds support for structural recursion on reflexive types. For example,
inductive Many (α : Type u) where | none : Many α | more : α → (Unit → Many α) → Many α def Many.map {α β : Type u} (f : α → β) : Many α → Many β | .none => .none | .more x xs => .more (f x) (fun _ => (xs ()).map f) #check Many.map.induct /- Many.map.induct {α β : Type u} (f : α → β) (motive : Many α → Prop) (case1 : motive Many.none) (case2 : ∀ (x : α) (xs : Unit → Many α), motive (xs ()) → motive (Many.more x xs)) : ∀ (a : Many α), motive a -/
-
-
#3903 makes the Lean frontend normalize all line endings to LF before processing. This lets Lean be insensitive to CRLF vs LF line endings, improving the cross-platform experience and making Lake hashes be faithful to what Lean processes.
-
#4130 makes the tactic framework be able to recover from runtime errors (for example, deterministic timeouts or maximum recursion depth errors).
-
splittactic -
applytactic-
#3929 makes error message for
applyshow implicit arguments in unification errors as needed. ModifiesMessageDatatype (see breaking changes below).
-
-
casestactic-
#4224 adds support for unification of offsets such as
x + 20000 = 20001incasestactic.
-
-
omegatactic -
simptactic-
#4176 makes names of erased lemmas clickable.
-
#4208 adds a pretty printer for discrimination tree keys.
-
#4202 adds
Simp.Config.indexconfiguration option, which controls whether to use the full discrimination tree when selecting candidate simp lemmas. Whenindex := false, only the head function is taken into account, like in Lean 3. This feature can help users diagnose tricky simp failures or issues in code from libraries developed using Lean 3 and then ported to Lean 4.In the following example, it will report that
foois a problematic theorem.opaque f : Nat → Nat → Nat @[simp] theorem foo : f x (x, y).2 = y := by sorry example : f a b ≤ b := by set_option diagnostics true in simp (config := { index := false }) /- [simp] theorems with bad keys foo, key: f _ (@Prod.mk ℕ ℕ _ _).2 -/With the information above, users can annotate theorems such as
foousingno_indexfor problematic subterms. Example:opaque f : Nat → Nat → Nat @[simp] theorem foo : f x (no_index (x, y).2) = y := by sorry example : f a b ≤ b := by simp -- `foo` is still applied with `index := true`
-
#4274 prevents internal
matchequational theorems from appearing in simp trace. -
#4177 and #4359 make
simpcontinue even if a simp lemma does not elaborate, if the tactic state is in recovery mode. -
#4341 fixes panic when applying
@[simp]to malformed theorem syntax. -
#4345 fixes
simpso that it does not use the forward version of a user-specified backward theorem. -
#4352 adds missing
dsimpsimplifications for fixed parameters of generated congruence theorems. -
#4362 improves trace messages for
simpso that constants are hoverable.
-
-
Elaboration
-
#4046 makes subst notation (
he ▸ h) try rewriting in both directions even when there is no expected type available. -
#3328 adds support for identifiers in autoparams (for example,
rflin(h : x = y := by exact rfl)). -
#4096 changes how the type in
letandhaveis elaborated, requiring that any tactics in the type be evaluated before proceeding, improving performance. -
#4215 ensures the expression tree elaborator commits to the computed "max type" for the entire arithmetic expression.
-
#4267 cases signature elaboration errors to show even if there are parse errors in the body.
-
#4368 improves error messages when numeric literals fail to synthesize an
OfNatinstance, including special messages warning when the expected type of the numeral can be a proposition. -
#4643 fixes issue leading to nested error messages and info trees vanishing, where snapshot subtrees were not restored on reuse.
-
#4657 calculates error suppression per snapshot, letting elaboration errors appear even when there are later parse errors (RFC #3556).
-
-
Metaprogramming
-
Work toward implementing
grindtactic-
0a515e and #4164 add
grind_normandgrind_norm_procattributes and@[grind_norm]theorems. -
#4170, #4221, and #4249 create
grindpreprocessor and core module. -
#4235 and d6709e add special
casestactic togrindalong with@[grind_cases]attribute to mark types that thiscasestactic should automatically apply to. -
#4243 adds special
injection?tactic togrind.
-
-
Other fixes or improvements
-
#4065 fixes a bug in the
Nat.reduceLeDiffsimproc. -
#3969 makes deprecation warnings activate even for generalized field notation ("dot notation").
-
#4132 fixes the
sorryterm so that it does not activate the implicit lambda feature -
9803c5 and 47c8e3 move
cdotandcalcparsers toLeannamespace. -
#4252 fixes the
casetactic so that it is usable in macros by having it erase macro scopes from the tag. -
#4335 fixes bugs in partial
calctactic when there is mdata or metavariables. -
#4329 makes
termination_by?report unused each unused parameter as_.
-
Language server, widgets, and IDE extensions
-
#4066 fixes features like "Find References" when browsing core Lean sources.
-
#4254 allows embedding user widgets in structured messages. Companion PR is vscode-lean4#449.
-
#4445 makes watchdog more resilient against badly behaving clients.
Library
-
#4059 upstreams many
ListandArrayoperations and theorems from Batteries. -
#4055 removes the unused
Inhabitedinstance forSubtype. -
#3967 adds dates in existing
@[deprecated]attributes. -
#4231 adds boilerplate
Char,UInt, andFintheorems. -
#4205 fixes the
MonadStoretype classes to usesemiOutParam. -
#4350 renames
IsLawfulSingletontoLawfulSingleton. -
Nat -
Array-
#4074 improves the functional induction principle
Array.feraseIdx.induct.
-
-
List-
#4172 removes
@[simp]fromList.length_pos.
-
-
Option -
BitVec-
Theorems: #3920, #4095, #4075, #4148, #4165, #4178, #4200, #4201, #4298, #4299, #4257, #4179, #4321, #4187.
-
#4193 adds simprocs for reducing
x >>> iandx <<< iwhereiis a bitvector literal. -
#4194 adds simprocs for reducing
(x <<< i) <<< jand(x >>> i) >>> jwhereiandjare natural number literals. -
#4229 redefines
rotateLeft/rotateRightto use modulo reduction of shift offset. -
0d3051 makes
<num>#<term>bitvector literal notation global.
-
-
Char/String -
HashMap-
#4248 fixes implicitness of typeclass arguments in
HashMap.ofList.
-
-
IO-
#4036 adds
IO.Process.getCurrentDirandIO.Process.setCurrentDirfor adjusting the current process's working directory.
-
Lean internals
-
Defeq and WHNF algorithms
-
Definition transparency
-
#4052 adds validation to application of
@[reducible]/@[semireducible]/@[irreducible]attributes (withlocal/scopedmodifiers as well). Settingset_option allowUnsafeReductibility trueturns this validation off.
-
-
Inductive types
-
Diagnostics and profiling
-
Typeclass resolution
-
#4119 fixes multiple issues with TC caching interacting with
synthPendingDepth, addsmaxSynthPendingDepthoption with default value1. -
#4210 ensures local instance cache does not contain multiple copies of the same instance.
-
#4216 fix handling of metavariables, to avoid needing to set the option
backward.synthInstance.canonInstancestofalse.
-
-
Other fixes or improvements
-
#4080 fixes propagation of state for
Lean.Elab.Command.liftCoreMandLean.Elab.Command.liftTermElabM. -
#3944 makes the
Reprderiving handler be consistent betweenstructureandinductivefor how types and proofs are erased. -
#4113 propagates
maxHeartbeatsto kernel to control "(kernel) deterministic timeout" error. -
#4128 catches stack overflow in auto-bound implicits feature.
-
#4129 adds
tryCatchRuntimeExcombinator to replacecatchRuntimeExreader state. -
#4155 simplifies the expression canonicalizer.
-
#4185 makes congruence theorem generators clean up type annotations of argument types.
-
#4192 fixes restoration of infotrees when auto-bound implicit feature is activated, fixing a pretty printing error in hovers and strengthening the unused variable linter.
-
dfb496 fixes
declareBuiltinto allow it to be called multiple times per declaration. -
#4569 fixes an issue introduced in a merge conflict, where the interrupt exception was swallowed by some
tryCatchRuntimeExuses. -
#4584 (backported as b056a0) adapts kernel interruption to the new cancellation system.
-
Compiler, runtime, and FFI
-
#4100 improves reset/reuse algorithm; it now runs a second pass relaxing the constraint that reused memory cells must only be for the exact same constructor.
-
#2903 fixes segfault in old compiler from mishandling
noConfusionapplications. -
#4311 fixes bug in constant folding.
-
#3915 documents the runtime memory layout for inductive types.
Lake
-
#4518 makes trace reading more robust. Lake now rebuilds if trace files are invalid or unreadable and is backwards compatible with previous pure numeric traces.
-
#4057 adds support for docstrings on
requirecommands. -
#4088 improves hovers for
family_defandlibrary_datacommands. -
#4147 adds default
README.mdto package templates -
#4261 extends
lake testhelp page, adds help page forlake check-test, addslake lintand tag@[lint_driver], adds support for specifying test and lint drivers from dependencies, addstestDriverArgsandlintDriverArgsoptions, adds support for library test drivers, makeslake check-testandlake check-lintonly load the package without dependencies. -
#4270 adds
lake packandlake unpackfor packing and unpacking Lake build artifacts from an archive. -
#4083 Switches the manifest format to use
major.minor.patchsemantic versions. Major version increments indicate breaking changes (e.g., new required fields and semantic changes to existing fields). Minor version increments (after0.x) indicate backwards-compatible extensions (e.g., adding optional fields, removing fields). This change is backwards compatible. Lake will still successfully read old manifests with numeric versions. It will treat the numeric versionNas semantic version0.N.0. Lake will also accept manifest versions with-suffixes (e.g.,x.y.z-foo) and then ignore the suffix. -
#4273 adds a lift from
JobMtoFetchMfor backwards compatibility reasons. -
#4351 fixes
LogIO-to-CliM-lifting performance issues. -
#4343 make Lake store the dependency trace for a build in the cached build long and then verifies that it matches the trace of the current build before replaying the log.
-
#4402 moves the cached log into the trace file (no more
.log.json). This means logs are no longer cached on fatal errors and this ensures that an out-of-date log is not associated with an up-to-date trace. Separately,.hashfile generation was changed to be more reliable as well. The.hashfiles are deleted as part of the build and always regenerate with--rehash. -
Other fixes or improvements
DevOps
-
#3984 adds a script (
script/rebase-stage0.sh) forgit rebase -ithat automatically updates each stage0. -
#4108 finishes renamings from transition to Std to Batteries.
-
#4109 adjusts the Github bug template to mention testing using live.lean-lang.org.
-
#4136 makes CI rerun only when
full-cilabel is added or removed. -
#4175 and 72b345 switch to using
#guard_msgsto run tests as much as possible. -
#3125 explains the Lean4
pygmentslexer. -
#4247 sets up a procedure for preparing release notes.
-
#4032 modernizes build instructions and workflows.
-
#4255 moves some expensive checks from merge queue to releases.
-
#4265 adds aarch64 macOS as native compilation target for CI.
-
f05a82 restores macOS aarch64 install suffix in CI
-
#4317 updates build instructions for macOS.
-
#4333 adjusts workflow to update Batteries in manifest when creating
lean-pr-testing-NNNNMathlib branches. -
#4355 simplifies
lean4checkerstep of release checklist. -
#4361 adds installing elan to
pr-releaseCI step. -
#4628 fixes the Windows build, which was missing an exported symbol.
Breaking changes
While most changes could be considered to be a breaking change, this section makes special note of API changes.
-
Nat.zero_orandNat.or_zerohave been swapped (#4094). -
IsLawfulSingletonis nowLawfulSingleton(#4350). -
The
BitVecliteral notation is now<num>#<term>rather than<term>#<term>, and it is global rather than scoped. UseBitVec.ofNat w xrather thanx#wwhenxis a not a numeric literal (0d3051). -
BitVec.rotateLeftandBitVec.rotateRightnow take the shift modulo the bitwidth (#4229). -
These are no longer simp lemmas:
List.length_pos(#4172),Option.bind_eq_some(#4314). -
Types in
letandhave(both the expressions and tactics) may fail to elaborate due to new restrictions on what sorts of elaboration problems may be postponed (#4096). In particular, tactics embedded in the type will no longer make use of the type ofvaluein expressions such aslet x : type := value; body. -
Now functions defined by well-founded recursion are marked with
@[irreducible]by default (#4061). Existing proofs that hold by definitional equality (e.g.rfl) can be rewritten to explicitly unfold the function definition (usingsimp,unfold,rw), or the recursive function can be temporarily made semireducible (usingunseal f inbefore the command), or the function definition itself can be marked as@[semireducible]to get the previous behavior. -
Due to #3929:
-
The
MessageData.ofPPFormatconstructor has been removed. Its functionality has been split into two:-
for lazy structured messages, please use
MessageData.lazy; -
for embedding
FormatorFormatWithInfos, useMessageData.ofFormatWithInfos.
An example migration can be found in #3929.
-
-
The
MessageData.ofFormatconstructor has been turned into a function. If you need to inspectMessageData, you can pattern-match onMessageData.ofFormatWithInfos.
-