8000 fix: ppx and reason bug by Alizter · Pull Request #7932 · ocaml/dune · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: ppx and reason bug #7932

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

Merged
merged 3 commits into from
Jul 23, 2023
Merged

Conversation

Alizter
Copy link
Collaborator
@Alizter Alizter commented Jun 10, 2023

Fix #7930

ppx needs the original source of a file even if it is a dialect. This was missing causing the sandboxed version to error. We add the original source file as a hidden dependency in the ppx action.

I also found that inline_tests was not using the correct dialect source, which can be seen in my commits as I tried to remove my original reason dependency. I therefore have also submitted a fix for that.

  • changelog

@Alizter

This comment was marked as outdated.

@Alizter Alizter force-pushed the ps/branch/test__repro__7930 branch from f22874b to 7db5af3 Compare June 10, 2023 12:45
@Alizter Alizter changed the title test: repro #7930 fix: ppx and reason bug Jun 10, 2023
@Alizter Alizter marked this pull request as ready for review June 10, 2023 12:47
@Alizter Alizter force-pushed the ps/branch/test__repro__7930 branch from 7db5af3 to a453b58 Compare June 10, 2023 12:48
@Alizter Alizter requested a review from rgrinberg June 10, 2023 12:49
@Alizter Alizter force-pushed the ps/branch/test__repro__7930 branch from a453b58 to e591a10 Compare June 10, 2023 15:39
@Alizter Alizter requested review from anmonteiro and rgrinberg June 10, 2023 16:58
@Alizter Alizter force-pushed the ps/branch/test__repro__7930 branch 3 times, most recently from e9db434 to 2553102 Compare June 11, 2023 11:05
@Alizter Alizter added this to the 3.9.0 milestone Jun 16, 2023
@Alizter Alizter force-pushed the ps/branch/test__repro__7930 branch from 2553102 to a9cc4bb Compare June 16, 2023 18:54
@emillon emillon removed this from the 3.9.0 milestone Jun 19, 2023
@emillon
Copy link
Collaborator
emillon commented Jun 22, 2023

I reproduced that without reason so I'll push a test which does not rely on a fake refmt.

@emillon emillon force-pushed the ps/branch/test__repro__7930 branch from a9cc4bb to ad3c6aa Compare June 22, 2023 08:49
@emillon
Copy link
Collaborator
emillon commented Jun 22, 2023

@Alizter I rebased and pushed a fix. Let me know what you think. This will need a changelog entry. Thanks!

@rgrinberg
Copy link
Member

@emillon this PR needs review from me and @anmonteiro still

@emillon
Copy link
Collaborator
emillon commented Jun 22, 2023

sure, to be clear I was just addressing the test

@Alizter
Copy link
Collaborator Author
Alizter commented Jun 22, 2023

@emillon It already has a changelog entry, is something missing?

@emillon
Copy link
Collaborator
emillon commented Jun 22, 2023

@emillon It already has a changelog entry, is something missing?

ugh, coffee for me I guess. sorry!

@@ -710,6 +710,10 @@ let pp_one_module sctx ~lib_name ~scope ~preprocessor_deps
; Path (Path.build dst)
; Command.Ml_kind.ppx_driver_flag ml_kind
; Dep (Path.build src)
; Hidden_deps
Copy link
Collaborator
@anmonteiro anmonteiro Jun 22, 2023

Choose a reason for hiding this comment

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

I don't understand why this is needed.

IIUC, the pipeline looks something like:

.re -> (dialect) .re.ml -> (pps) .pp.ml

So isn't the original source file already a (transitive) dependency of the pps action?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

But sandboxing does not take the transitive closure, onoy the specified deoendencies. Thats why its important to always fully specify them.

@Alizter Alizter force-pushed the ps/branch/test__repro__7930 branch from ad3c6aa to 2485dc3 Compare July 5, 2023 22:39
@Alizter
Copy link
Collaborator Author
Alizter commented Jul 5, 2023

@rgrinberg I've dropped the commit modifying the targets in inline_tests.ml. As you can see this creates an exception. I can fix it by tweaking the source files:

diff --git a/src/dune_rules/inline_tests.ml b/src/dune_rules/inline_tests.ml
index 77a92acc2..941900c09 100644
--- a/src/dune_rules/inline_tests.ml
+++ b/src/dune_rules/inline_tests.ml
@@ -285,7 +285,10 @@ include Sub_system.Register_end_point (struct
       in
       List.concat l
     in
-    let source_files = List.concat_map source_modules ~f:Module.sources in
+    let source_files =
+      List.concat_map source_modules ~f:(fun module_ ->
+          Module.ml_source module_ |> Module.sources)
+    in
     Memo.parallel_iter_set
       (module Mode_conf.Set)
       info.modes
diff --git a/test/blackbox-tests/test-cases/reason-expect.t/run.t b/test/blackbox-tests/test-cases/reason-expect.t/run.t
index d1c599f90..f694d3809 100644
--- a/test/blackbox-tests/test-cases/reason-expect.t/run.t
+++ b/test/blackbox-tests/test-cases/reason-expect.t/run.t
@@ -20,18 +20,7 @@ syntax and ppx_expect break at dune lang 3.3 due to the sandboxing of ppx.
   > (lang dune 3.9)
   > EOF
   $ dune test
-  File "dune", line 3, characters 1-15:
-  3 |  (inline_tests)
-       ^^^^^^^^^^^^^^
-  Fatal error: exception Sys_error("$TESTCASE_ROOT/_build/.sandbox/31552d8346d4edb1acb27f906d1a4b1b/default/./test.re.ml: No such file or directory")
-  Raised by primitive operation at Stdlib.open_in_gen in file "stdlib.ml", line 405, characters 28-54
-  Called from Stdio__In_channel.with_file in file "src/in_channel.ml", line 18, characters 45-66
-  Called from Stdio__In_channel.read_all in file "src/in_channel.ml" (inlined), line 86, characters 21-49
-  Called from Ppx_expect_evaluator.create_group in file "evaluator/ppx_expect_evaluator.ml", line 113, characters 22-69
-  Called from Base__List.count_map in file "src/list.ml", line 462, characters 13-17
-  Called from Ppx_expect_evaluator.evaluate_tests in file "evaluator/ppx_expect_evaluator.ml", line 207, characters 2-85
-  Called from Stdlib__List.map in file "list.ml", line 92, characters 20-23
-  Called from Stdlib__List.map in file "list.ml", line 92, characters 32-39
-  Called from Ppx_inline_test_lib__Runtime.exit in file "runtime-lib/runtime.ml", line 646, characters 2-49
-  Called from Dune__exe__Inline_test_runner_test in file ".test.inline-tests/inline_test_runner_test.ml-gen", line 1, characters 9-44
+  File "test.re.ml", line 1, characters 0-0:
+  Error: Files _build/default/test.re.ml and
+  _build/default/test.re.ml.corrected differ.
   [1]

@Alizter Alizter force-pushed the ps/branch/test__repro__7930 branch 2 times, most recently from 3ce0b45 to be63d7f Compare July 12, 2023 14:25
@rgrinberg
Copy link
Member

I don't understand how this diff is supposed to work:

+  File "test.re.ml", line 1, characters 0-0:
+  Error: Files _build/default/test.re.ml and
+  _build/default/test.re.ml.corrected differ.

We have a source file test.re, and test.re.ml is supposed to contain the correction for a generated file?! Why would we offer a promotion for a generated file?

@rgrinberg
Copy link
Member

Okay, the issue is that our clone of refmt is bugged because it doesn't output line directives. Unfortunately, inserting the line directive to correct the filename breaks ppx_expect. No idea what's happening but I pushed the commit that demonstrates the issue.

Anyway, we can investigate this later. Just remove the copy-pasting between the refmt's and this is good to go

@Alizter
Copy link
Collaborator Author
Alizter commented Jul 16, 2023

@rgrinberg Right, if you look at the commits, the last one I pushed fixes inline_tests. Before I get the same error as you did.

@rgrinberg
Copy link
Member

It's not the same error. The previous error was expected because the refmt error is broken. The subsequent is because ppx_expect doesn't understand directive for some reason

@Alizter Alizter force-pushed the ps/branch/test__repro__7930 branch from 4e90f16 to e96994e Compare July 16, 2023 15:15
@Alizter
Copy link
Collaborator Author
Alizter commented Jul 16, 2023

@rgrinberg I've consolidated the fake refmt and squashed (fixedup) your commit.

@Alizter
Copy link
Collaborator Author
Alizter commented Jul 16, 2023

@rgrinberg Actually the backtrace in the bug you found isn't repro. My machine differs from the CI for some reason. Maybe we should leave the removing of the refmt dep to another PR and fix this inline tests issue?

@rgrinberg
Copy link
Member

We can't have the test suite depend on refmt

@Alizter
Copy link
Collaborator Author
Alizter commented Jul 16, 2023

@rgrinberg Alright, shall I just scrub the backtrace then?

@rgrinberg
Copy link
Member

The back trace is easily fixable we just need to remove the locations.

That's not the point though, there's clearly something wrong with this fake refmt if it's making ppx_expect fail. We should fix it or it will break the test suite in other mysterious ways.

@Alizter Alizter force-pushed the ps/branch/test__repro__7930 branch from e96994e to cd12cee Compare July 16, 2023 16:21
@rgrinberg
Copy link
Member

If that's the best we can do, then it's acceptable.

@anmonteiro can you take a look at refmt? Perhaps I'm missing something obvious.

@Alizter
Copy link
Collaborator Author
Alizter commented Jul 16, 2023

@rgrinberg You added this line to the fake refmt:

  output_string out (sprintf "# 1 %S\n" source);

That was intentional right?

@rgrinberg
Copy link
Member

Yes. Without this, how would ppx_expect find the original source?

Alizter added 3 commits July 16, 2023 18:57
Signed-off-by: Ali Caglayan <alizter@gmail.com>
Signed-off-by: Ali Caglayan <alizter@gmail.com>
This highlights a bug with inline_tests not respecting the dialect
sources correctly.

Signed-off-by: Ali Caglayan <alizter@gmail.com>
@Alizter Alizter force-pushed the ps/branch/test__repro__7930 branch from cd12cee to 8e81b06 Compare July 16, 2023 16:57
@anmonteiro
Copy link
Collaborator

What’s the refmt problem? Btw Reason can’t parse line directives, not sure if that’s related.

@rgrinberg
Copy link
Member

We have this fake refmt binary that we use for the tests. There's a problem with it's not working with ppx_expect for some reason (see exception). Perhaps you know what the reason is?

refmt doesn't need to understand line directives, it just needs to produce a parsetree with the correct locations. I think it does so with --binary which is what dune uses.

@anmonteiro
Copy link
Collaborator

This looks like a ppx_expect bug rather than Reason? https://github.com/search?q=%22pos+%2B+len+past+end%22&type=code

@anmonteiro
Copy link
Collaborator

My guess: the ppx_expect evaluator is trying to read the new file expecting the old file contents length?

@Alizter
Copy link
Collaborator Author
Alizter commented Jul 17, 2023

Hmm I don't know how to progress with this now.

@rgrinberg rgrinberg added this to the 3.10.0 milestone Jul 23, 2023
@rgrinberg rgrinberg merged commit 8fe927e into ocaml:main Jul 23, 2023
emillon added a commit to emillon/opam-repository that referenced this pull request Jul 28, 2023
CHANGES:

- Add `dune show rules` as alias of the `dune rules` command. (ocaml/dune#8000, @Alizter)

- Fix `%{deps}` to expand properly in `(cat ...)` when containing 2 or more
  items. (ocaml/dune#8196, @Alizter)

- Add `dune show installed-libraries` as an alias of the `dune
  installed-libraries` command. (ocaml/dune#8135, @Alizter)

- Fix the `severity` of error messages sent over RPC which was missing. (ocaml/dune#8193,
  @Alizter)

- Add `dune build --dump-gc-stats FILE` argument to dump garbage collection
  stats to a named file. (ocaml/dune#8072, @Alizter)

- Fix bug with ppx and Reason syntax due to missing dependency in sandboxed
  action (ocaml/dune#7932, fixes ocaml/dune#7930, @Alizter)

- Add `dune describe package-entries` to print all package entries (ocaml/dune#7480,
  @moyodiallo)

- Improve `dune describe external-lib-deps` by adding the internal dependencies
  for more information. (ocaml/dune#7478, @moyodiallo)

- Re-enable background file digests on Windows. The files are now open in a way
  that prevents race condition around deletion. (ocaml/dune#8262, fixes ocaml/dune#8268, @emillon)
emillon added a commit to emillon/opam-repository that referenced this pull request Jul 31, 2023
CHANGES:

- Add `dune show rules` as alias of the `dune rules` command. (ocaml/dune#8000, @Alizter)

- Fix `%{deps}` to expand properly in `(cat ...)` when containing 2 or more
  items. (ocaml/dune#8196, @Alizter)

- Add `dune show installed-libraries` as an alias of the `dune
  installed-libraries` command. (ocaml/dune#8135, @Alizter)

- Fix the `severity` of error messages sent over RPC which was missing. (ocaml/dune#8193,
  @Alizter)

- Add `dune build --dump-gc-stats FILE` argument to dump garbage collection
  stats to a named file. (ocaml/dune#8072, @Alizter)

- Fix bug with ppx and Reason syntax due to missing dependency in sandboxed
  action (ocaml/dune#7932, fixes ocaml/dune#7930, @Alizter)

- Add `dune describe package-entries` to print all package entries (ocaml/dune#7480,
  @moyodiallo)

- Improve `dune describe external-lib-deps` by adding the internal dependencies
  for more information. (ocaml/dune#7478, @moyodiallo)

- Re-enable background file digests on Windows. The files are now open in a way
  that prevents race condition around deletion. (ocaml/dune#8262, fixes ocaml/dune#8268, @emillon)
nberth pushed a commit to nberth/opam-repository that referenced this pull request Jun 18, 2024
CHANGES:

- Add `dune show rules` as alias of the `dune rules` command. (ocaml/dune#8000, @Alizter)

- Fix `%{deps}` to expand properly in `(cat ...)` when containing 2 or more
  items. (ocaml/dune#8196, @Alizter)

- Add `dune show installed-libraries` as an alias of the `dune
  installed-libraries` command. (ocaml/dune#8135, @Alizter)

- Fix the `severity` of error messages sent over RPC which was missing. (ocaml/dune#8193,
  @Alizter)

- Add `dune build --dump-gc-stats FILE` argument to dump garbage collection
  stats to a named file. (ocaml/dune#8072, @Alizter)

- Fix bug with ppx and Reason syntax due to missing dependency in sandboxed
  action (ocaml/dune#7932, fixes ocaml/dune#7930, @Alizter)

- Add `dune describe package-entries` to print all package entries (ocaml/dune#7480,
  @moyodiallo)

- Improve `dune describe external-lib-deps` by adding the internal dependencies
  for more information. (ocaml/dune#7478, @moyodiallo)

- Re-enable background file digests on Windows. The files are now open in a way
  that prevents race condition around deletion. (ocaml/dune#8262, fixes ocaml/dune#8268, @emillon)
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.

ppx_expect + reason is broken after dune lang 3.2
4 participants
0