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

Ppxlib.0.26.0 compatibility #400

Merged
merged 6 commits into from
Mar 29, 2023

Conversation

pitag-ha
Copy link
Contributor

This is a patch PR to make the PPX compatible with ppxlib.0.26.0 which has bumped the AST to 4.14/5.00.

This commit makes the ppx compatible with ppxlib.0.25.0.
@pitag-ha pitag-ha force-pushed the ppxlib.0.25.0-compatibility branch from bb80eca to 603fe9a Compare March 28, 2022 11:19
src/ppx/instrument.ml Outdated Show resolved Hide resolved
There are a couple of cmdliner functions used that are deprecated in
1.1.0, for example Term.info.
@pitag-ha
Copy link
Contributor Author

pitag-ha commented Apr 1, 2022

I've just added a cmdliner constraint, thinking that that might fix the CI given that the CI was failing exactly on the compiler versions on which cmdliner.1.1.0 can be installed. However, that hasn't fixed the CI. So I've reverted that.

So I've looked into the CI failures. There are three different kinds of failures:

The first one occurs on macos-latest and windows-latest and seems to concern ocamlformat. Is it possible that you only have an ocamlformat binary for linux, so on macos and windows, ocamlformat has to be installed via opam and therefore downgrades ppxlib? If so, that has always been a problem, hasn't it? Or is that new with this PR?

The second one is about

dune build ./not_excluded.bc --instrument-with bisect_ppx 2>&1

On old compilers, that outputs a line before printing the instrumented code, but on new compilers (>= 4.08) it doesn't. Has that always been the case? If not, I'm wondering if that might be somehow related to dune3.

The third one is the only worrying I'd say and I have no idea where it comes from:

$ echo "(lang dune 2.7)" > dune-project
$ cat > dune <<'EOF'
> (executables
> (names normal)
> (preprocess (pps bisect_ppx --bisect-sigterm)))
> EOF
$ cat > normal.ml <<'EOF'
> let () = ()
> EOF
$ dune exec ./normal.exe
$ bisect-ppx-report summary --verbose

used to yield 0% coverage and now it yields 100% (only on ocaml>=4.08). Do you happen to have some guess what might be happening there?

@pitag-ha
Copy link
Contributor Author

Hey @aantron, any chance that you'll have time to have a look at this soon? For me, it would be great if you could have a quick glimpse at the CI to let me know if it's my PR that's breaking the CI (for more details, see my questions in the last comment). Of course, if my PR is breaking it, I'll look into it in more detail to fix it.

@ceastlund
Copy link

Ping, @aantron? There are further changes to ppxlib that would require bisect_ppx fixes. We can't update further until this PR goes out. Hope you have time to look at it soon!

@quinn-dougherty
Copy link

quinn-dougherty commented Aug 31, 2022

used to yield 0% coverage and now it yields 100%

In local development (on #405 branch), I'm getting this as well in the diff tests, it's the only problem left with make test

@pitag-ha
Copy link
Contributor Author

pitag-ha commented Sep 1, 2022

Thanks for pointing that out @quinn-dougherty! I've just had a look and get the same diff (about coverage in test/sigterm/sigterm.t) on master. So maybe this PR can be merged, @aantron?

@roptat roptat mentioned this pull request Oct 10, 2022
@pitag-ha
Copy link
Contributor Author

Hey @aantron , there start to be more and more problems due to having this PR pending, see e.g. this issue and this comment. Would it be possible to merge this?

@barracuda156
Copy link

Just got this error:

File "src/ppx/instrument.mli", line 8, characters 11-57:
8 |    inherit Ppxlib.Ast_traverse.map_with_expansion_context
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: Unbound class type Ppxlib.Ast_traverse.map_with_expansion_context

@ceastlund
Copy link

It has been replaced by map_with_expansion_context_and_errors. It will take a little plumbing to propagate the errors the new way, but beyond that it does the same job.

@barracuda156
Copy link

@ceastlund Thank you! For now I just replaced it with the new name (OCaml is not an area of my expertise at all), but it failed a bit further on:

File "src/ppx/instrument.ml", line 1049, characters 12-14:
1049 |       match ce.pcl_desc with
                   ^^
Error: This expression has type Ppxlib__.Import.Ast.class_expr *
                                Ppxlib__.Location.Error.t list
       which is not a record type.

@ceastlund
Copy link

Ppxlib exports a With_errors submodule to help propagate those bindings via >>| and >>= operators. Someone familiar with that convention will have to update the code. It's not hard for someone who's used OCaml monads before, but if you're new to it it'll be involved.

@pitag-ha
Copy link
Contributor Author

Hi @barracuda156 and @ceastlund, given the problems that currently make it very difficult to have ppx_bisect actively maintained, there are already people who have added ppxlib.0.28.0 support on their own bisect_ppx fork. For example, @anmonteiro: https://github.com/anmonteiro/bisect_ppx/commit/cc442a08e3a2e0e18deb48f3a696076ac0986728. I think, there, possible errors aren't handled, but the code compiles.

I was originally thinking that it would be good, first to merge and release this PR to have a bisect_ppx version compatible with ppxlib 0.26.0 and 0.27.0 and then to merge and release a bisect_ppx PR adding 0.28.0 support. But at this point, I think we can just mix it all into one PR. I will see when I find time for that. In the meanwhile, feel free to open a PR, either to my branch or directly.

edwintorok added a commit to edwintorok/xs-opam that referenced this pull request Feb 13, 2023
Doesn't work with ppxlib 0.26.0, and other packages are forcing that as
a minimum.

Can be restored once aantron/bisect_ppx#400 is
solved upstream

Signed-off-by: Edwin Török <edwin.torok@cloud.com>
edwintorok added a commit to edwintorok/xs-opam that referenced this pull request Feb 13, 2023
Doesn't work with ppxlib 0.26.0, and other packages are forcing that as
a minimum.

Can be restored once aantron/bisect_ppx#400 is
solved upstream

Signed-off-by: Edwin Török <edwin.torok@cloud.com>
edwintorok added a commit to edwintorok/xs-opam that referenced this pull request Feb 13, 2023
Doesn't work with ppxlib 0.26.0, and other packages are forcing that as
a minimum.

Can be restored once aantron/bisect_ppx#400 is
solved upstream

Signed-off-by: Edwin Török <edwin.torok@cloud.com>
@pitag-ha
Copy link
Contributor Author

pitag-ha commented Mar 3, 2023

Hi @aantron, a kind reminder and update on this: This PR makes bisect_ppx compatible with the latest compilers. It's also the first step to making it compatible with the latest ppxlib again.

@aantron
Copy link
Owner

aantron commented Mar 3, 2023

@pitag-ha Thanks to you and everyone! I am working through bit rot issues in some of my other repos, and will reach Bisect_ppx in a few days. Then I will fix this and any other issues. Thanks for all the discussions, info, and links to date!

edwintorok added a commit to edwintorok/xs-opam that referenced this pull request Mar 7, 2023
Doesn't work with ppxlib 0.26.0, and other packages are forcing that as
a minimum.

Can be restored once aantron/bisect_ppx#400 is
solved upstream

Signed-off-by: Edwin Török <edwin.torok@cloud.com>
Copy link
Owner

@aantron aantron left a comment

Choose a reason for hiding this comment

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

Thanks for your work and patience!

This PR looks good. I see the same failures in CI (and locally). They are not related to this PR. I'll work to address them outside this PR.

@@ -22,7 +22,7 @@ depends: [
"cmdliner" {>= "1.0.0"}
"dune" {>= "2.7.0"}
"ocaml" {>= "4.03.0"}
"ppxlib" {>= "0.21.0"}
"ppxlib" {>= "0.26.0" & < "0.29.0"}
Copy link
Owner

Choose a reason for hiding this comment

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

FYI it appears that after this PR, the right upper constraint is < "0.28.0":

File "src/ppx/instrument.mli", line 8, characters 11-57:
8 |    inherit Ppxlib.Ast_traverse.map_with_expansion_context
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: Unbound class type Ppxlib.Ast_traverse.map_with_expansion_context

However, I'll probably try to port Bisect to 0.28.0 rather than add the constraint. @pitag-ha, do you know if people need a release of Bisect that is compatible with ppxlib 0.26.0 and 0.27.0, at this point?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

FYI it appears that after this PR, the right upper constraint is < "0.28.0":

Good catch, thanks!

@pitag-ha, do you know if people need a release of Bisect that is compatible with ppxlib 0.26.0 and 0.27.0, at this point?

I think ppxlib >= 0.28.0 support directly should be enough.

@aantron
Copy link
Owner

aantron commented Mar 29, 2023

@pitag-ha, as the ppxlib maintainer, could you comment on the correctness of patches like https://github.com/anmonteiro/bisect_ppx/commit/cc442a08e3a2e0e18deb48f3a696076ac0986728 for 0.28.0? I am ready to review them from the Bisect point of view and cherry-pick them.

@pitag-ha
Copy link
Contributor Author

pitag-ha commented Apr 8, 2023

@pitag-ha, as the ppxlib maintainer, could you comment on the correctness of patches like https://github.com/anmonteiro/bisect_ppx/commit/cc442a08e3a2e0e18deb48f3a696076ac0986728 for 0.28.0?

Thanks for reaching out on that! https://github.com/anmonteiro/bisect_ppx/commit/cc442a08e3a2e0e18deb48f3a696076ac0986728 doesn't handle the errors, but drops them. So that was good to have something that would build. However for something we want to merge and release, we should really handle the errors instead of dropping them. You can use the Ppxlib.With_errors module to comfortably propagate the errors.

E.g. instead of

method! expression ctxt e =
   (...)
   let cstr, _locs = (self#class_structure ctxt c) in
   Exp.object_ ~loc ~attrs cstr

you can use the With_error's map:

method! expression ctxt e =
   (...)
   self#class_structure ctxt c >>| fun cstr -> Exp.object_ ~loc ~attrs cstr

And then, at the level of the structure node, you can embed all errors, i.e. instead of

let instrumented_ast, _errs = super#structure ctxt ast in
let runtime_initialization =
  Generated_code.runtime_initialization points path in
runtime_initialization @ instrumented_ast

something along the lines of

let instrumented_ast, errs = super#structure ctxt ast in
let errs =
   List.map (fun error ->
      Ast_builder.Default.pstr_extension
        ~loc:(Location.Error.get_location error)
        (Location.Error.to_extension error)
        []) errs
in
let runtime_initialization =
  Generated_code.runtime_initialization points path in
errs @ runtime_initialization @ instrumented_ast

@pitag-ha
Copy link
Contributor Author

pitag-ha commented Apr 8, 2023

Let us know if you have any questions about that!

psafont pushed a commit to edwintorok/xs-opam that referenced this pull request Jun 12, 2023
Doesn't work with ppxlib 0.26.0, and other packages are forcing that as
a minimum.

Can be restored once aantron/bisect_ppx#400 is
solved upstream

Signed-off-by: Edwin Török <edwin.torok@cloud.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.

None yet

6 participants