Skip to content

Commit bd3003d

Browse files
committed
Merge branch 'master' of https://github.com/leanprover/lean4 into async-kernel
2 parents d3079a6 + 35e1554 commit bd3003d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+16507
-16654
lines changed

doc/dev/release_checklist.md

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,16 +147,10 @@ We'll use `v4.7.0-rc1` as the intended release version in this example.
147147
- You can monitor this at `https://github.com/leanprover/lean4/actions/workflows/ci.yml`, looking for the `v4.7.0-rc1` tag.
148148
- This step can take up to an hour.
149149
- (GitHub release notes) Once the release appears at https://github.com/leanprover/lean4/releases/
150-
- Edit the release notes on Github to select the "Set as a pre-release box".
151-
- If release notes have been written already, copy the section of `RELEASES.md` for this version into the Github release notes
152-
and use the title "Changes since v4.6.0 (from RELEASES.md)".
153-
- Otherwise, in the "previous tag" dropdown, select `v4.6.0`, and click "Generate release notes".
150+
- Verify that the release is marked as a prerelease (this should have been done automatically by the CI release job).
151+
- In the "previous tag" dropdown, select `v4.6.0`, and click "Generate release notes".
154152
This will add a list of all the commits since the last stable version.
155-
- Delete anything already mentioned in the hand-written release notes above.
156153
- Delete "update stage0" commits, and anything with a completely inscrutable commit message.
157-
- Briefly rearrange the remaining items by category (e.g. `simp`, `lake`, `bug fixes`),
158-
but for minor items don't put any work in expanding on commit messages.
159-
- (How we want to release notes to look is evolving: please update this section if it looks wrong!)
160154
- Next, we will move a curated list of downstream repos to the release candidate.
161155
- This assumes that there is already a *reviewed* branch `bump/v4.7.0` on each repository
162156
containing the required adaptations (or no adaptations are required).

src/Init/Data/BitVec/Basic.lean

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ We define many of the bitvector operations from the
2020
of SMT-LIBv2.
2121
-/
2222

23+
set_option linter.missingDocs true
24+
2325
/--
2426
A bitvector of the specified width.
2527
@@ -34,9 +36,9 @@ structure BitVec (w : Nat) where
3436
O(1), because we use `Fin` as the internal representation of a bitvector. -/
3537
toFin : Fin (2^w)
3638

37-
@[deprecated (since := "2024-04-12")]
38-
protected abbrev Std.BitVec := _root_.BitVec
39-
39+
/--
40+
Bitvectors have decidable equality. This should be used via the instance `DecidableEq (BitVec n)`.
41+
-/
4042
-- We manually derive the `DecidableEq` instances for `BitVec` because
4143
-- we want to have builtin support for bit-vector literals, and we
4244
-- need a name for this function to implement `canUnfoldAtMatcher` at `WHNF.lean`.

src/Init/Data/BitVec/Bitblast.lean

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ https://github.com/mhk119/lean-smt/blob/bitvec/Smt/Data/Bitwise.lean.
2828
2929
-/
3030

31+
set_option linter.missingDocs true
32+
3133
open Nat Bool
3234

3335
namespace Bool

src/Init/Data/BitVec/Folds.lean

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import Init.Data.BitVec.Lemmas
88
import Init.Data.Nat.Lemmas
99
import Init.Data.Fin.Iterate
1010

11+
set_option linter.missingDocs true
12+
1113
namespace BitVec
1214

1315
/--

src/Init/Data/BitVec/Lemmas.lean

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import Init.Data.Nat.Lemmas
1212
import Init.Data.Nat.Mod
1313
import Init.Data.Int.Bitwise.Lemmas
1414

15+
set_option linter.missingDocs true
16+
1517
namespace BitVec
1618

1719
/--

src/Init/Data/Int/Basic.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,8 @@ protected def pow (m : Int) : Nat → Int
322322
| 0 => 1
323323
| succ n => Int.pow m n * m
324324

325-
instance : HPow Int Nat Int where
326-
hPow := Int.pow
325+
instance : NatPow Int where
326+
pow := Int.pow
327327

328328
instance : LawfulBEq Int where
329329
eq_of_beq h := by simp [BEq.beq] at h; assumption

src/Lean/Elab/Frontend.lean

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ deriving Nonempty
8888

8989
open Language in
9090
/--
91-
Variant of `IO.processCommands` that allows for potential incremental reuse. Pass in result of a
91+
Variant of `IO.processCommands` that allows for potential incremental reuse. Pass in the result of a
9292
previous invocation done with the same state (but usually different input context) to allow for
9393
reuse.
9494
-/
@@ -131,47 +131,6 @@ def process (input : String) (env : Environment) (opts : Options) (fileName : Op
131131
let s ← IO.processCommands inputCtx { : Parser.ModuleParserState } (Command.mkState env {} opts)
132132
pure (s.commandState.env, s.commandState.messages)
133133

134-
/--
135-
Parses values of options registered during import and left by the C++ frontend as strings, fails if
136-
any option names remain unknown.
137-
-/
138-
def reparseOptions (opts : Options) : IO Options := do
139-
let mut opts := opts
140-
let decls ← getOptionDecls
141-
for (name, val) in opts do
142-
let .ofString val := val
143-
| continue -- Already parsed by C++
144-
-- Options can be prefixed with `weak` in order to turn off the error when the option is not
145-
-- defined
146-
let weak := name.getRoot == `weak
147-
if weak then
148-
opts := opts.erase name
149-
let name := name.replacePrefix `weak Name.anonymous
150-
let some decl := decls.find? name
151-
| unless weak do
152-
throw <| .userError s!"invalid -D parameter, unknown configuration option '{name}'
153-
154-
If the option is defined in this library, use '-D{`weak ++ name}' to set it conditionally"
155-
156-
match decl.defValue with
157-
| .ofBool _ =>
158-
match val with
159-
| "true" => opts := opts.insert name true
160-
| "false" => opts := opts.insert name false
161-
| _ =>
162-
throw <| .userError s!"invalid -D parameter, invalid configuration option '{val}' value, \
163-
it must be true/false"
164-
| .ofNat _ =>
165-
let some val := val.toNat?
166-
| throw <| .userError s!"invalid -D parameter, invalid configuration option '{val}' value, \
167-
it must be a natural number"
168-
opts := opts.insert name val
169-
| .ofString _ => opts := opts.insert name val
170-
| _ => throw <| .userError s!"invalid -D parameter, configuration option '{name}' \
171-
cannot be set in the command line, use set_option command"
172-
173-
return opts
174-
175134
@[export lean_run_frontend]
176135
def runFrontend
177136
(input : String)

src/Lean/Elab/MutualDef.lean

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,10 @@ private def declValToTerminationHint (declVal : Syntax) : TermElabM TerminationH
323323
else
324324
return .none
325325

326+
def instantiateMVarsProfiling (e : Expr) : MetaM Expr := do
327+
profileitM Exception s!"instantiate metavars" (← getOptions) do
328+
instantiateMVars e
329+
326330
private def elabFunValues (headers : Array DefViewElabHeader) : TermElabM (Array Expr) :=
327331
headers.mapM fun header => do
328332
let mut reusableResult? := none
@@ -348,7 +352,7 @@ private def elabFunValues (headers : Array DefViewElabHeader) : TermElabM (Array
348352
elabTermEnsuringType valStx type <* synthesizeSyntheticMVarsNoPostponing
349353
-- NOTE: without this `instantiatedMVars`, `mkLambdaFVars` may leave around a redex that
350354
-- leads to more section variables being included than necessary
351-
let val ← instantiateMVars val
355+
let val ← instantiateMVarsProfiling val
352356
mkLambdaFVars xs val
353357
if let some snap := header.bodySnap? then
354358
snap.new.resolve <| some {
@@ -389,7 +393,7 @@ private def instantiateMVarsAtHeader (header : DefViewElabHeader) : TermElabM De
389393

390394
private def instantiateMVarsAtLetRecToLift (toLift : LetRecToLift) : TermElabM LetRecToLift := do
391395
let type ← instantiateMVars toLift.type
392-
let val ← instantiateMVars toLift.val
396+
let val ← instantiateMVarsProfiling toLift.val
393397
pure { toLift with type, val }
394398

395399
private def typeHasRecFun (type : Expr) (funFVars : Array Expr) (letRecsToLift : List LetRecToLift) : Option FVarId :=
@@ -597,7 +601,7 @@ private def pickMaxFVar? (lctx : LocalContext) (fvarIds : Array FVarId) : Option
597601
fvarIds.getMax? fun fvarId₁ fvarId₂ => (lctx.get! fvarId₁).index < (lctx.get! fvarId₂).index
598602

599603
private def preprocess (e : Expr) : TermElabM Expr := do
600-
let e ← instantiateMVars e
604+
let e ← instantiateMVarsProfiling e
601605
-- which let-decls are dependent. We say a let-decl is dependent if its lambda abstraction is type incorrect.
602606
Meta.check e
603607
pure e
@@ -708,7 +712,7 @@ private def mkLetRecClosures (sectionVars : Array Expr) (mainFVarIds : Array FVa
708712
-- This can happen when this particular let-rec has nested let-rec that have been resolved in previous iterations.
709713
-- This code relies on the fact that nested let-recs occur before the outer most let-recs at `letRecsToLift`.
710714
-- Unresolved nested let-recs appear as metavariables before they are resolved. See `assignExprMVar` at `mkLetRecClosureFor`
711-
let valNew ← instantiateMVars letRecsToLift[i]!.val
715+
let valNew ← instantiateMVarsProfiling letRecsToLift[i]!.val
712716
letRecsToLift := letRecsToLift.modify i fun t => { t with val := valNew }
713717
-- We have to recompute the `freeVarMap` in this case. This overhead should not be an issue in practice.
714718
freeVarMap ← mkFreeVarMap sectionVars mainFVarIds recFVarIds letRecsToLift
@@ -821,10 +825,10 @@ def main (sectionVars : Array Expr) (mainHeaders : Array DefViewElabHeader) (mai
821825
let letRecsToLift ← letRecsToLift.mapM fun toLift => withLCtx toLift.lctx toLift.localInstances do
822826
Meta.check toLift.type
823827
Meta.check toLift.val
824-
return { toLift with val := (← instantiateMVars toLift.val), type := (← instantiateMVars toLift.type) }
828+
return { toLift with val := (← instantiateMVarsProfiling toLift.val), type := (← instantiateMVars toLift.type) }
825829
let letRecClosures ← mkLetRecClosures sectionVars mainFVarIds recFVarIds letRecsToLift
826830
-- mkLetRecClosures assign metavariables that were placeholders for the lifted declarations.
827-
let mainVals ← mainVals.mapM (instantiateMVars ·)
831+
let mainVals ← mainVals.mapM (instantiateMVarsProfiling ·)
828832
let mainHeaders ← mainHeaders.mapM instantiateMVarsAtHeader
829833
let letRecClosures ← letRecClosures.mapM fun closure => do pure { closure with toLift := (← instantiateMVarsAtLetRecToLift closure.toLift) }
830834
-- Replace fvarIds for functions being defined with closed terms
@@ -927,7 +931,7 @@ where
927931
try
928932
let values ← elabFunValues headers
929933
Term.synthesizeSyntheticMVarsNoPostponing
930-
values.mapM (instantiateMVars ·)
934+
values.mapM (instantiateMVarsProfiling ·)
931935
catch ex =>
932936
logException ex
933937
headers.mapM fun header => mkSorry header.type (synthetic := true)
@@ -961,7 +965,7 @@ where
961965
data := e.toMessageData opts
962966
}
963967
typeCheckedPromise.resolve <|
964-
.mk { diagnostics := (← Snapshot.Diagnostics.ofMessageLog msgLog) } #[])
968+
.mk { diagnostics := (← Snapshot.Diagnostics.ofMessageLog msgLog) } #[]
965969
processDeriving headers
966970
for view in views, header in headers do
967971
-- NOTE: this should be the full `ref`, and thus needs to be done after any snapshotting

src/Lean/Elab/PreDefinition/Basic.lean

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ prelude
77
import Init.ShareCommon
88
import Lean.Compiler.NoncomputableAttr
99
import Lean.Util.CollectLevelParams
10+
import Lean.Util.NumObjs
11+
import Lean.Util.NumApps
12+
import Lean.PrettyPrinter
1013
import Lean.Meta.AbstractNestedProofs
1114
import Lean.Meta.ForEachExpr
1215
import Lean.Elab.RecAppSyntax
@@ -17,7 +20,6 @@ namespace Lean.Elab
1720
open Meta
1821
open Term
1922

20-
2123
/--
2224
A (potentially recursive) definition.
2325
The elaborator converts it into Kernel definitions using many different strategies.
@@ -98,15 +100,33 @@ private def compileDecl (decl : Declaration) : TermElabM Bool := do
98100
throw ex
99101
return true
100102

103+
register_builtin_option diagnostics.threshold.proofSize : Nat := {
104+
defValue := 16384
105+
group := "diagnostics"
106+
descr := "only display proof statistics when proof has at least this number of terms"
107+
}
108+
109+
private def reportTheoremDiag (d : TheoremVal) : TermElabM Unit := do
110+
if (← isDiagnosticsEnabled) then
111+
let proofSize ← d.value.numObjs
112+
if proofSize > diagnostics.threshold.proofSize.get (← getOptions) then
113+
let sizeMsg := MessageData.trace { cls := `size } m!"{proofSize}" #[]
114+
let constOccs ← d.value.numApps (threshold := diagnostics.threshold.get (← getOptions))
115+
let constOccsMsg ← constOccs.mapM fun (declName, numOccs) => return MessageData.trace { cls := `occs } m!"{MessageData.ofConst (← mkConstWithLevelParams declName)} ↦ {numOccs}" #[]
116+
-- let info
117+
logInfo <| MessageData.trace { cls := `theorem } m!"{d.name}" (#[sizeMsg] ++ constOccsMsg)
118+
101119
private def addNonRecAux (preDef : PreDefinition) (compile : Bool) (all : List Name) (applyAttrAfterCompilation := true) : TermElabM Unit :=
102120
withRef preDef.ref do
103121
let preDef ← abstractNestedProofs preDef
104122
let decl ←
105123
match preDef.kind with
106124
| DefKind.«theorem» =>
107-
pure <| Declaration.thmDecl {
125+
let d := {
108126
name := preDef.declName, levelParams := preDef.levelParams, type := preDef.type, value := preDef.value, all
109127
}
128+
reportTheoremDiag d
129+
pure <| Declaration.thmDecl d
110130
| DefKind.«opaque» =>
111131
pure <| Declaration.opaqueDecl {
112132
name := preDef.declName, levelParams := preDef.levelParams, type := preDef.type, value := preDef.value

src/Lean/Elab/PreDefinition/Main.lean

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,8 @@ def shouldUseWF (preDefs : Array PreDefinition) : Bool :=
151151
preDef.termination.terminationBy? matches some {structural := false, ..} ||
152152
preDef.termination.decreasingBy?.isSome
153153

154-
/--
155-
Checks the given pre-definitions in the kernel and adds them to the environment. If `postponeCheck`
156-
is `true`, the kernel check may be postponed, in which case the environment and declaration are
157-
returned on which `Environment.addDecl` should be called at some later point to perform the check.
158-
-/
159-
def addPreDefinitionsCore (preDefs : Array PreDefinition) (postponeCheck := false) : TermElabM (Option (Environment × Declaration)) := withLCtx {} {} do
154+
private def addPreDefinitionsCore (preDefs : Array PreDefinition) (postponeCheck : Bool) :
155+
TermElabM (Option (Environment × Declaration)) := withLCtx {} {} do
160156
profileitM Exception "process pre-definitions" (← getOptions) do
161157
withTraceNode `Elab.def.processPreDef (fun _ => return m!"process pre-definitions") do
162158
for preDef in preDefs do
@@ -231,9 +227,20 @@ def addPreDefinitionsCore (preDefs : Array PreDefinition) (postponeCheck := fals
231227
catch _ => s.restore
232228
return none
233229

230+
/-- Checks the given pre-definitions in the kernel and adds them to the environment. -/
234231
def addPreDefinitions (preDefs : Array PreDefinition) : TermElabM Unit :=
235232
addPreDefinitionsCore preDefs (postponeCheck := false) |> discard
236233

234+
/--
235+
Checks the given pre-definitions in the kernel and adds them to the environment. Depending on the
236+
involved definitions, the kernel check may be postponed, in which case the environment and
237+
declaration are returned on which `Environment.addDecl` should be called at some later point to
238+
perform the check.
239+
-/
240+
def addPreDefinitionsWithPostpone (preDefs : Array PreDefinition) :
241+
TermElabM (Option (Environment × Declaration)) :=
242+
addPreDefinitionsCore preDefs (postponeCheck := true)
243+
237244
builtin_initialize
238245
registerTraceClass `Elab.definition.body
239246
registerTraceClass `Elab.definition.scc

src/Lean/Expr.lean

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,28 +1452,26 @@ partial def betaRev (f : Expr) (revArgs : Array Expr) (useZeta := false) (preser
14521452
else
14531453
let sz := revArgs.size
14541454
let rec go (e : Expr) (i : Nat) : Expr :=
1455+
let done (_ : Unit) : Expr :=
1456+
let n := sz - i
1457+
mkAppRevRange (e.instantiateRange n sz revArgs) 0 n revArgs
14551458
match e with
1456-
| Expr.lam _ _ b _ =>
1459+
| .lam _ _ b _ =>
14571460
if i + 1 < sz then
14581461
go b (i+1)
14591462
else
1460-
let n := sz - (i + 1)
1461-
mkAppRevRange (b.instantiateRange n sz revArgs) 0 n revArgs
1462-
| Expr.letE _ _ v b _ =>
1463+
b.instantiate revArgs
1464+
| .letE _ _ v b _ =>
14631465
if useZeta && i < sz then
14641466
go (b.instantiate1 v) i
14651467
else
1466-
let n := sz - i
1467-
mkAppRevRange (e.instantiateRange n sz revArgs) 0 n revArgs
1468-
| Expr.mdata k b =>
1468+
done ()
1469+
| .mdata _ b =>
14691470
if preserveMData then
1470-
let n := sz - i
1471-
mkMData k (mkAppRevRange (b.instantiateRange n sz revArgs) 0 n revArgs)
1471+
done ()
14721472
else
14731473
go b i
1474-
| b =>
1475-
let n := sz - i
1476-
mkAppRevRange (b.instantiateRange n sz revArgs) 0 n revArgs
1474+
| _ => done ()
14771475
go f 0
14781476

14791477
/--

0 commit comments

Comments
 (0)