Skip to content

fix: add missing initHeartbeats#1037

Merged
fgdorais merged 8 commits intomainfrom
eric-wieser/initHeartbeats
Feb 13, 2026
Merged

fix: add missing initHeartbeats#1037
fgdorais merged 8 commits intomainfrom
eric-wieser/initHeartbeats

Conversation

@eric-wieser
Copy link
Copy Markdown
Member

In only one case a Core.Context is created from within CoreM, and we inherit from the parent Context the initHeartbeats. Otherwise, we get the current heartbeats from IO.

It's not entirely clear to me what the intended semantics of lintCore are; should they inherit the outer heartbeat count (as with this patch), or get a new heartbeat budget for each declaration (prior to it)?

@github-actions github-actions bot added the awaiting-review This PR is ready for review; the author thinks it is ready to be merged. label Nov 11, 2024
ghost pushed a commit to leanprover-community/mathlib4 that referenced this pull request Nov 11, 2024
@ghost
Copy link
Copy Markdown

ghost commented Nov 11, 2024

Mathlib CI status (docs):

@ghost ghost added the builds-mathlib label Nov 11, 2024
@fgdorais
Copy link
Copy Markdown
Collaborator

LGTM Could you explain, for documentation purposes, why this isn't something Lean core could do?

@fgdorais fgdorais added awaiting-author Waiting for PR author to address issues and removed awaiting-review This PR is ready for review; the author thinks it is ready to be merged. labels Nov 26, 2024
@ghost ghost added the merge-conflict This PR has merge conflicts with the `main` branch which must be resolved by the author. label Dec 2, 2024
@eric-wieser
Copy link
Copy Markdown
Member Author

Sorry, I missed that message.

What are you expecting Lean core to do here? Because we are constructing a Lean.Core.Context manually from scratch, it's our responsibility to fill in all of its fields.

Perhaps @kmill should have a look at this and suggest if we can avoid this manual construction in the first place (and confirm whether the PR in its current state is still an improvement over the status quo).

match ← withCurrHeartbeats (linter.test decl)
|>.run' mkMetaContext
|>.run' {options, fileName := "", fileMap := default} {env}
|>.run' {options, fileName := "", fileMap := default, initHeartbeats } {env}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the withCurrHeartbeats sets initHeartbeats from IO.getNumHeartbeats. What effect does initializing initHeartbeats here have? Can you come up with a test that validates this?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're right, this has no effect.

let initHeartbeats ← IO.getNumHeartbeats
let res ← EIO.asTask <|
init {} |>.run' {} { options, fileName, fileMap } |>.run' { env }
init {} |>.run' {} { options, fileName, fileMap, initHeartbeats } |>.run' { env }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that Lean.Core.wrapAsync exists, and it does a bit more heartbeats arithmetic. Lean.Core.CoreM.toIO looks relevant.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrapAsync indeed looks like the right tool, as otherwise the hearbeat counts on one thread are meaninglessly transferred to another thread.

eric-wieser and others added 2 commits January 8, 2025 15:20
In only one case a `Core.Context` is created from within CoreM, and we inherit from the parent Context the `initHeartbeats`. Otherwise, we get the current heartbeats from IO.

Co-authored-by: Laurent Sartran <lsartran@google.com>
@eric-wieser eric-wieser force-pushed the eric-wieser/initHeartbeats branch from c753fca to 9d7fca8 Compare January 8, 2025 15:21
@ghost ghost removed the merge-conflict This PR has merge conflicts with the `main` branch which must be resolved by the author. label Jan 8, 2025
@fgdorais
Copy link
Copy Markdown
Collaborator

Have issues been fixed to everyone's satisfaction?

ghost pushed a commit to leanprover-community/mathlib4 that referenced this pull request Jan 18, 2025
@fgdorais
Copy link
Copy Markdown
Collaborator

I'm afraid I lost track of this one. What's the current status?

@eric-wieser
Copy link
Copy Markdown
Member Author

I need to update the description to reflect the new version, but I think the approach now aligns with @kmill's suggestion.

The mathlib failure suggests that either I have broken the heartbeat counting, or that we were previously erroneously resetting the heartbeat counter mid-linter.

@ghost ghost added the merge-conflict This PR has merge conflicts with the `main` branch which must be resolved by the author. label Dec 31, 2025
@eric-wieser eric-wieser removed awaiting-author Waiting for PR author to address issues merge-conflict This PR has merge conflicts with the `main` branch which must be resolved by the author. labels Jan 26, 2026
@eric-wieser
Copy link
Copy Markdown
Member Author

Do I need to do anything here to get mathlib to build with this change?

@fgdorais fgdorais added this pull request to the merge queue Feb 13, 2026
Merged via the queue into main with commit 450ddfd Feb 13, 2026
2 checks passed
fgdorais added a commit that referenced this pull request Feb 26, 2026
Co-authored-by: Laurent Sartran <lsartran@google.com>
Co-authored-by: F. G. Dorais <fgdorais@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants