Skip to content

Add --dumpheap and -g flags for Holmake (issue #1917)#1928

Open
charles-cooper wants to merge 4 commits intoHOL-Theorem-Prover:developfrom
charles-cooper:dumpheap
Open

Add --dumpheap and -g flags for Holmake (issue #1917)#1928
charles-cooper wants to merge 4 commits intoHOL-Theorem-Prover:developfrom
charles-cooper:dumpheap

Conversation

@charles-cooper
Copy link
Copy Markdown
Contributor

co-authored by claude opus 4.6

Summary

Add --dumpheap and -g flags to Holmake for heap checkpointing and proof diagnostics. Closes #1917.

Flags

Flag Effect
--dumpheap Save Poly/ML heap checkpoints at proof boundaries (cursor_checkpoints/<thm>_{context|end_of_proof}.save)
-g Run proofs through goalFrag; show unsolved goal state on failure
-g --dumpheap Fragment-stepped execution for navigable checkpoints (context + end_of_proof saves)
--tactic-timeout=N Per-tactic timeout in seconds (default 5s when -g active)

New modules

  • TacticStep (src/parse/): Consumer helpers for tactic fragment navigation — fragment text/classification, step plan generation, select-step merging. Used by both holmakebuild and the LSP server.
  • TacticParse additions: flatten_frags and reexpand_thenlt_frags — structural decomposition functions that fix linearize's ThenLT opacity bug inside >> chains.

Prover modes (holmakebuild.sml)

Mode Prover Behavior
No flags basic_prover (TAC_PROOF) Unchanged
-g One-shot goalFrag.expand Diagnostics on failure
--dumpheap One-shot + context checkpoint Checkpoint at store_thm time
-g --dumpheap Fragment-stepped Per-fragment ef() calls, context + end_of_proof checkpoints

Key fix: loadedMods in poly-init2.ML

Globals and CoreReplVARS are loaded via use in poly-init2.ML but were not added to loadedMods. When Meta.load encountered them as dependencies (e.g., holmakebuild.uo → Globals), it re-ran Globals.sml, creating fresh ref cells that silently shadowed the ones set by hol.ML's main() after loadState. Adding them to loadedMods prevents this re-load.

Changed files

  • src/parse/TacticStep.sig/sml — new module
  • src/parse/TacticParse.sig/sml — expose flatten_frags, reexpand_thenlt_frags
  • src/1/holmakebuild.sml — prover implementation, checkpoint logic, tactic timeout
  • src/1/boolLib.sml — set Globals.holmake_current_thm
  • src/prekernel/Globals.sig/sml — new holmake flag refs
  • tools/Holmake/poly/HM_Cline.sig/sml — CLI options
  • tools/Holmake/poly/BuildCommand.sml — thread flags to child process
  • tools-poly/hol.ML — parse new flags, set Globals after loadState
  • tools-poly/poly/poly-init2.ML — loadedMods fix, early Globals load
  • tools/parsing/HOLSourceExpand.sig/sml — tactic text storage, holmake_active flag
  • tools/parsing/HOLSource.sml — expSpan export
  • bin/hol.ML — backward-compat flag extraction for direct hol <state> <files> invocations

--dumpheap: save Poly/ML heap checkpoints at proof boundaries
-g: run proofs through goalFrag, show goal state on failure

New modules and flags:
- TacticStep.sig/sml: consumer helpers for tactic fragment navigation
  (fragment text/classification, step plan generation, select merging)
- TacticParse: expose flatten_frags + reexpand_thenlt_frags (structurally
  fix linearize's ThenLT opacity bug inside >> chains)
- Globals: holmake_dumpheap_flag, holmake_g_flag, holmake_allow_cheat,
  holmake_tactic_timeout refs
- HM_Cline: --dumpheap, -g, --tactic-timeout options
- BuildCommand: thread flags to child hol process cline
- hol.ML: parse new flags, set Globals after loadState

Prover implementation (holmakebuild.sml):
- Fragment-stepped prover for -g --dumpheap: per-fragment ef() calls
  for navigable checkpoints (context + end_of_proof saves)
- One-shot goalFrag prover for -g alone: diagnostics only
- Basic prover unchanged for no flags
- Tactic timeout: inline Thread.fork+Mutex+ConditionVar, per-step
  for fragments, per-proof for one-shot
- Proof attrs fallback: has_proof_attrs → one-shot (wrapper not in source)
- Eager cache cleaning after each proof

Critical fix (poly-init2.ML):
- Add Globals + CoreReplVARS to loadedMods so Meta.load skips them
  after loadState. Without this, Meta.load re-runs Globals.sml via use,
  creating fresh ref cells that shadow the ones set by hol.ML main()

Also:
- bin/hol.ML: backward-compat flag extraction (dead code from 2016)
- boolLib.sml: set Globals.holmake_current_thm during store_thm
…elds)

Develop added --thmsrc (FRU16). Our branch added --dumpheap/-g/--allow-cheat
--tactic-timeout (FRU19). Merged to FRU20 with both field sets.
holmakebuild.sml used Thread, Mutex, ConditionVar, and PolyML.SaveState
which don't exist in Moscow ML. Extract these into a PolyRuntime module
with platform-specific implementations:

- src/portableML/poly/concurrent/PolyRuntime.sml: real implementations
  (thread-based timeout, PolyML.SaveState heap save, PolyML.compiler eval)
- src/portableML/mosml/concurrent/PolyRuntime.sml: no-op stubs
  (features gated by Globals refs which are always false on mosml)

holmakebuild.sml now uses PolyRuntime.tactic_timeout, .save_heap,
.eval_sml_string instead of inline Poly/ML-specific code.
…oofman

holmakebuild.sml in src/1/ cannot reference goalFrag, proofManagerLib,
etc. because they're in src/proofman/ which builds AFTER src/1/. On
Poly/ML this worked via heap-resolved references, but mosml compiles
each directory independently and needs .ui dependencies in sigobj.

Fix: restore holmakebuild.sml to the original basic_prover (no
goalFrag deps). Move advanced provers to holmakebuild_prover.sml in
the new src/proofman/poly/ directory (builds after goalFrag is available).

Poly BuildCommand links holmakebuild_prover.uo before the script
when -g or --dumpheap is active. Mosml doesn't use these features
(Globals refs are always false) so basic_prover suffices.
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.

Feature: --dumpheap option for Holmake (save Poly/ML heap on cheat/error)

1 participant