Skip to content

speed up Print Assumptions: walk stored proof term - #22425

Open
zeldovich wants to merge 2 commits into
rocq-prover:masterfrom
zeldovich:print-assumptions
Open

speed up Print Assumptions: walk stored proof term#22425
zeldovich wants to merge 2 commits into
rocq-prover:masterfrom
zeldovich:print-assumptions

Conversation

@zeldovich

Copy link
Copy Markdown
Contributor

This change speeds up Print Assumptions for large proofs that have a lot of shared terms. The motivation was a large Iris-based project where [Print Assumptions] on a single top-level theorem was almost half of the total build time of the whole project (6 minutes out of 13 minutes).

[Print Assumptions] obtains every opaque body through [Global.force_proof], which applies the section discharge ([Discharge.cook_opaque_proofterm], once per enclosing section) before the command looks at the term. The discharge is a rebuild, and the rebuild destroys sharing.

complexity/PrintAssumptionsSharing.v is a regression test for the walk itself: a proof whose stored DAG is 22 nodes and whose tree unfolding is over 4M, so the old walk is exponential in the size of the file.

This also adds a test for the weird corner case of [Print Assumptions] that wasn't covered by existing tests (the "used in" annotation that [ax2ty] attaches to an axiom eliminated by a [match ... with end]).

This change speeds up Print Assumptions for large proofs that have a lot
of shared terms.  The motivation was a large Iris-based project where
[Print Assumptions] on a single top-level theorem was almost half of
the total build time of the whole project (6 minutes out of 13 minutes).

[Print Assumptions] obtains every opaque body through [Global.force_proof],
which applies the section discharge ([Discharge.cook_opaque_proofterm],
once per enclosing section) before the command looks at the term.
The discharge is a rebuild, and the rebuild destroys sharing.

complexity/PrintAssumptionsSharing.v is a regression test for the walk
itself: a proof whose stored DAG is 22 nodes and whose tree unfolding
is over 4M, so the old walk is exponential in the size of the file.

This also adds a test for the weird corner case of [Print Assumptions]
that wasn't covered by existing tests (the "used in" annotation that
[ax2ty] attaches to an axiom eliminated by a [match ... with end]).
@zeldovich
zeldovich requested review from a team as code owners August 30, 2026 15:22
@coqbot-app coqbot-app Bot added the needs: full CI The latest GitLab pipeline that ran was a light CI. Say "@coqbot run full ci" to get a full CI. label Aug 30, 2026
Comment thread vernac/assumptions.ml Outdated
walk would have grown is read by [assumptions] only through
[Option.has_some]. The one visible effect is on [ax2ty]: a
[match ... with end] that is one shared node reached along several paths
contributes one "used in" entry rather than one per path.

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.

This is a user visible change

Axiom f : False.

Definition bla := (let x := nat in match f return x with end, let y := bool in match f return y with end).

Print Assumptions bla.
(* master:
Axioms:
f : False
used in bla to prove
 y
used in bla to prove
 x

PR:
Axioms:
f : False
used in bla to prove
 x
*)

but IDK if that really matters considering y and x are not very informative without printing the local context.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If you do Require Import Coq.Compat.AdmitAxiom. and then admit a handful of sub goals, does this make it so that only one appears?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I pushed a commit to preserve the old behavior. (I had assumed this is some weird feature that's not used, but clearly that's not true.) The fix is to avoid caching anything that produces one of these "used in" reports.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

See #4300 , #4054 , 2defd4c for the history. (tl;dr: the move to the new evar-based proof engine in 8.4->8.5 made it infeasible to mint global axioms during proof execution, so admit became abstract case proof_admitted for proof_admitted : False; later support was added to fix Print Assumptions)

Preserve old behavior in terms of the "used in" output.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs: full CI The latest GitLab pipeline that ran was a light CI. Say "@coqbot run full ci" to get a full CI.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants