-
Notifications
You must be signed in to change notification settings - Fork 409
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
fix(melange): run melc ppx with merlin #6476
Conversation
Signed-off-by: Javier Chavarri <javier.chavarri@gmail.com>
No idea. Anyway printing the .merlin is just for debugging so don't bother thinking too hard.
It should be always added for emit stanzas and for libraries that are "melange only". See the condition we have for object directories already. |
src/dune_rules/merlin.ml
Outdated
make_directive "FLG" | ||
(Sexp.List [ Atom (Pp_kind.to_flag flag); Atom args ]) | ||
(Sexp.List | ||
[ Atom (Pp_kind.to_flag Ppx); Atom "melc -as-ppx -bs-jsx 3" ]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't the melange ppx come first?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't the merlin syntax something like FLG -ppx melc -as-ppx -bs-jsx 3
? The first atom is what renders the -ppx
flag next to FLG
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should make a note to remove the -bs-jsx-3
stuff eventually. Here's my rough plan:
- move the React JSX PPX out of the compiler (Add react-jsx-ppx as a separate package melange-re/melange#396)
- distribute this new package with melange
- nudge users to change to
(preprocess (pps reactjs_jsx_ppx))
rather than(flags :standard -bs-jsx 3)
- Delete this line in the merlin generated config
src/dune_rules/merlin.ml
Outdated
@@ -414,7 +435,7 @@ module Unprocessed = struct | |||
Path.Set.union src_dirs | |||
(Path.Set.of_list_map ~f:Path.source more_src_dirs) | |||
in | |||
{ Processed.stdlib_dir; src_dirs; obj_dirs; flags; extensions } | |||
{ Processed.stdlib_dir; src_dirs; obj_dirs; flags; extensions; mode } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Processed shouldn't include the mode. The flags should already contain what's needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I spent some time trying to implement this, but I don't understand how it is possible.
flags
includes only the compiler flags, and it's dumped in a single FLG
directive here:
Lines 92 to 95 in 75d5b40
| flags -> | |
[ make_directive "FLG" | |
(Sexp.List (List.map ~f:(fun s -> Sexp.Atom s) flags)) | |
] |
We want melange FLG
to be a separate directive. I can replace mode
field in processed with something like melange_ppx_flag
of type string list option
or similar. In any case, something else needs to be passed to Processed
in order to add this new directive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does it need to be a separate FLG
directive? We manage to put all the other flags in one directive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so, there were two separate FLG
directives already.
One for the OCaml flags:
Lines 93 to 95 in 0280c9e
[ make_directive "FLG" | |
(Sexp.List (List.map ~f:(fun s -> Sexp.Atom s) flags)) | |
] |
Another for the pp
(or ppx
) flags:
Lines 100 to 102 in 0280c9e
make_directive "FLG" | |
(Sexp.List [ Atom (Pp_kind.to_flag flag); Atom args ]) | |
:: flags |
I don't understand how to inject the melc
ppx in either of those. The first one (afaiu) is to tell Merlin which flags are used for the OCaml compiler. The second one is for user-defined ppxs. We need a new directive to tell Merlin "you also need to run this ppx", as it's a separate process: it's not part of the compiler flags, nor a ppx that is user defined.
Do you or @anmonteiro see a way to "blend" it with any of the two other existing directives?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rgrinberg Any thoughts on the above? Considering there were already two FLG
directives, should melc
ppx be made part of any of them or could it exist on its own? If anything, it should be part of the second, but I don't think it's possible at the moment as it's not a user defined ppx (so can't be compiled with ppx driver).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is hacky but it looks good enough for now. A few points:
- We shouldn't hard code the path of
melc
. We should use the absolute path that was resolved by dune - We should make sure that
melc
is actually built if it's defined in the same workspace.
In any case, if @anmonteiro is fine with this temporary hack then we can merge it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree we should fix 1. & 2. before merging.
What's the temporary hack? the 2 FLG
directives?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I would expect all these melange ppx's to be ported to ppxlib and enabled explicitly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's the goal for the ReactJS PPX, as highlighted in #6476 (comment).
I don't yet have a clear plan for the builtin PPX, which currently is very tightly integrated into the compiler.
* main: test(melange): demonstrate error in melange compilation trying to build @ALL (ocaml#6485) chore(nix): make it faster to get melange (ocaml#6347) refactor: status db style tweaks (ocaml#6478) fix: improve error message for status db (ocaml#6479) refactor: remove unused [flags] parameter (ocaml#6480) refactor(ctypes): remove pesky aliases (ocaml#6482) chore: tweak `hacking.rst` following `dune.exe` move to _boot (ocaml#6484) feature(coq): automatic detection of native chore(coq): bump Coq lang to 0.7 test: disable formatting for a single dune file (ocaml#6465) refactor: clean up module compilation (ocaml#6461) doc: add button to copy code blocks in Dune manual (ocaml#6428) refactor: deforest a set conversion (ocaml#6473) refactor: remove temporary map used for sorting (ocaml#6472) fix(melange): handle include_subdirs unqualified (ocaml#6475)
Signed-off-by: Javier Chavarri <javier.chavarri@gmail.com>
I meant something else, rather how to pass compiler flags to melange |
I tested this change with vscode editor and it seems it doesn't work, I started getting errors of the kind I am not sure how to fix this, so I reverted the change in 993c0ff. |
|
* main: test: formatting of alternative dune files (ocaml#6567) refactor: remove Modules.is_empty (ocaml#6564) refactor: module kinds (ocaml#6562) refactor(coq): resolve lack of coqc properly Cache file contents in action builder by name. (ocaml#6555) fix: re-enable dune on older macos sdk's (ocaml#6515) fix: do not hide lib interface module (ocaml#6549) test: remove pkg-config output for reproducibility (ocaml#6543) melange: add test for ocaml flags (ocaml#6548) fix: improve virtual library error messages test: virtual library and impl locations test: alias module regression (ocaml#6544) refactor(merlin): dump config sub command (ocaml#6547)
Signed-off-by: Javier Chavarri <javier.chavarri@gmail.com>
Signed-off-by: Javier Chavarri <javier.chavarri@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Do you plan to fix the remaining TODO in Merlin.to_dot_merlin
?
Signed-off-by: Javier Chavarri <javier.chavarri@gmail.com>
Fixed the todo and verified the output in test in |
src/dune_rules/merlin.ml
Outdated
let () = | ||
match mode with | ||
| `Ocaml -> () | ||
| `Melange -> print "# FLG -ppx melc -as-ppx -bs-jsx 3\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can use the same machinery above, with quote_for_dot_merlin
. See my comment in the test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check 5c34973.
Signed-off-by: Javier Chavarri <javier.chavarri@gmail.com>
Note that user ppx's are provided as absolute paths to merlin for exactly this reason. Merlin doesn't use the ocaml toolchain (it vendors what it needs), so there's no need to worry about that. Okay, we can skip the dependency on melc for now because we don't handle ppx cleanly either. |
src/dune_rules/merlin.ml
Outdated
@@ -68,7 +69,9 @@ module Processed = struct | |||
|
|||
let serialize_path = Path.to_absolute_filename | |||
|
|||
let to_sexp ~pp { stdlib_dir; obj_dirs; src_dirs; flags; extensions } = | |||
let melc_ppx_flg = "melc -as-ppx -bs-jsx 3" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the offending line. It should be using serialize_path
to encode melc
and using the melc
path we resolved to build the actual library
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I'm pretty sure you can provide flags as separate atoms. So that we don't have to rely on merlin to parse anything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be using
serialize_path
to encodemelc
and using themelc
path we resolved to build the actual library
@rgrinberg Could you help me understand this part, please? The path that is resolved in merlin points to the melc stdlib e.g. _opam/lib/melange
, assuming you refer to this code
Line 398 in 5a09827
| `Melange -> Melange_binary.where sctx ~dir |
But the path here should be to the melc
command, which would be in e.g. _opam/bin/melc
. How are both related? Or am I misunderstanding?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, keep asking questions if something is unclear. The gist of the issue is: we should not use any relative paths in the .Merlin directive. All paths should be absolute. So, library paths, stdlib paths, preprocessors, etc should all be fully resolved.
The current code violates this with the way it refers to the melc binary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for clarifying. I tried a fix in c6e8bd6.
Signed-off-by: Javier Chavarri <javier.chavarri@gmail.com>
Signed-off-by: Javier Chavarri <javier.chavarri@gmail.com>
Signed-off-by: Javier Chavarri <javier.chavarri@gmail.com>
Signed-off-by: Javier Chavarri <javier.chavarri@gmail.com>
@rgrinberg in f698bd6 I lifted the calculation of melc flags to the |
src/dune_rules/merlin.ml
Outdated
, match acc_melc_flags with | ||
| Some _ -> acc_melc_flags | ||
| None -> melc_flags )) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure about this. Should it rather be melc_flags
directly? (i.e. no accumulation needed)
I guess the missing part is: what is the relationship between the paths
passed as param to print_generic_dot_merlin
?
a8fcf19
to
97c0115
Compare
Signed-off-by: Javier Chavarri <javier.chavarri@gmail.com>
Signed-off-by: Javier Chavarri <javier.chavarri@gmail.com>
According to the tests, |
Signed-off-by: Javier Chavarri <javier.chavarri@gmail.com>
@rgrinberg Fixed in dadc896. I moved the definition of |
Signed-off-by: Javier Chavarri <javier.chavarri@gmail.com>
I have been testing vscode-ocaml extension using this PR, but unfortunately something regressed with the most recent changes and now it does not work at all. I see errors in lsp log of the kind:
This used to work at the beginning of the PR, when passing whole command in quotes, e.g. |
Not that I know. Let's just leave it as a single form for now. |
Signed-off-by: Javier Chavarri <javier.chavarri@gmail.com>
Signed-off-by: Javier Chavarri <javier.chavarri@gmail.com>
updated in 8bacbb7 to pass single string. Confirmed it works with editor integration. |
Fixes merlin support when using the melange ppx Signed-off-by: Javier Chavarri <javier.chavarri@gmail.com>
* main: (54 commits) doc: how we write `to_dyn` and `equal` (ocaml#6621) test(cache): test output of man pages test: dune utop for (subdir ..) (ocaml#6629) refactor: improve style of utop rules (ocaml#6628) test: depend on utop (ocaml#6627) refactor(stdune): Add Appendable_list.cons (ocaml#6624) doc: tighten wording in README.md test: add a repro case for ocaml#6607 (ocaml#6612) doc: cleanup status badges in README.md (ocaml#6618) doc(README): rewrap paragraphs and cleanup links coq: more resilient config query fix: link time code gen (ocaml#6606) fix(melange): run melc ppx with merlin (ocaml#6476) feature(melange): add compile_flags (ocaml#6569) refactor: move `modules: Modules.t` from `Dune_package.Lib` to `Lib_info` (ocaml#6605) Set CLICOLOR_FORCE=0 (ocaml#6608) fix: declare deps for ccomp detection (ocaml#6610) refactor: assume Cmdliner.Arg.conv is abstract (ocaml#6609) refactor: gen_rules pattern matching (ocaml#6604) Add CI for MSVC using dkml-workflows (ocaml#6540) ...
Fixes #6456.
A couple of questions:
to_dot_merlin
. It seems allFLG
directives are commented? I don't understand what's the purpose-bs-jsx 3
should be conditionally added, based onflags
field value onlibrary
ormelange.emit
stanzas.