Skip to content

Conversation

@NicolasRouquette
Copy link
Contributor

@NicolasRouquette NicolasRouquette commented Dec 7, 2025

See #335

Lake's getAugmentedEnv creates a new environment with only specific
variables (LEAN_PATH, LEAN_SRC_PATH, etc.) rather than inheriting
the shell environment. This means DOCGEN_MAX_HEARTBEATS was not
being passed through to the doc-gen4 subprocess.

This fix reads DOCGEN_MAX_HEARTBEATS from the environment in the
lakefile and explicitly passes it as --max-heartbeats CLI argument
to the 'single' and 'genCore' commands.
The maxHeartbeats parameter was being passed to Load.load but the
Process.process function had a hardcoded value of 5000000 that was
overriding it. This fix:

1. Adds maxHeartbeats parameter to Process.process (with same default)
2. Uses the parameter instead of hardcoded value
3. Passes maxHeartbeats from Load.load to Process.process

This allows DOCGEN_MAX_HEARTBEATS env var or --max-heartbeats CLI flag
to actually control the heartbeat limit during documentation generation.
The maxHeartbeats field in Core.Context doesn't affect Lean's internal
operations like equation theorem generation (getEqnsFor?). Those use
the maxHeartbeats *option* which has a default of 200000.

This fix adds maxHeartbeats to the options in both Load.lean and
Analyze.lean, so that elaboration operations respect the configured
limit.
Copy link
Collaborator

@hargoniX hargoniX left a comment

Choose a reason for hiding this comment

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

Thanks for implementing this! Just one question, do you plan to do the fix for adapting the new String.toNat? next Lean release yourself or should I put that on my TODO list?

@NicolasRouquette
Copy link
Contributor Author

I'll clean up the PR to use the new String.toNat?.

I need to look into the discussion about maxHeartbeats here: leanprover/lean4#11546 (comment) and review the PR.

- Removed the parseNatWithUnderscores function and its doc comments with issue references
- Simplified getMaxHeartbeats to use flag.as! Nat directly for the CLI flag and s.toNat? for the environment variable
- Changed the max-heartbeats flag type from String to Nat in both singleCmd and genCoreCmd
- Removed the "Supports underscores as separators" mention from flag descriptions

In README.md:

- Removed the "Underscores can be used as separators for readability" sentence (the examples still show underscores since they will work in a version of Lean4 that includes this merged PR: leanprover/lean4#11541
@NicolasRouquette
Copy link
Contributor Author

@hargoniX

  1. I pushed a commit that defines maxHeartbeat as a Nat to take advantage of the new String.toNat? functionality.

  2. Please look at my analysis of @nomeata 's comment regarding getEqnsFor? -- I believe that we can simply wait for him to do the cleanup he described and we should be able to properly set maxHeartbeats without doing anything in this PR.

I would prefer merging this PR after verifying that it actually works on a version of Lean4 that has @nomeata 's changes.

@nomeata
Copy link
Contributor

nomeata commented Dec 8, 2025

My planned changes will probably not affect this issue here. The issue here is that realizeConst works in a pristine environment when called on imported declarations. Maybe you can find a way to affect that environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants