perf: add checkInterrupted to inferType cache miss path (#13258)

This PR adds a `Core.checkInterrupted` call in `checkInferTypeCache` on
cache miss, allowing cancellation to be detected during large type
inference traversals. Previously, `inferTypeImp` could run for >100ms
without any interruption check when processing large expressions (e.g.
BVDecide proof terms), making IDE cancellation unresponsive.

The check is only on cache miss (actual computation), so cache hits have
zero overhead. `checkInterrupted` is used instead of the heavier
`checkSystem` to minimize performance impact — local benchmarks show no
measurable regression on `tests/elab/5664.lean`.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Joachim Breitner 2026-04-03 08:03:55 +02:00 committed by GitHub
parent acae2b44fd
commit d3b04871f5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -180,12 +180,14 @@ private def inferFVarType (fvarId : FVarId) : MetaM Expr := do
@[inline] private def checkInferTypeCache (e : Expr) (inferType : MetaM Expr) : MetaM Expr := do
if !(← read).cacheInferType || e.hasMVar then
Core.checkInterrupted
inferType
else
let key ← mkExprConfigCacheKey e
match (← get).cache.inferType.find? key with
| some type => return type
| none =>
Core.checkInterrupted
let type ← inferType
unless type.hasMVar do
modifyInferTypeCache fun c => c.insert key type