Skip to content
This repository was archived by the owner on Aug 24, 2024. It is now read-only.

fix: print-paths changed to setup-file in Lean v4.4.0 #55

Merged
merged 5 commits into from
Jan 10, 2024

Conversation

utensil
Copy link
Contributor

@utensil utensil commented Dec 11, 2023

Description

LeanInk/Analysis/LeanContext.lean relies on print-paths to initializeLakeContext, but in leanprover/lean4#2858 which is part of Lean v4.4.0 release, print-paths is changed to setup-file, with an extra parameter and changed JSON output.

This PR bumps LeanInk to use v4.4.0-rc1, replacing print-paths with setup-file and handles the parameter and output change accordingly.

There is probably no immediate need to merge this PR as doc-gen4 is using https://github.com/hargoniX/LeanInk/ which is 30+ commits behind leanprover/LeanInk and doesn't have this file, and I'm not aware of other major users.

More discussions on Zulip.

Notable Changes

Additional Notes

@utensil
Copy link
Contributor Author

utensil commented Dec 11, 2023

Locally it works fine (on Mac and my Ubuntu CI), but CI is red. Will look into that later.

@utensil
Copy link
Contributor Author

utensil commented Dec 12, 2023

There is no way I can pass the test for LeanInk. I tried the 2 approaches:

  1. bumping Lean for LeanInk, so LeanInk itself and the target Lean program are both on v4.4.0, but tests in LeanInk are outdated by this leap of Lean toolchain, causing many failures that I don't intend to fix in this PR (or should I?). (this is now at my fix-print-path-bump branch)
  2. don't bump Lean for LeanInk, so LeanInk itself is on old Lean (on this PR branch), it works fine for a target Lean program on v4.4.0 (locally), but tests in LeanInk are still failing because now the target Lean programs are the tests in LeanInk on the old Lean toolchain which doesn't play with setup-file.

@utensil
Copy link
Contributor Author

utensil commented Dec 12, 2023

I'll take approach 1, and fix the tests later. In the meanwhile, code in this PR or branch fix-print-path-nobump can lake build and works for target Lean code on Lean v4.4.0.

@@ -980,7 +980,7 @@
"The `simp` tactic uses lemmas and hypotheses to simplify the main goal target or\nnon-dependent hypotheses. It has many variants:\n- `simp` simplifies the main goal target using lemmas tagged with the attribute `[simp]`.\n- `simp [h₁, h₂, ..., hₙ]` simplifies the main goal target using the lemmas tagged\n with the attribute `[simp]` and the given `hᵢ`'s, where the `hᵢ`'s are expressions.\n If an `hᵢ` is a defined constant `f`, then the equational lemmas associated with\n `f` are used. This provides a convenient way to unfold `f`.\n- `simp [*]` simplifies the main goal target using the lemmas tagged with the\n attribute `[simp]` and all hypotheses.\n- `simp only [h₁, h₂, ..., hₙ]` is like `simp [h₁, h₂, ..., hₙ]` but does not use `[simp]` lemmas.\n- `simp [-id₁, ..., -idₙ]` simplifies the main goal target using the lemmas tagged\n with the attribute `[simp]`, but removes the ones named `idᵢ`.\n- `simp at h₁ h₂ ... hₙ` simplifies the hypotheses `h₁ : T₁` ... `hₙ : Tₙ`. If\n the target or another hypothesis depends on `hᵢ`, a new simplified hypothesis\n `hᵢ` is introduced, but the old one remains in the local context.\n- `simp at *` simplifies all the hypotheses and the target.\n- `simp [*] at *` simplifies target and all (propositional) hypotheses using the\n other hypotheses.\n",
"_type": "token"},
{"typeinfo":
{"type": "{α : Type ?u.3247} → [self : BEq α] → α → α → Bool",
{"type": "{α : Type ?u.3298} → [self : BEq α] → α → α → Bool",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

De Bruijn index change across versions seems to be normal.

@@ -1939,7 +1939,7 @@
"raw": "absurd",
"link": null,
"docstring":
"Anything follows from two contradictory hypotheses. Example:\n```\nexample (hp : p) (hnp : ¬p) : q := absurd hp hnp\n```\nFor more information: [Propositional Logic](https://leanprover.github.io/theorem_proving_in_lean4/propositions_and_proofs.html#propositional-logic)\n",
"Anything follows from two contradictory hypotheses. Example:\n```\nexample (hp : p) (hnp : ¬p) : q := absurd hp hnp\n```\nFor more information: [Propositional Logic](https://lean-lang.org/theorem_proving_in_lean4/propositions_and_proofs.html#propositional-logic)\n",
Copy link
Contributor Author

@utensil utensil Dec 12, 2023

Choose a reason for hiding this comment

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

This file is full of this url change. Here is the meaningful diff produced by

git diff 71b8365e08fb8b786cff628bbea38a2512370ca7 0227adbf7ee9b323efa0c47bbd00c8976b51e4a1 test/bench/Basic.lean.leanInk.expected|grep -E '^[-+] '|grep -v theorem_proving_in_lean4
-    {"type": "{α : Type ?u.3247} → [self : BEq α] → α → α → Bool",
+    {"type": "{α : Type ?u.3298} → [self : BEq α] → α → α → Bool",
-   {"typeinfo": {"type": "m + n = k + m", "name": "h", "_type": "typeinfo"},
+   {"typeinfo": {"type": "n + m = k + m", "name": "h", "_type": "typeinfo"},
-    "conclusion": "0 = 0 + zero * k",
+    "conclusion": "0 = zero * m + zero * k",
-  [{"name": "",
-    "hypotheses": [],
-    "conclusion": "Goals accomplished! 🐙",
+  [{"name": "zero",
+    "hypotheses":
+    [{"type": "Nat", "names": ["m", "k"], "body": "", "_type": "hypothesis"}],
+    "conclusion": "0 = 0 + zero * k",
-  [{"name": "zero",
-    "hypotheses":
-    [{"type": "Nat", "names": ["m", "k"], "body": "", "_type": "hypothesis"}],
-    "conclusion": "0 = zero * m + zero * k",
+  [{"name": "",
+    "hypotheses": [],
+    "conclusion": "Goals accomplished! 🐙",
-   {"typeinfo": {"type": "n * m = k * m", "name": "h", "_type": "typeinfo"},
+   {"typeinfo": {"type": "m * n = k * m", "name": "h", "_type": "typeinfo"},
-    "raw": " => ",
+    "raw": " ",
- {"messages": [],
+ {"messages":
+  [{"contents":
+    "Error: unsolved goals\ncase succ\nn : Nat\nih : 0 - n = 0\n⊢ pred 0 = 0",
+    "_type": "message"}],
-  [{"name": "",
-    "hypotheses": [],
-    "conclusion": "Goals accomplished! 🐙",
+  [{"name": "succ",
+    "hypotheses":
+    [{"type": "Nat", "names": ["n"], "body": "", "_type": "hypothesis"},
+     {"type": "0 - n = 0", "names": ["ih"], "body": "", "_type": "hypothesis"}],
+    "conclusion": "0 - succ n = 0",
+    "_type": "goal"}],
+  "contents":
+  [{"typeinfo": null,
+    "semanticType": null,
+    "raw": "=> ",
+    "link": null,
+    "docstring":
+    "In induction alternative, which can have 1 or more cases on the left\nand `_`, `?_`, or a tactic sequence after the `=>`.\n",
+    "_type": "token"}],
+  "_type": "sentence"},
+ {"messages":
+  [{"contents":
+    "Error: unsolved goals\ncase succ\nn : Nat\nih : 0 - n = 0\n⊢ pred 0 = 0",
+    "_type": "message"}],
+  "goals":
+  [{"name": "succ",
+    "hypotheses":
+    [{"type": "Nat", "names": ["n"], "body": "", "_type": "hypothesis"},
+     {"type": "0 - n = 0", "names": ["ih"], "body": "", "_type": "hypothesis"}],
+    "conclusion": "pred 0 = 0",

@@ -40,7 +40,7 @@
"raw": "Unit",
"link": null,
"docstring":
"The unit type, the canonical type with one element, named `unit` or `()`.\nIn other words, it describes only a single value, which consists of said constructor applied\nto no arguments whatsoever.\nThe `Unit` type is similar to `void` in languages derived from C.\n\n`Unit` is actually defined as `PUnit.{0}` where `PUnit` is the universe\npolymorphic version. The `Unit` should be preferred over `PUnit` where possible to avoid\nunnecessary universe parameters.\n\nIn functional programming, `Unit` is the return type of things that \"return\nnothing\", since a type with one element conveys no additional information.\nWhen programming with monads, the type `m Unit` represents an action that has\nsome side effects but does not return a value, while `m α` would be an action\nthat has side effects and returns a value of type `α`.\n",
"The unit type, the canonical type with one element, named `unit` or `()`.\nIn other words, it describes only a single value, which consists of said constructor applied\nto no arguments whatsoever.\nThe `Unit` type is similar to `void` in languages derived from C.\n\n`Unit` is actually defined as `PUnit.{1}` where `PUnit` is the universe\npolymorphic version. The `Unit` should be preferred over `PUnit` where possible to avoid\nunnecessary universe parameters.\n\nIn functional programming, `Unit` is the return type of things that \"return\nnothing\", since a type with one element conveys no additional information.\nWhen programming with monads, the type `m Unit` represents an action that has\nsome side effects but does not return a value, while `m α` would be an action\nthat has side effects and returns a value of type `α`.\n",
Copy link
Contributor Author

@utensil utensil Dec 12, 2023

Choose a reason for hiding this comment

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

PUnit.{0} changed to PUnit.{1}.

@@ -103,7 +103,7 @@
"link": null,
"docstring": null,
"_type": "token"},
{"typeinfo": {"type": "A × A → B", "name": "B", "_type": "typeinfo"},
{"typeinfo": {"type": "Type", "name": "B", "_type": "typeinfo"},
Copy link
Contributor Author

@utensil utensil Dec 12, 2023

Choose a reason for hiding this comment

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

No idea why this is A × A → B before. B is

structure B where
  pair : A × A

Obviously B is just a Type.

{"messages":
[{"contents":
"Error: unsolved goals\ncase succ\nn : Nat\nih : 0 - n = 0\n⊢ pred 0 = 0",
"_type": "message"}],
Copy link
Contributor Author

@utensil utensil Dec 12, 2023

Choose a reason for hiding this comment

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

This proof is no longer proven, will investigate. The same applies to all Error: unsolved goals.

Copy link
Contributor Author

@utensil utensil Dec 12, 2023

Choose a reason for hiding this comment

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

@[simp] protected theorem zero_sub (n : Nat) : 0 - n = 0 := by
  induction n with
  | zero => rfl
  | succ n ih => simp [ih, Nat.sub_succ]

This proof failed to use the protected simp lemma pred_zero in the same namespace, is this expected?

@@ -51,11 +56,13 @@ def initializeLakeContext (lakeFile : FilePath) (header : Syntax) : AnalysisM Un
| 0 => do
let stdout := stdout.split (· == '\n') |>.getLast!
match Json.parse stdout with
| Except.error _ => throw <| IO.userError s!"Failed to parse lake output: {stdout}"
| Except.error msg => throw <| IO.userError s!"Failed to parse lake output: {stdout}\nerror: {msg}"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The msg is helpful for debugging.

@femtomc
Copy link

femtomc commented Dec 28, 2023

Note that this branch (and its fixes) also fixes my issue #56.

@mhuisi mhuisi merged commit 58755bf into leanprover:main Jan 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants