machinechecked 0.1.13__tar.gz → 0.1.15__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. {machinechecked-0.1.13 → machinechecked-0.1.15}/PKG-INFO +1 -1
  2. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/machinechecked.egg-info/PKG-INFO +1 -1
  3. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/machinechecked.egg-info/SOURCES.txt +3 -2
  4. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/prooflens/assess.py +4 -2
  5. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/prooflens/cache.py +20 -8
  6. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/prooflens/cli.py +4 -1
  7. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/prooflens/data/ProofLensProbe.lean +84 -51
  8. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/prooflens/export.py +4 -1
  9. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/prooflens/formalization.py +2 -1
  10. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/prooflens/manifest.py +1 -1
  11. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/prooflens/pipeline.py +9 -6
  12. machinechecked-0.1.15/engine/python/prooflens/repin.py +473 -0
  13. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/prooflens/simple.py +38 -1
  14. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/prooflens/source_regions.py +61 -9
  15. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/prooflens/symbols.py +42 -5
  16. machinechecked-0.1.15/engine/python/prooflens/web/assets/index-B_fzeuBg.js +278 -0
  17. machinechecked-0.1.13/engine/python/prooflens/web/assets/index-GfZV3aEH.css → machinechecked-0.1.15/engine/python/prooflens/web/assets/index-e4I0NErR.css +1 -1
  18. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/prooflens/web/index.html +2 -2
  19. {machinechecked-0.1.13 → machinechecked-0.1.15}/pyproject.toml +1 -1
  20. machinechecked-0.1.13/engine/python/prooflens/web/assets/index-DevCW_Pm.js +0 -278
  21. {machinechecked-0.1.13 → machinechecked-0.1.15}/LICENSE +0 -0
  22. {machinechecked-0.1.13 → machinechecked-0.1.15}/README.md +0 -0
  23. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/machinechecked.egg-info/dependency_links.txt +0 -0
  24. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/machinechecked.egg-info/entry_points.txt +0 -0
  25. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/machinechecked.egg-info/requires.txt +0 -0
  26. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/machinechecked.egg-info/top_level.txt +0 -0
  27. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/prooflens/__init__.py +0 -0
  28. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/prooflens/__main__.py +0 -0
  29. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/prooflens/audit.py +0 -0
  30. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/prooflens/bundle.py +0 -0
  31. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/prooflens/config.py +0 -0
  32. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/prooflens/data/prooflens.sty +0 -0
  33. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/prooflens/data/schema/evidence.schema.json +0 -0
  34. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/prooflens/data/schema/inventory.schema.json +0 -0
  35. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/prooflens/data/schema/manifest-claim.schema.json +0 -0
  36. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/prooflens/data/schema/manifest-index.schema.json +0 -0
  37. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/prooflens/data/statuses.json +0 -0
  38. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/prooflens/deps.py +0 -0
  39. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/prooflens/evidence.py +0 -0
  40. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/prooflens/paper.py +0 -0
  41. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/prooflens/pdfclaims.py +0 -0
  42. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/prooflens/probe.py +0 -0
  43. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/prooflens/promote.py +0 -0
  44. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/prooflens/published.py +0 -0
  45. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/prooflens/replay.py +0 -0
  46. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/prooflens/review_cli.py +0 -0
  47. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/prooflens/review_queue.py +0 -0
  48. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/prooflens/reviews.py +0 -0
  49. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/prooflens/schemas.py +0 -0
  50. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/prooflens/server.py +0 -0
  51. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/prooflens/sources.py +0 -0
  52. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/prooflens/status.py +0 -0
  53. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/prooflens/tex.py +0 -0
  54. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/prooflens/util.py +0 -0
  55. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/prooflens/web/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
  56. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/prooflens/web/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
  57. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/prooflens/web/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
  58. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/prooflens/web/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
  59. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/prooflens/web/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
  60. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/prooflens/web/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
  61. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/prooflens/web/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
  62. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/prooflens/web/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
  63. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/prooflens/web/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
  64. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/prooflens/web/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
  65. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/prooflens/web/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
  66. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/prooflens/web/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
  67. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/prooflens/web/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
  68. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/prooflens/web/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
  69. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/prooflens/web/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
  70. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/prooflens/web/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
  71. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/prooflens/web/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
  72. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/prooflens/web/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
  73. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/prooflens/web/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
  74. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/prooflens/web/assets/cursor-editorTextHighlight-kG3uUOwL.svg +0 -0
  75. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/prooflens/web/assets/pdf.worker.min-yatZIOMy.mjs +0 -0
  76. {machinechecked-0.1.13 → machinechecked-0.1.15}/engine/python/prooflens/web/theme.css +0 -0
  77. {machinechecked-0.1.13 → machinechecked-0.1.15}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: machinechecked
3
- Version: 0.1.13
3
+ Version: 0.1.15
4
4
  Summary: Read a mathematical paper beside its Lean formalisation, and see claim by claim what Lean establishes.
5
5
  License: Apache-2.0
6
6
  Project-URL: Homepage, https://machinechecked.org
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: machinechecked
3
- Version: 0.1.13
3
+ Version: 0.1.15
4
4
  Summary: Read a mathematical paper beside its Lean formalisation, and see claim by claim what Lean establishes.
5
5
  License: Apache-2.0
6
6
  Project-URL: Homepage, https://machinechecked.org
@@ -26,6 +26,7 @@ engine/python/prooflens/pipeline.py
26
26
  engine/python/prooflens/probe.py
27
27
  engine/python/prooflens/promote.py
28
28
  engine/python/prooflens/published.py
29
+ engine/python/prooflens/repin.py
29
30
  engine/python/prooflens/replay.py
30
31
  engine/python/prooflens/review_cli.py
31
32
  engine/python/prooflens/review_queue.py
@@ -68,6 +69,6 @@ engine/python/prooflens/web/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2
68
69
  engine/python/prooflens/web/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2
69
70
  engine/python/prooflens/web/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2
70
71
  engine/python/prooflens/web/assets/cursor-editorTextHighlight-kG3uUOwL.svg
71
- engine/python/prooflens/web/assets/index-DevCW_Pm.js
72
- engine/python/prooflens/web/assets/index-GfZV3aEH.css
72
+ engine/python/prooflens/web/assets/index-B_fzeuBg.js
73
+ engine/python/prooflens/web/assets/index-e4I0NErR.css
73
74
  engine/python/prooflens/web/assets/pdf.worker.min-yatZIOMy.mjs
@@ -25,7 +25,7 @@ from __future__ import annotations
25
25
  from .status import fields
26
26
 
27
27
  from .reviews import Review, history
28
- from .source_regions import SCHEME as SOURCE_SCHEME, matches as source_matches
28
+ from .source_regions import SCHEME as SOURCE_SCHEME, changed_line, matches as source_matches
29
29
 
30
30
  OUT_OF_SCOPE = {"expository", "literature", "empirical", "proof-step", "part-of", "duplicate"}
31
31
 
@@ -541,9 +541,11 @@ class Assessor:
541
541
  "revision (python -m prooflens.source_regions --config FILE "
542
542
  f"--paper {pid}); then rebuild"))
543
543
  elif not source_matches(c, t):
544
+ where = changed_line(c, region) if region else None
544
545
  detail = region.get("error") or (
545
546
  "is missing; rebuild the source evidence" if not region else
546
- "differs from the frozen source region")
547
+ "differs from the frozen source region"
548
+ + (f": {where}" if where else ""))
547
549
  self.findings.append(_finding(
548
550
  "violation", "source-changed", c["id"],
549
551
  f"the source region at {c['location']} {detail}"))
@@ -220,13 +220,18 @@ def check_space(project: Path, tmp: Path, man: dict) -> None:
220
220
  "revision, or old build output) and restore again; nothing was changed")
221
221
 
222
222
 
223
- def _unpack(arc: Path, project: Path) -> None:
223
+ def _unpack(arc: Path, project: Path, older: bool = False) -> None:
224
224
  """Unpack an archive written by `_pack` into the project and its path dependencies, with the
225
225
  tar `data` filter (no absolute paths, no `..`, no links out of the destination). Everything
226
226
  is unpacked into a staging folder first and moved into place only once the whole archive
227
- has been read, so a failure (a full disk, a corrupt archive) leaves the build as it was."""
227
+ has been read, so a failure (a full disk, a corrupt archive) leaves the build as it was.
228
+
229
+ An archive in the older layout (`older`) holds paths from the checkout's parent, under the
230
+ folder names of the checkout it was made in; each top folder is mapped onto the project or a
231
+ path dependency whose folder has that name in any case, and any other path is refused."""
228
232
  import tarfile
229
233
  deps = {d.name: d for d in path_deps(project)}
234
+ folded = {d.name.lower(): d for d in deps.values()}
230
235
  stage = Path(tempfile.mkdtemp(prefix=".lean-cache-restore-", dir=project))
231
236
  try:
232
237
  bases: dict[str, Path] = {}
@@ -234,7 +239,17 @@ def _unpack(arc: Path, project: Path) -> None:
234
239
  with tarfile.open(fileobj=z.stdout, mode="r|") as tf:
235
240
  for m in tf:
236
241
  head, _, rest = m.name.partition("/")
237
- if head == "project" and rest:
242
+ if older and not rest.strip("/") and m.isdir():
243
+ continue # the top folder itself
244
+ if older and rest and head.lower() == project.name.lower():
245
+ key, base, m.name = "project", project, rest
246
+ elif older and rest and head.lower() in folded:
247
+ base = folded[head.lower()]
248
+ key, m.name = f"path-{base.name}", rest
249
+ elif older:
250
+ raise CacheError(f"the archive's path {m.name} is not in this project or a "
251
+ "path dependency of it; build from source")
252
+ elif head == "project" and rest:
238
253
  key, base, m.name = "project", project, rest
239
254
  elif head == "path" and rest.partition("/")[0] in deps:
240
255
  name, _, m.name = rest.partition("/")
@@ -428,7 +443,7 @@ def restore(project: Path, repo: str | None = None, local: Path | None = None,
428
443
  src.fetch(name, tmp / name)
429
444
  man = json.loads((tmp / name).read_text())
430
445
  if not man.get("layout") and not name.startswith(_prefix(project.name)):
431
- continue # an archive in the older layout unpacks only into a folder of its name
446
+ continue # an archive in the older layout is named after the checkout's folder
432
447
  wanted = [p["name"] for p in man["parts"]] if man.get("parts") else [f"{stem}.tar.zst"]
433
448
  if any(w not in src.assets for w in wanted):
434
449
  continue
@@ -481,10 +496,7 @@ def restore(project: Path, repo: str | None = None, local: Path | None = None,
481
496
  if got != man["sha256"]:
482
497
  raise CacheError(f"sha256 {got} is not the manifest's {man['sha256']}; "
483
498
  "build from source")
484
- if man.get("layout") == 2:
485
- _unpack(arc, project)
486
- else:
487
- _sh(["tar", "-C", str(project.parent), "-I", "zstd -T0", "-xf", str(arc)])
499
+ _unpack(arc, project, older=man.get("layout") != 2)
488
500
  log(f"restored {stem} ("
489
501
  + ("the same Lean inputs" if key[0] == 0 else f"{dist} commits behind HEAD")
490
502
  + f", sha256 {got[:16]}…) "
@@ -352,6 +352,7 @@ def _check_json(a):
352
352
  "status": c["status"], "status_code": c["status_code"], "class": c["class"],
353
353
  "links": [{"name": l["name"], "status": l["status"], "status_code": l["status_code"], "class": l["class"],
354
354
  "source": l.get("source")} for l in c["links"]],
355
+ "correspondence": c.get("correspondence"),
355
356
  "suggestions": [{"name": x["name"], "why": x.get("why")}
356
357
  for x in c.get("suggestions", [])]}
357
358
  for c in body["claims"]]
@@ -535,7 +536,7 @@ def cmd_symbol(a):
535
536
  try:
536
537
  if a.action == "add":
537
538
  ln = sy.add(cfg, a.claim, a.tex, a.decl, a.reviewer, var=a.var, type_of=a.type_of,
538
- term=a.term)
539
+ term=a.term, at=a.at)
539
540
  print(f"linked {a.tex} in {a.claim} to {ln['lean']} (by {ln['by']}); "
540
541
  "rebuild the site to show it")
541
542
  elif a.action == "remove":
@@ -808,6 +809,8 @@ def main(argv=None):
808
809
  p_.add_argument("--type-of", dest="type_of", help="the binder whose type it is")
809
810
  p_.add_argument("--term", help="the sub-term it is, as WHERE#K: b:<binder>, c (the "
810
811
  "conclusion) or l:<part>, and the sub-term's number")
812
+ p_.add_argument("--at", help="the sub-term it is, by its identity in the proposition "
813
+ "(the `id` the reader's data gives it)")
811
814
  p_.add_argument("--as", dest="reviewer",
812
815
  default=os.environ.get("MACHINECHECKED_REVIEWER"),
813
816
  help="human:NAME or llm:MODEL (default: $MACHINECHECKED_REVIEWER)")
@@ -36,8 +36,16 @@ structure Query where
36
36
  accept_prefix : String
37
37
  allowed_axioms : Array String
38
38
  requests : Array Request
39
+ /-- Each request's heartbeat budget, in thousands as `maxHeartbeats`; Lean's default if none. -/
40
+ max_heartbeats : Option Nat := none
39
41
  deriving FromJson, Inhabited
40
42
 
43
+ /-- Runs `x` with a heartbeat budget of `n` thousand heartbeats when one is given. -/
44
+ def withBudget (n? : Option Nat) (x : MetaM α) : MetaM α :=
45
+ match n? with
46
+ | some n => withTheReader Core.Context (fun c => { c with maxHeartbeats := n * 1000 }) x
47
+ | none => x
48
+
41
49
  /-! ## Environment helpers -/
42
50
 
43
51
  def moduleOf (env : Environment) (n : Name) : Name :=
@@ -169,16 +177,19 @@ def constPrint (ci : ConstantInfo) : MetaM (String × String × Array Name) := d
169
177
  index of the statement's binder it refers to (`var`, a position in `vars`), when the innermost
170
178
  subexpression around it is one. Each tagged subexpression is also recorded as the range of
171
179
  segments it covers (`terms`, in printing order, an outer one before those inside it), so that the
172
- reader can select a whole sub-term. -/
173
- partial def segments (vars : Array FVarId) (t : Widget.CodeWithInfos) (ref : Option (String × Json))
174
- (acc : Array Json) (terms : Array (Nat × Nat)) : Array Json × Array (Nat × Nat) :=
180
+ reader can select a whole sub-term, with its position in the whole proposition (`root`, the
181
+ position of the printed expression, extended by the tag's own `subexprPos`): the identity of a
182
+ sub-term, which depends on the proposition only, not on how it is printed or split. -/
183
+ partial def segments (vars : Array FVarId) (root : SubExpr.Pos) (t : Widget.CodeWithInfos)
184
+ (ref : Option (String × Json)) (acc : Array Json) (terms : Array (Nat × Nat × String)) :
185
+ Array Json × Array (Nat × Nat × String) :=
175
186
  match t with
176
187
  | Widget.TaggedText.text s =>
177
188
  match ref with
178
189
  | some (k, v) => (acc.push (Json.mkObj [("t", s), (k, v)]), terms)
179
190
  | none => (acc.push (Json.mkObj [("t", s)]), terms)
180
191
  | Widget.TaggedText.append xs =>
181
- xs.foldl (fun (a, ts) x => segments vars x ref a ts) (acc, terms)
192
+ xs.foldl (fun (a, ts) x => segments vars root x ref a ts) (acc, terms)
182
193
  | Widget.TaggedText.tag info sub =>
183
194
  let r := match info.info.val.info with
184
195
  | .ofTermInfo ti => match ti.expr with
@@ -188,23 +199,26 @@ partial def segments (vars : Array FVarId) (t : Widget.CodeWithInfos) (ref : Opt
188
199
  | _ => none
189
200
  let start := acc.size
190
201
  let slot := terms.size
191
- let (acc', terms') := segments vars sub r acc (terms.push (start, start))
192
- (acc', terms'.set! slot (start, acc'.size))
202
+ let id := toString (root.append info.subexprPos)
203
+ let (acc', terms') := segments vars root sub r acc (terms.push (start, start, id))
204
+ (acc', terms'.set! slot (start, acc'.size, id))
193
205
 
194
206
  /-- The sub-terms worth selecting: those covering two segments or more, each range once (the
195
207
  outermost tag of a range keeps it), and none for a very large term. -/
196
- def termsJson (terms : Array (Nat × Nat)) : Json := Id.run do
208
+ def termsJson (terms : Array (Nat × Nat × String)) : Json := Id.run do
197
209
  let mut out : Array Json := #[]
198
210
  let mut seen : Array (Nat × Nat) := #[]
199
- for (a, b) in terms do
211
+ for (a, b, id) in terms do
200
212
  if b - a ≥ 2 && !seen.contains (a, b) then
201
213
  seen := seen.push (a, b)
202
- out := out.push (Json.mkObj [("from", toJson a), ("to", toJson b)])
214
+ out := out.push (Json.mkObj [("from", toJson a), ("to", toJson b), ("id", Json.str id)])
203
215
  return Json.arr (if out.size > 3000 then #[] else out)
204
216
 
205
217
  /-- The fields of a pretty-printed expression with navigable constants and binders; plain text
206
- if tagging fails, and a marker if printing fails, so that one large term cannot stop the probe. -/
207
- def ppFields (e : Expr) (vars : Array FVarId := #[]) : MetaM (List (String × Json)) := do
218
+ if tagging fails, and a marker if printing fails, so that one large term cannot stop the probe.
219
+ `root` is the position of `e` in the whole proposition (`id`). -/
220
+ def ppFields (e : Expr) (vars : Array FVarId := #[]) (root : SubExpr.Pos := .root) :
221
+ MetaM (List (String × Json)) := do
208
222
  try
209
223
  -- The type of a bound variable is printed (`pp.funBinderTypes`): `∃ Φ : T, …` says what Φ
210
224
  -- is. The head of every application is tagged too (`pp.tagAppFns`), so that the function a
@@ -213,8 +227,9 @@ def ppFields (e : Expr) (vars : Array FVarId := #[]) : MetaM (List (String × Js
213
227
  let typed := fun (o : Options) => o.setBool `pp.funBinderTypes true
214
228
  let code ← withOptions (fun o => (typed o).setBool `pp.tagAppFns true) (Widget.ppExprTagged e)
215
229
  let text := toString (← withOptions typed (ppExpr e))
216
- let (segs, terms) := segments vars code none #[] #[]
217
- return [("text", Json.str text), ("segments", Json.arr segs), ("terms", termsJson terms)]
230
+ let (segs, terms) := segments vars root code none #[] #[]
231
+ return [("text", Json.str text), ("segments", Json.arr segs), ("terms", termsJson terms),
232
+ ("id", Json.str (toString root))]
218
233
  catch _ =>
219
234
  try
220
235
  return [("text", Json.str (toString (← ppExpr e)))]
@@ -222,8 +237,8 @@ def ppFields (e : Expr) (vars : Array FVarId := #[]) : MetaM (List (String × Js
222
237
  return [("text", Json.str "(not printable)"),
223
238
  ("error", Json.str (toString (← err.toMessageData.toString)))]
224
239
 
225
- def ppJson (e : Expr) (vars : Array FVarId := #[]) : MetaM Json :=
226
- return Json.mkObj (← ppFields e vars)
240
+ def ppJson (e : Expr) (vars : Array FVarId := #[]) (root : SubExpr.Pos := .root) : MetaM Json :=
241
+ return Json.mkObj (← ppFields e vars root)
227
242
 
228
243
  def isExistsApp (e : Expr) : Option (Name × Expr) :=
229
244
  if e.isAppOfArity ``Exists 2 then
@@ -237,77 +252,89 @@ implication, "for every" or "there is" as a tree whose leaves are pretty-printed
237
252
  quantifier inside the conclusion is a node (`forall`, `exists`) with its variable's name, type and
238
253
  number, and its body as its one part. `vars` is
239
254
  threaded through the tree, so that every witness has a variable of its own: two witnesses in
240
- sibling parts never share one. Display only; it changes no record that is assessed. -/
241
- partial def logicJson (vars : Array FVarId) (e : Expr) : MetaM (Json × Array FVarId) := do
255
+ sibling parts never share one. `pos` is the position of `e` in the whole proposition; each
256
+ node and variable carries its own (`id`). Display only; it changes no record that is assessed. -/
257
+ partial def logicJson (vars : Array FVarId) (e : Expr) (pos : SubExpr.Pos) :
258
+ MetaM (Json × Array FVarId) := do
242
259
  let op := if e.isAppOfArity ``And 2 then some "and"
243
260
  else if e.isAppOfArity ``Or 2 then some "or"
244
261
  else if e.isAppOfArity ``Iff 2 then some "iff" else none
245
262
  match op with
246
263
  | some o =>
247
- let (a, vars) ← logicJson vars e.appFn!.appArg!
248
- let (b, vars) ← logicJson vars e.appArg!
249
- return (Json.mkObj [("op", o), ("args", Json.arr #[a, b])], vars)
264
+ let (a, vars) ← logicJson vars e.appFn!.appArg! pos.pushAppFn.pushAppArg
265
+ let (b, vars) ← logicJson vars e.appArg! pos.pushAppArg
266
+ return (Json.mkObj [("op", o), ("id", Json.str (toString pos)),
267
+ ("args", Json.arr #[a, b])], vars)
250
268
  | none =>
251
269
  if e.isAppOfArity ``Not 1 then
252
- let (a, vars) ← logicJson vars e.appArg!
253
- return (Json.mkObj [("op", "not"), ("args", Json.arr #[a])], vars)
270
+ let (a, vars) ← logicJson vars e.appArg! pos.pushAppArg
271
+ return (Json.mkObj [("op", "not"), ("id", Json.str (toString pos)),
272
+ ("args", Json.arr #[a])], vars)
254
273
  if let .forallE n t body bi := e then
255
274
  if (← isProp t) && !body.hasLooseBVars then
256
275
  -- An implication inside a part: its premise is a part of its own, not an assumption
257
276
  -- of the whole statement.
258
- let (a, vars) ← logicJson vars t
259
- let (b, vars) ← logicJson vars body
260
- return (Json.mkObj [("op", "implies"), ("args", Json.arr #[a, b])], vars)
261
- let tj ← ppJson t vars
277
+ let (a, vars) ← logicJson vars t pos.pushBindingDomain
278
+ let (b, vars) ← logicJson vars body pos.pushBindingBody
279
+ return (Json.mkObj [("op", "implies"), ("id", Json.str (toString pos)),
280
+ ("args", Json.arr #[a, b])], vars)
281
+ let tj ← ppJson t vars pos.pushBindingDomain
262
282
  return ← withLocalDecl n bi t fun x => do
263
283
  let idx := vars.size
264
- let (b, vars') ← logicJson (vars.push x.fvarId!) (body.instantiate1 x)
284
+ let (b, vars') ←
285
+ logicJson (vars.push x.fvarId!) (body.instantiate1 x) pos.pushBindingBody
265
286
  return (Json.mkObj [("op", "forall"), ("name", n.eraseMacroScopes.toString),
266
- ("var", toJson idx), ("type", tj), ("args", Json.arr #[b])], vars')
287
+ ("var", toJson idx), ("id", Json.str (toString pos)), ("type", tj),
288
+ ("args", Json.arr #[b])], vars')
267
289
  match isExistsApp e with
268
290
  | some (_, .lam n t body bi) =>
269
- let tj ← ppJson t vars
291
+ -- The witness is bound by the predicate `fun x => …`, the second argument of `Exists`.
292
+ let lam := pos.pushAppArg
293
+ let tj ← ppJson t vars lam.pushBindingDomain
270
294
  withLocalDecl n bi t fun x => do
271
295
  let idx := vars.size
272
- let (b, vars') ← logicJson (vars.push x.fvarId!) (body.instantiate1 x)
296
+ let (b, vars') ←
297
+ logicJson (vars.push x.fvarId!) (body.instantiate1 x) lam.pushBindingBody
273
298
  return (Json.mkObj [("op", "exists"), ("name", n.eraseMacroScopes.toString),
274
- ("var", toJson idx), ("type", tj), ("args", Json.arr #[b])], vars')
275
- | _ => return (Json.mkObj [("leaf", ← ppJson e vars)], vars)
299
+ ("var", toJson idx), ("id", Json.str (toString lam)), ("type", tj),
300
+ ("args", Json.arr #[b])], vars')
301
+ | _ => return (Json.mkObj [("leaf", ← ppJson e vars pos)], vars)
276
302
 
277
303
  /-! ## The inspection representation -/
278
304
 
279
305
  /-- Split a proposition into its quantifier prefix and its conclusion. Universal binders are
280
306
  `forall` (data), `hypothesis` (a proposition) or `instance`; existential binders are `exists`.
281
307
  Definitions are not unfolded: the prefix is the one written in the specification. -/
282
- partial def telescope (e : Expr) (acc : Array Json) (vars : Array FVarId := #[]) :
283
- MetaM (Array Json × Json) := do
308
+ partial def telescope (e : Expr) (acc : Array Json) (vars : Array FVarId := #[])
309
+ (pos : SubExpr.Pos := .root) : MetaM (Array Json × Json) := do
284
310
  match e with
285
311
  | .forallE n t body bi =>
286
312
  let isHyp ← isProp t
287
313
  let role :=
288
314
  if bi.isInstImplicit then "instance" else if isHyp then "hypothesis" else "forall"
289
- let tj ← ppJson t vars
315
+ let tj ← ppJson t vars pos.pushBindingDomain
290
316
  withLocalDecl n bi t fun x => do
291
317
  let hyps := (acc.filter fun j => j.getObjValD "role" == Json.str "hypothesis").size
292
318
  let nm := if n.hasMacroScopes || n.isAnonymous then s!"h{hyps + 1}"
293
319
  else n.toString
294
320
  -- What an instance supplies: a proposition (`[Nonempty E]`) or data (`[Inhabited E]`).
295
321
  let supplies := if isHyp then "proposition" else "data"
296
- let j := Json.mkObj [("role", role), ("name", nm),
322
+ let j := Json.mkObj [("role", role), ("name", nm), ("id", Json.str (toString pos)),
297
323
  ("type", tj), ("binder", binderStr bi), ("supplies", supplies)]
298
- telescope (body.instantiate1 x) (acc.push j) (vars.push x.fvarId!)
324
+ telescope (body.instantiate1 x) (acc.push j) (vars.push x.fvarId!) pos.pushBindingBody
299
325
  | _ =>
300
326
  match isExistsApp e with
301
327
  | some (_, .lam n t body bi) =>
302
- let tj ← ppJson t vars
328
+ let lam := pos.pushAppArg
329
+ let tj ← ppJson t vars lam.pushBindingDomain
303
330
  withLocalDecl n bi t fun x => do
304
331
  let j := Json.mkObj [("role", "exists"), ("name", n.eraseMacroScopes.toString),
305
- ("type", tj), ("binder", binderStr bi)]
306
- telescope (body.instantiate1 x) (acc.push j) (vars.push x.fvarId!)
332
+ ("id", Json.str (toString lam)), ("type", tj), ("binder", binderStr bi)]
333
+ telescope (body.instantiate1 x) (acc.push j) (vars.push x.fvarId!) lam.pushBindingBody
307
334
  | _ =>
308
335
  -- The conclusion, with its logical shape when it has one (`logic`, display only).
309
- let fields ← ppFields e vars
310
- let (logic, _) ← logicJson vars e
336
+ let fields ← ppFields e vars pos
337
+ let (logic, _) ← logicJson vars e pos
311
338
  let shaped := (logic.getObjVal? "op").toOption.isSome
312
339
  return (acc, Json.mkObj (if shaped then fields ++ [("logic", logic)] else fields))
313
340
  where
@@ -357,7 +384,8 @@ def emitClosure (h : IO.FS.Handle) (roots : Array Name) (root : Name) (used : Ar
357
384
  unless inScope roots env n do continue
358
385
  let some c := env.find? n | continue
359
386
  members := members.push n.toString
360
- let (j, more) ← declRecord roots n c
387
+ -- Each member has its own heartbeat budget: a closure can hold thousands.
388
+ let (j, more) ← withCurrHeartbeats (declRecord roots n c)
361
389
  unless (← seen.get).contains n do
362
390
  seen.modify (·.insert n)
363
391
  emit h j
@@ -460,7 +488,10 @@ def indexRecords (h : IO.FS.Handle) (roots : Array Name) : MetaM Unit := do
460
488
  | .axiomInfo _ => some "axiom" | _ => none
461
489
  let some k := kind | continue
462
490
  if k == "def" && (← isInstance n) then continue
463
- let ty ← try pure (toString (← ppExpr ci.type)) catch _ => pure "(not printable)"
491
+ -- Each declaration printed has its own heartbeat budget: a project can hold tens of
492
+ -- thousands, more than one budget prints.
493
+ let ty ← withCurrHeartbeats do
494
+ try pure (toString (← ppExpr ci.type)) catch _ => pure "(not printable)"
464
495
  let doc ← findDocString? env n
465
496
  emit h (Json.mkObj [("record", "index"), ("name", n.toString), ("kind", k),
466
497
  ("module", mod.toString), ("range", ← rangeJson n),
@@ -605,8 +636,10 @@ open ProofLensProbe in
605
636
  ("githash", Lean.githash)])
606
637
  layering h q
607
638
  for r in q.requests do
608
- -- Each request has its own heartbeat budget.
609
- try withCurrHeartbeats <|
639
+ -- Each request has its own heartbeat budget. A request that fails, including by running
640
+ -- out of heartbeats (a runtime exception, which `try` does not catch), emits an error
641
+ -- record for itself and the probe goes on.
642
+ tryCatchRuntimeEx (withBudget q.max_heartbeats <| withCurrHeartbeats do
610
643
  match r.kind with
611
644
  | "spec" => specRecord h q roots seen r.name.toName
612
645
  | "accept" | "refute" => proofRecord h q r.kind r.name.toName (r.spec.map (·.toName))
@@ -626,9 +659,9 @@ open ProofLensProbe in
626
659
  else
627
660
  emit h (Json.mkObj [("record", "defclosure"), ("name", r.name),
628
661
  ("errors", toJson #["missing"])])
629
- | _ => pure ()
630
- catch err =>
631
- emit h (Json.mkObj [("record", if r.kind == "decl" then "defclosure" else r.kind),
632
- ("name", r.name), ("spec", match r.spec with | some x => Json.str x | none => Json.null),
633
- ("errors", toJson #[s!"probe-error: {← err.toMessageData.toString}"])])
662
+ | _ => pure ())
663
+ (fun err => do
664
+ emit h (Json.mkObj [("record", if r.kind == "decl" then "defclosure" else r.kind),
665
+ ("name", r.name), ("spec", match r.spec with | some x => Json.str x | none => Json.null),
666
+ ("errors", toJson #[s!"probe-error: {← err.toMessageData.toString}"])]))
634
667
  emit h (Json.mkObj [("record", "done")])
@@ -105,7 +105,10 @@ def public_claim(chunk: dict, pub) -> dict:
105
105
  out["location"] = chunk.get("location") if pub.source_text else None
106
106
  out["statement_tex"] = chunk.get("statement_tex") if pub.source_text else None
107
107
  a = chunk.get("anchor")
108
- out["anchor"] = _pick(a, ["id", "env", "number", "label", "begin", "end", "kind", "source_sha256"] +
108
+ # `head` (the baseline of the first line) is what the index's top is computed from, so the
109
+ # published claim must keep it for its location to agree with the index.
110
+ out["anchor"] = _pick(a, ["id", "env", "number", "label", "begin", "head", "end", "kind",
111
+ "source_sha256"] +
109
112
  (["file", "line"] if pub.source_text else [])) if a else None
110
113
  clauses = []
111
114
  for cl in chunk["clauses"]:
@@ -64,9 +64,10 @@ def statements(fy: dict) -> list[dict]:
64
64
  continue
65
65
  rest = src[m.end():]
66
66
  module = r.get("module") if isinstance(r.get("module"), str) else None
67
+ note = r.get("note").strip() if isinstance(r.get("note"), str) else ""
67
68
  out.append({"source": src, "kind": m.group(1).lower(), "number": m.group(2),
68
69
  "hint": _tokens(rest), "lean": names, "status": r.get("status"),
69
- "module": module})
70
+ "module": module, "note": note})
70
71
  return out
71
72
 
72
73
 
@@ -110,7 +110,7 @@ def symbol_links(display: dict | None, cid: str, tex: str | None, lean: dict) ->
110
110
  or not tex or pins.get("source") != sha256_text(tex)
111
111
  or shown is None
112
112
  or ("target" in pins and pins["target"] != shown)
113
- or ("term" in target and "target" not in pins))
113
+ or (("term" in target or "at" in target) and "target" not in pins))
114
114
  out.append({"symbol": ln.get("symbol") or {}, "lean": target, "by": ln.get("by"),
115
115
  "stale": bool(stale)})
116
116
  return out
@@ -74,7 +74,8 @@ def build(cfg: Config, release: str | None = None, skip_lean: bool = False,
74
74
  or (r["kind"] in ("accept", "refute", "witness") and
75
75
  f"{r['kind']}:{r['name']}:{r.get('spec') or ''}" not in lean["proofs"])]
76
76
  if missing:
77
- raise RuntimeError(f"the stored probe does not cover {missing[:5]}; run the probe")
77
+ raise StaleEvidence(f"the stored Lean results do not cover {', '.join(missing[:5])}"
78
+ + (", …" if len(missing) > 5 else "") + "; " + RUN_PROBE)
78
79
  lean_digest = lean_inputs_digest(cfg)
79
80
  log("probe: reusing the stored probe records (no Lean input changed)")
80
81
  elif not skip_lean:
@@ -214,16 +215,17 @@ def reusable_lean(cfg: Config) -> dict:
214
215
  content of every Lean input (here and in every path dependency) and the same probe."""
215
216
  rels = ev.releases(cfg.out_dir)
216
217
  if not rels:
217
- raise RuntimeError("no stored evidence to reuse")
218
+ raise StaleEvidence("no stored Lean results to reuse; " + RUN_PROBE)
218
219
  body = ev.load(cfg.out_dir, read_json(rels[-1])["evidence"])["body"]
219
220
  lean, prov = body.get("lean"), body["provenance"]
220
221
  if not lean or not prov.get("lean_inputs_sha256") or not prov.get("probe_sha256"):
221
- raise RuntimeError("the stored evidence does not record its Lean inputs; run the probe")
222
+ raise StaleEvidence("the stored Lean results do not record their Lean inputs; "
223
+ + RUN_PROBE)
222
224
  if prov["lean_inputs_sha256"] != lean_inputs_digest(cfg):
223
- raise RuntimeError("Lean inputs changed since the stored probe (here or in a path "
224
- "dependency); run the probe")
225
+ raise StaleEvidence("Lean inputs changed since the stored Lean results (here or in a "
226
+ "path dependency); " + RUN_PROBE)
225
227
  if prov["probe_sha256"] != probe_digest():
226
- raise RuntimeError("the probe changed since the stored records; run the probe")
228
+ raise StaleEvidence("the Lean probe changed since the stored Lean results; " + RUN_PROBE)
227
229
  return lean
228
230
 
229
231
 
@@ -242,6 +244,7 @@ class StaleEvidence(RuntimeError):
242
244
 
243
245
 
244
246
  NO_RELEASE = "no release: run `machinechecked build` first"
247
+ RUN_PROBE = "run `machinechecked build` without `--reuse-lean`"
245
248
 
246
249
 
247
250
  def inventory_changed(cfg: Config, body: dict) -> str | None: