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

refactor: simplify merlin diagnostics #1005

Merged
merged 1 commit into from
Jan 12, 2023

Conversation

rgrinberg
Copy link
Member

Updating the document with no changes is no longer needed because we
don't reuse the pipeline.

Signed-off-by: Rudi Grinberg me@rgrinberg.com

@rgrinberg rgrinberg force-pushed the ps/rr/refactor__simplify_merlin_diagnostics branch 3 times, most recently from b76d042 to e0cbc79 Compare January 11, 2023 22:14
@ulugbekna ulugbekna mentioned this pull request Jan 11, 2023
let+ document = f document in
{ doc with document = Some document }
in
Table.set t.db uri doc)
Copy link
Member Author

Choose a reason for hiding this comment

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

@ulugbekna this code was evil. We're updating a value in the hash table after waiting for the termination of f, but the value might be out of date by then due to a concurrent document change notification.

ocaml-lsp-server/src/document.ml Outdated Show resolved Hide resolved
@@ -128,22 +128,15 @@ module Single_pipeline : sig
-> f:(Mpipeline.t -> 'a)
-> ('a, Exn_with_backtrace.t) result Fiber.t
end = struct
type t =
{ thread : Lev_fiber.Thread.t
; mutable last : (Text_document.t * Mconfig.t * Mpipeline.t) option
Copy link
Collaborator

@ulugbekna ulugbekna Jan 11, 2023

Choose a reason for hiding this comment

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

does this mean that we don't try reusing the last pipeline even if it's the same document?

Copy link
Member Author

@rgrinberg rgrinberg Jan 11, 2023

Choose a reason for hiding this comment

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

Yes, the optimization is gone. I don't think it ever worked anyway given that it relied on physical equality of the Mconfig.t being returned.

Comment on lines +266 to 272
Document_store.parallel_iter document_store ~f:(fun doc ->
match Document.kind doc with
| `Other -> Fiber.return doc
| `Other -> Fiber.return ()
| `Merlin merlin ->
let doc = Document.update_text doc [] in
let+ () =
Diagnostics.merlin_diagnostics diagnostics merlin
in
doc)
Diagnostics.merlin_diagnostics diagnostics merlin)
in
Diagnostics.send diagnostics `All
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this re-make pipelines and send diagnostics to all files on a dune build completion (when dune is in watch mode)? Sounds super expensive

Copy link
Member Author

Choose a reason for hiding this comment

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

Wait until you see how expensive is the build itself :)

But more seriously, of course it would be better to recompute only the documents which were invalidated by the build. Unfortunately that would be far more difficult.

Copy link
Collaborator

Choose a reason for hiding this comment

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

the documents which were invalidated by the build. Unfortunately that would be far more difficult.

But dune knows what those documents are, right? (because of the incremental re-building it has)

If yes, that becomes a matter of extending the dune rpc?

Copy link
Collaborator

Choose a reason for hiding this comment

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

the documents which were invalidated by the build. Unfortunately that would be far more difficult.

actually, yes, I started noticing how my laptop fans go off often if I have dune running in watch mode

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, that would be enough. In particular, the rule would be that a merlin document should be invalidated whenever:

  • Any .cmi file in its -I directories has been invalidated
  • Any of the preprocessing binaries has been invalidated
  • Any of the runtime dependencies of the preprocessing binaries has been invalidated

Copy link
Member Author

Choose a reason for hiding this comment

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

actually, yes, I started noticing how my laptop fans go off often if I have dune running in watch mode

Thankfully you can limit the concurrency with -j. That calms down the fans considerably.

@rgrinberg rgrinberg force-pushed the ps/rr/refactor__simplify_merlin_diagnostics branch from e0cbc79 to c438bc2 Compare January 11, 2023 23:55
@rgrinberg rgrinberg added this to the 1.15.1 milestone Jan 12, 2023
Updating the document with no changes is no longer needed because we
don't reuse the pipeline.

This also fixes a bug whenever we're editing a document and dune is
running in watch mode. The issue was that we were updating a document
the store in the background and overwriting updates to the document
requested by the user.

Signed-off-by: Rudi Grinberg <me@rgrinberg.com>

<!-- ps-id: a79143e1-01bc-4565-b900-ee5d97474ced -->
@rgrinberg rgrinberg force-pushed the ps/rr/refactor__simplify_merlin_diagnostics branch from c438bc2 to 917509f Compare January 12, 2023 00:09
@rgrinberg rgrinberg merged commit 77625a9 into master Jan 12, 2023
ulugbekna added a commit to ulugbekna/opam-repository that referenced this pull request Jan 19, 2023
CHANGES:

## Fixes

- Fix race condition when a document was being edited and dune in watch mode was
  running ([ocaml/ocaml-lsp#1005](ocaml/ocaml-lsp#1005), fixes
  [ocaml/ocaml-lsp#941](ocaml/ocaml-lsp#941),
  [ocaml/ocaml-lsp#1003](ocaml/ocaml-lsp#1003))
ulugbekna added a commit to ulugbekna/opam-repository that referenced this pull request Jan 19, 2023
CHANGES:

## Fixes

- Fix race condition when a document was being edited and dune in watch mode was
  running ([ocaml/ocaml-lsp#1005](ocaml/ocaml-lsp#1005), fixes
  [ocaml/ocaml-lsp#941](ocaml/ocaml-lsp#941),
  [ocaml/ocaml-lsp#1003](ocaml/ocaml-lsp#1003))
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.

2 participants