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

feature(melange): add correct stdlib dir #6443

Merged
merged 1 commit into from
Nov 11, 2022

Conversation

rgrinberg
Copy link
Member

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

ps-id: cce82426-de1a-4473-a3af-1a91ab987de5

Copy link
Collaborator

@anmonteiro anmonteiro left a comment

Choose a reason for hiding this comment

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

LGTM, asked 2 clarifications

@rgrinberg rgrinberg force-pushed the ps/rr/feature_melange___add_correct_stdlib_dir branch 2 times, most recently from 6b85079 to dfe45e4 Compare November 11, 2022 04:04
@anmonteiro
Copy link
Collaborator

I was thinking whether this would be correct in watch mode, but I believe there's no way to set an environment variable while the watcher is running. If that's the case, I'm convinced this is correct.

let open Memo.O in
let* env = Super_context.env_node sctx ~dir >>= Env_node.external_env in
match Env.get env "MELANGELIB" with
| Some p -> Memo.return (Some (Path.of_string p))
Copy link
Member Author

Choose a reason for hiding this comment

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

This branch is an optimization I suppose. We can still just run the binary and get the expected result.

@rgrinberg
Copy link
Member Author

but I believe there's no way to set an environment variable while the watcher is running

Yes, for now there isn't. We have a goal of making dune build redirect build requests to the build server running in watch mode. Such a build request would also transfer the environment from the dune build command.

Another long term goal is to persist these memoization tables between runs so that restarting dune is fast.

Copy link
Collaborator

@jchavarri jchavarri left a comment

Choose a reason for hiding this comment

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

Looks good, I wonder if we can get rid of the optionality in stdlib_dir at some point, or it will be permanent.

let open Memo.O in
let* env = Super_context.env_node sctx ~dir >>= Env_node.external_env in
match Env.get env "MELANGELIB" with
| Some p -> Memo.return (Some (Path.of_string p))
Copy link
Collaborator

Choose a reason for hiding this comment

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

for the record, @emillon and I ran into some cases where MELANGELIB would be set to empty string. Not sure if it should be handled here. Or it is enough with melange-re/melange#412.

| None -> (
let* melc = melc sctx ~dir in
match melc with
| Error _ -> Memo.return None
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe after #6403 we can fail here too? So that melange_where return a non-optional value?

Copy link
Member Author

Choose a reason for hiding this comment

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

If we fail, then we wouldn't generate any of the rules in this directory. That would be highly suboptimal

@rgrinberg rgrinberg force-pushed the ps/rr/feature_melange___add_correct_stdlib_dir branch 2 times, most recently from dc17733 to 25a4a36 Compare November 11, 2022 14:58
@rgrinberg
Copy link
Member Author

@jchavarri i've fixed a few more issues. give this a try when you have time.

@rgrinberg rgrinberg force-pushed the ps/rr/feature_melange___add_correct_stdlib_dir branch from 25a4a36 to 5ffdf8d Compare November 11, 2022 16:25
@jchavarri
Copy link
Collaborator

I am trying a fork of the melange opam template on the dune branch, pinning both melange and dune:

opam pin add dune https://github.com/ocaml/dune.git#5ffdf8d0541dc4a3d976d48a745deea7e3833ce9
opam pin add melange https://github.com/melange-re/melange.git#660be9975b98f2b7defa7506aaa6d96801e24613

This is what I found:


For modules on melange.emit entries, the following error is shown on the editor:

No config found for file "Hello.ml" in ".". Try calling `dune build`.

Maybe expected?


For modules inside Melange libraries that use Melange stdlib (e.g. Js.log):

  • type annotations and go to definition work! 🎉 for both stdlib and user implemented functions
  • but the following errors are shown on OCaml lsp console when hovering over the functions of the stdlib:
[Error - 6:20:10 PM] Request textDocument/hover failed.
  Message: uncaught exception
  Code: -32603 
[object Object]

@rgrinberg
Copy link
Member Author

@jchavarri could you turn on the verbosity according to ocamllabs/vscode-ocaml-platform#1020 (comment)

I'd like to see the error.

@jchavarri
Copy link
Collaborator

[Trace - 11:13:45 PM] Sending request 'textDocument/hover - (19)'.
Params: {
    "textDocument": {
        "uri": "file:///home/me/code/melange-opam-template/lib2/name.ml"
    },
    "position": {
        "line": 2,
        "character": 28
    }
}


[Trace - 11:13:45 PM] Received response 'textDocument/hover - (19)' in 2ms. Request failed: uncaught exception (-32603).
Error data: {
    "exn": "Ocaml_typing.Envaux.Error(_)",
    "backtrace": "Raised at Ocaml_typing__Envaux.env_from_summary in file \"ocaml-lsp-server/vendor/merlin/src/ocaml/typing/envaux.ml\", line 69, characters 32-70\nCalled from Ocaml_typing__Envaux.env_from_summary in file \"ocaml-lsp-server/vendor/merlin/src/ocaml/typing/envaux.ml\", line 45, characters 12-38\nCalled from Ocaml_typing__Envaux.env_from_summary in file \"ocaml-lsp-server/vendor/merlin/src/ocaml/typing/envaux.ml\", line 53, characters 12-38\nCalled from Ocaml_typing__Envaux.env_from_summary in file \"ocaml-lsp-server/vendor/merlin/src/ocaml/typing/envaux.ml\", line 53, characters 12-38\nCalled from Ocaml_typing__Envaux.env_from_summary in file \"ocaml-lsp-server/vendor/merlin/src/ocaml/typing/envaux.ml\", line 53, characters 12-38\nCalled from Ocaml_typing__Envaux.env_from_summary in file \"ocaml-lsp-server/vendor/merlin/src/ocaml/typing/envaux.ml\", line 45, characters 12-38\nCalled from Ocaml_typing__Envaux.env_from_summary in file \"ocaml-lsp-server/vendor/merlin/src/ocaml/typing/envaux.ml\", line 45, characters 12-38\nCalled from Ocaml_typing__Envaux.env_from_summary in file \"ocaml-lsp-server/vendor/merlin/src/ocaml/typing/envaux.ml\", line 45, characters 12-38\nCalled from Ocaml_typing__Envaux.env_from_summary in file \"ocaml-lsp-server/vendor/merlin/src/ocaml/typing/envaux.ml\", line 45, characters 12-38\nCalled from Ocaml_typing__Envaux.env_from_summary in file \"ocaml-lsp-server/vendor/merlin/src/ocaml/typing/envaux.ml\", line 41, characters 24-50\nCalled from Ocaml_typing__Envaux.env_from_summary in file \"ocaml-lsp-server/vendor/merlin/src/ocaml/typing/envaux.ml\", line 41, characters 24-50\nCalled from Ocaml_typing__Envaux.env_from_summary in file \"ocaml-lsp-server/vendor/merlin/src/ocaml/typing/envaux.ml\", line 41, characters 24-50\nCalled from Ocaml_typing__Envaux.env_from_summary in file \"ocaml-lsp-server/vendor/merlin/src/ocaml/typing/envaux.ml\", line 41, characters 24-50\nCalled from Ocaml_typing__Envaux.env_from_summary in file \"ocaml-lsp-server/vendor/merlin/src/ocaml/typing/envaux.ml\", line 41, characters 24-50\nCalled from Ocaml_typing__Envaux.env_from_summary in file \"ocaml-lsp-server/vendor/merlin/src/ocaml/typing/envaux.ml\", line 45, characters 12-38\nCalled from Ocaml_typing__Envaux.env_from_summary in file \"ocaml-lsp-server/vendor/merlin/src/ocaml/typing/envaux.ml\", line 41, characters 24-50\nCalled from Ocaml_typing__Envaux.env_from_summary in file \"ocaml-lsp-server/vendor/merlin/src/ocaml/typing/envaux.ml\", line 41, characters 24-50\nCalled from Ocaml_typing__Envaux.env_from_summary in file \"ocaml-lsp-server/vendor/merlin/src/ocaml/typing/envaux.ml\", line 41, characters 24-50\nCalled from Ocaml_typing__Envaux.env_from_summary in file \"ocaml-lsp-server/vendor/merlin/src/ocaml/typing/envaux.ml\", line 41, characters 24-50\nCalled from Ocaml_typing__Envaux.env_from_summary in file \"ocaml-lsp-server/vendor/merlin/src/ocaml/typing/envaux.ml\", line 41, characters 24-50\nCalled from Ocaml_typing__Envaux.env_from_summary in file \"ocaml-lsp-server/vendor/merlin/src/ocaml/typing/envaux.ml\", line 41, characters 24-50\nCalled from Ocaml_typing__Envaux.env_from_summary in file \"ocaml-lsp-server/vendor/merlin/src/ocaml/typing/envaux.ml\", line 41, characters 24-50\nCalled from Ocaml_typing__Envaux.env_from_summary in file \"ocaml-lsp-server/vendor/merlin/src/ocaml/typing/envaux.ml\", line 41, characters 24-50\nCalled from Ocaml_typing__Envaux.env_from_summary in file \"ocaml-lsp-server/vendor/merlin/src/ocaml/typing/envaux.ml\", line 41, characters 24-50\nCalled from Ocaml_typing__Envaux.env_from_summary in file \"ocaml-lsp-server/vendor/merlin/src/ocaml/typing/envaux.ml\", line 41, characters 24-50\nCalled from Ocaml_typing__Envaux.env_from_summary in file \"ocaml-lsp-server/vendor/merlin/src/ocaml/typing/envaux.ml\", line 41, characters 24-50\nCalled from Ocaml_typing__Envaux.env_from_summary in file \"ocaml-lsp-server/vendor/merlin/src/ocaml/typing/envaux.ml\", line 41, characters 24-50\nCalled from Ocaml_typing__Envaux.env_from_summary in file \"ocaml-lsp-server/vendor/merlin/src/ocaml/typing/envaux.ml\", line 41, characters 24-50\nCalled from Ocaml_typing__Envaux.env_from_summary in file \"ocaml-lsp-server/vendor/merlin/src/ocaml/typing/envaux.ml\", line 41, characters 24-50\nCalled from Ocaml_typing__Envaux.env_from_summary in file \"ocaml-lsp-server/vendor/merlin/src/ocaml/typing/envaux.ml\", line 41, characters 24-50\nCalled from Ocaml_typing__Envaux.env_from_summary in file \"ocaml-lsp-server/vendor/merlin/src/ocaml/typing/envaux.ml\", line 53, characters 12-38\nCalled from Ocaml_typing__Envaux.env_from_summary in file \"ocaml-lsp-server/vendor/merlin/src/ocaml/typing/envaux.ml\", line 53, characters 12-38\nCalled from Ocaml_typing__Envaux.env_from_summary in file \"ocaml-lsp-server/vendor/merlin/src/ocaml/typing/envaux.ml\", line 53, characters 12-38\nCalled from Ocaml_typing__Envaux.env_from_summary in file \"ocaml-lsp-server/vendor/merlin/src/ocaml/typing/envaux.ml\", line 53, characters 12-38\nCalled from Ocaml_typing__Envaux.env_from_summary in file \"ocaml-lsp-server/vendor/merlin/src/ocaml/typing/envaux.ml\", line 53, characters 12-38\nCalled from Ocaml_typing__Envaux.env_from_summary in file \"ocaml-lsp-server/vendor/merlin/src/ocaml/typing/envaux.ml\", line 53, characters 12-38\nCalled from Ocaml_typing__Envaux.env_from_summary in file \"ocaml-lsp-server/vendor/merlin/src/ocaml/typing/envaux.ml\", line 53, characters 12-38\nCalled from Ocaml_typing__Envaux.env_from_summary in file \"ocaml-lsp-server/vendor/merlin/src/ocaml/typing/envaux.ml\", line 53, characters 12-38\nCalled from Ocaml_typing__Envaux.env_from_summary in file \"ocaml-lsp-server/vendor/merlin/src/ocaml/typing/envaux.ml\", line 53, characters 12-38\nCalled from Ocaml_typing__Envaux.env_from_summary in file \"ocaml-lsp-server/vendor/merlin/src/ocaml/typing/envaux.ml\", line 53, characters 12-38\nCalled from Ocaml_typing__Envaux.env_from_summary in file \"ocaml-lsp-server/vendor/merlin/src/ocaml/typing/envaux.ml\", line 53, characters 12-38\nCalled from Ocaml_typing__Envaux.env_from_summary in file \"ocaml-lsp-server/vendor/merlin/src/ocaml/typing/envaux.ml\", line 53, characters 12-38\nCalled from Ocaml_typing__Envaux.env_from_summary in file \"ocaml-lsp-server/vendor/merlin/src/ocaml/typing/envaux.ml\", line 53, characters 12-38\nCalled from Ocaml_typing__Envaux.env_from_summary in file \"ocaml-lsp-server/vendor/merlin/src/ocaml/typing/envaux.ml\", line 53, characters 12-38\nCalled from Ocaml_typing__Envaux.env_from_summary in file \"ocaml-lsp-server/vendor/merlin/src/ocaml/typing/envaux.ml\", line 53, characters 12-38\nCalled from Ocaml_typing__Envaux.env_from_summary in file \"ocaml-lsp-server/vendor/merlin/src/ocaml/typing/envaux.ml\", line 53, characters 12-38\nCalled from Ocaml_typing__Envaux.env_from_summary in file \"ocaml-lsp-server/vendor/merlin/src/ocaml/typing/envaux.ml\", line 53, characters 12-38\nCalled from Ocaml_typing__Envaux.env_from_summary in file \"ocaml-lsp-server/vendor/merlin/src/ocaml/typing/envaux.ml\", line 53, characters 12-38\nCalled from Ocaml_typing__Envaux.env_from_summary in file \"ocaml-lsp-server/vendor/merlin/src/ocaml/typing/envaux.ml\", line 53, characters 12-38\nCalled from Ocaml_typing__Envaux.env_from_summary in file \"ocaml-lsp-server/vendor/merlin/src/ocaml/typing/envaux.ml\", line 53, characters 12-38\nCalled from Ocaml_typing__Envaux.env_from_summary in file \"ocaml-lsp-server/vendor/merlin/src/ocaml/typing/envaux.ml\", line 53, characters 12-38\nCalled from Ocaml_typing__Envaux.env_from_summary in file \"ocaml-lsp-server/vendor/merlin/src/ocaml/typing/envaux.ml\", line 53, characters 12-38\nCalled from Ocaml_typing__Envaux.env_from_summary in file \"ocaml-lsp-server/vendor/merlin/src/ocaml/typing/envaux.ml\", line 53, characters 12-38\nCalled from Ocaml_typing__Envaux.env_from_summary in file \"ocaml-lsp-server/vendor/merlin/src/ocaml/typing/envaux.ml\", line 53, characters 12-38\nCalled from Ocaml_typing__Envaux.env_from_summary in file \"ocaml-lsp-server/vendor/merlin/src/ocaml/typing/envaux.ml\", line 53, characters 12-38\nCalled from Ocaml_typing__Envaux.env_from_summary in file \"ocaml-lsp-server/vendor/merlin/src/ocaml/typing/envaux.ml\", line 53, characters 12-38\nCalled from Ocaml_typing__Envaux.env_from_summary in file \"ocaml-lsp-server/vendor/merlin/src/ocaml/typing/envaux.ml\", line 53, characters 12-38\nCalled from Ocaml_typing__Env.env_of_only_summary in file \"ocaml-lsp-server/vendor/merlin/src/ocaml/typing/env.ml\", line 3590, characters 16-59\nCalled from Ocaml_typing__Envaux.env_of_only_summary in file \"ocaml-lsp-server/vendor/merlin/src/ocaml/typing/envaux.ml\" (inlined), line 100, characters 2-46\nCalled from Merlin_analysis__Locate.doc_from_uid in file \"ocaml-lsp-server/vendor/merlin/src/analysis/locate.ml\", line 911, characters 26-70\nCalled from Merlin_analysis__Locate.get_doc.from_uid in file \"ocaml-lsp-server/vendor/merlin/src/analysis/locate.ml\", line 946, characters 17-44\nCalled from Merlin_utils__Std.let_ref in file \"ocaml-lsp-server/vendor/merlin/src/utils/std.ml\", line 690, characters 8-12\nRe-raised at Merlin_utils__Std.let_ref in file \"ocaml-lsp-server/vendor/merlin/src/utils/std.ml\", line 692, characters 30-39\nCalled from Ocaml_lsp_server__Document.Merlin.doc_comment in file \"ocaml-lsp-server/src/document.ml\", line 265, characters 6-46\nCalled from Ocaml_lsp_server__Document.Merlin.type_enclosing.(fun) in file \"ocaml-lsp-server/src/document.ml\", line 284, characters 20-44\nCalled from Merlin_utils__Std.let_ref in file \"ocaml-lsp-server/vendor/merlin/src/utils/std.ml\", line 690, characters 8-12\nRe-raised at Merlin_utils__Std.let_ref in file \"ocaml-lsp-server/vendor/merlin/src/utils/std.ml\", line 692, characters 30-39\nCalled from Merlin_utils__Misc.try_finally in file \"ocaml-lsp-server/vendor/merlin/src/utils/misc.ml\", line 45, characters 8-15\nRe-raised at Merlin_utils__Misc.try_finally in file \"ocaml-lsp-server/vendor/merlin/src/utils/misc.ml\", line 62, characters 10-24\nCalled from Stdlib__Fun.protect in file \"fun.ml\", line 33, characters 8-15\nRe-raised at Stdlib__Fun.protect in file \"fun.ml\", line 38, characters 6-52\nCalled from Merlin_kernel__Mocaml.with_state in file \"ocaml-lsp-server/vendor/merlin/src/kernel/mocaml.ml\", line 18, characters 8-38\nRe-raised at Merlin_kernel__Mocaml.with_state in file \"ocaml-lsp-server/vendor/merlin/src/kernel/mocaml.ml\", line 20, characters 42-53\nCalled from Ocaml_lsp_server__Document.Merlin.with_pipeline.(fun) in file \"ocaml-lsp-server/src/document.ml\", line 224, characters 22-77\nCalled from Stdune__Exn_with_backtrace.try_with in file \"otherlibs/stdune/exn_with_backtrace.ml\", line 9, characters 8-12\nRe-raised at Stdune__Exn.raise_with_backtrace in file \"otherlibs/stdune/exn.ml\" (inlined), line 36, characters 27-56\nCalled from Stdune__Exn_with_backtrace.reraise in file \"otherlibs/stdune/exn_with_backtrace.ml\", line 18, characters 33-71\nCalled from Fiber__Core.O.(>>|).(fun) in file \"src/fiber/core.ml\", line 250, characters 36-41\nCalled from Fiber__Scheduler.exec in file \"src/fiber/scheduler.ml\", line 73, characters 8-11\nRe-raised at Stdune__Exn.raise_with_backtrace in file \"otherlibs/stdune/exn.ml\" (inlined), line 36, characters 27-56\nCalled from Stdune__Exn_with_backtrace.reraise in file \"otherlibs/stdune/exn_with_backtrace.ml\", line 18, characters 33-71\nCalled from Fiber__Scheduler.exec in file \"src/fiber/scheduler.ml\", line 73, characters 8-11\n"
}


[Error - 11:13:45 PM] Request textDocument/hover failed.
  Message: uncaught exception
  Code: -32603 
[object Object]

@rgrinberg
Copy link
Member Author

Thanks. I won't be able to debug this error myself. We'll just notify @voodoos that this issue exists.

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

ps-id: cce82426-de1a-4473-a3af-1a91ab987de5
@rgrinberg rgrinberg force-pushed the ps/rr/feature_melange___add_correct_stdlib_dir branch from 5ffdf8d to 42d15cd Compare November 11, 2022 23:47
@rgrinberg
Copy link
Member Author

Merging this is already an improvement. Let's keep working on it.

@rgrinberg rgrinberg merged commit 85df845 into main Nov 11, 2022
@Alizter Alizter deleted the ps/rr/feature_melange___add_correct_stdlib_dir branch November 12, 2022 15:10
jchavarri added a commit to jchavarri/dune that referenced this pull request Nov 12, 2022
* main: (33 commits)
  refactor(melange): move [lib_output_dir] (ocaml#6449)
  refactor: move dune.exe binary to _boot (ocaml#6308)
  test: split dune-project-meta/main.t (ocaml#6448)
  feature(melange): add correct stdlib dir (ocaml#6443)
  feature(melange): virtual libs (ocaml#6444)
  doc: rewrap dune-files + minor improvements (ocaml#6395)
  test: split several-packages.t (ocaml#6423)
  feature(melange): add alias field (ocaml#6401)
  refactor(melange): share visible_cmi branch (ocaml#6442)
  fix(ci): build @install to build dune (ocaml#6441)
  test: split no-installable-mode.t (ocaml#6436)
  test: split enabled_if-exec.t (ocaml#6439)
  test: ocamldep-multi-stanzas.t remove nesting (ocaml#6438)
  test: split duplicate-c-cxx-obj.t (ocaml#6437)
  test: split bad-alias-error.t (ocaml#6425)
  test: split duplicate-c-cxx.t (ocaml#6433)
  test: split intf-only.t (ocaml#6434)
  fix(coq): fix coqtop args being passed incorrectly
  test: split github1099.t (ocaml#6435)
  test: split re-export-exe.t (ocaml#6432)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants