Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto-compilation & -setup of dependencies on file worker startup #263

Merged
merged 14 commits into from
Jan 19, 2021

Conversation

Kha
Copy link
Member

@Kha Kha commented Jan 13, 2021

This PR extends the file worker to call leanpkg print-path <imports> on startup (if there is a leanpkg.toml in the workspace root), which will configure the current package (compiling all dependencies), compile the specified (local) modules, and print the corresponding LEAN_PATH to stdout, where it is picked up by the file worker. While running, the latest stderr line of leanpkg is reported as an "information" message.

Note that this won't work when editing Lean's own src/ because there is no leanpkg binary in stage 0.

There are two more minor server changes included:

  • A fatal file worker exception after receiving didOpen (i.e. when we know the path of the current file) is reported as a diagnostic, which is great for displaying the result of a failed leanpkg invocation
  • Only didChange requests restart a crashed file worker now; without this change, the documentSymbol request threw my Emacs into a restart loop

Feel free to give this a try, perhaps even on Windows if someone feels courageous!

How to test:

  • open tests/leanpkg/b/ as a workspace folder
  • opening B.lean in there should automatically compile & find B/Foo.lean as well as the dependency ../a
  • try editing B/Foo.lean, e.g. introducing the commented delay or an error; restarting the worker for B.lean should make the change visible there

TODO:

  • Analogous feature using Nix when there is a flake.nix in the root instead

@Kha Kha marked this pull request as ready for review January 13, 2021 16:57
@Kha Kha marked this pull request as draft January 13, 2021 17:39
src/Leanpkg.lean Outdated
@@ -18,6 +18,24 @@ def readManifest : IO Manifest := do
def writeManifest (manifest : Lean.Syntax) (fn : String) : IO Unit := do
IO.FS.writeFile fn manifest.reprint.get!

def lockFileName := "build/.lock"

partial def withLockFile (x : IO α) : IO α :=
Copy link
Member Author

Choose a reason for hiding this comment

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

let stderr ← IO.ofExcept stderr.get
if (← leanpkgProc.wait) == 0 then
match stdout.split (· == '\n') with
| [leanPath, leanSrcPath] => searchPathRef.set (← parseSearchPath leanPath (← getBuiltinSearchPath))
Copy link
Member Author

Choose a reason for hiding this comment

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

@leodemoura @Vtec234 now with LEAN_SRC_PATH (unused so far)

@Kha
Copy link
Member Author

Kha commented Jan 19, 2021

Nix support is working, so this should be ready to go:
image
Getting the gorgeous Nix progress bar I showed off in the demo in there is future work... :)

@Kha Kha merged commit 3fbf405 into leanprover:master Jan 19, 2021
ChrisHughes24 pushed a commit to ChrisHughes24/lean4 that referenced this pull request Dec 2, 2022
- split Mathlib/Lean/Expr into multiple files.
- implement a version of replaceRecM that correctly instantiates free vars.
- some additonal Expr functions

These are prereqs of leanprover#234  and leanprover#229 

Co-authored-by: Ed Ayers <EdAyers@users.noreply.github.com>
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.

1 participant