Skip to content

Commit

Permalink
fix: add checkSystem and withIncRecDepth to withAutoBoundImplicit
Browse files Browse the repository at this point in the history
Fix stack overflow crash.

Closes #4117

The fix can be improved: we could try to avoid creating hundreds of
auto implicits before failing.
  • Loading branch information
leodemoura committed May 10, 2024
1 parent fe7b96d commit 5ac0662
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/Lean/Elab/Term.lean
Original file line number Diff line number Diff line change
Expand Up @@ -1523,7 +1523,8 @@ partial def withAutoBoundImplicit (k : TermElabM α) : TermElabM α := do
let flag := autoImplicit.get (← getOptions)
if flag then
withReader (fun ctx => { ctx with autoBoundImplicit := flag, autoBoundImplicits := {} }) do
let rec loop (s : SavedState) : TermElabM α := do
let rec loop (s : SavedState) : TermElabM α := withIncRecDepth do
checkSystem "auto-implicit"
try
k
catch
Expand Down
1 change: 1 addition & 0 deletions tests/lean/4117.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
structure D:=(t:A)(c N:={s with} 0
1 change: 1 addition & 0 deletions tests/lean/4117.lean.expected.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4117.lean:2:0: error: unexpected end of input; expected ')'
4 changes: 2 additions & 2 deletions tests/lean/run/simpDiag.lean
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ info: [simp] used theorems (max: 1201, num: 3):
Nat.reduceAdd (builtin simproc) ↦ 771
ack.eq_1 ↦ 768[simp] tried theorems (max: 1974, num: 2):
ack.eq_3 ↦ 1974, succeeded: 1201
ack.eq_1 ↦ 768[simp] tried theorems (max: 1973, num: 2):
ack.eq_3 ↦ 1973, succeeded: 1201
ack.eq_1 ↦ 768, succeeded: 768use `set_option diagnostics.threshold <num>` to control threshold for reporting counters
---
Expand Down

0 comments on commit 5ac0662

Please sign in to comment.