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

Add Extension.V3.declare_with_path_arg #431

Merged
merged 11 commits into from
Jul 5, 2023

Conversation

ELLIOTTCABLE
Copy link
Contributor

Seems like an oversight in the new API; came up in this Discuss thread.

make builds; make test passes. However, make test passes no matter what I do. Can't verify that my added test actually passes — but it's a trivial addition, it should be "if it compiles, it works." 🙈

(Could use a CONTRIBUTING section in the README with instructions as to how to build/test/PR, etc. hahaha.)

Copy link
Collaborator

@panglesd panglesd 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 the PR!

However, make test passes no matter what I do

This is I think because the test you modify is only enabled in OCaml between 4.08 and 4.11 (included). So if the OCaml version in your switch is outside these bounds, the test is not run.

However, the CI ran the test. You need to register the new transformation to another extension node.

test/driver/transformations/test.ml Outdated Show resolved Hide resolved
test/driver/transformations/test.ml Outdated Show resolved Hide resolved
test/driver/transformations/test.ml Outdated Show resolved Hide resolved
test/driver/transformations/test.ml Outdated Show resolved Hide resolved
test/driver/transformations/test.ml Outdated Show resolved Hide resolved
@pitag-ha
Copy link
Member

Thanks for contributing, it's always nice to see new people on the repo!

What's the use case you have in mind? In V3, the module path the extension point lives in can be accessed by the rewriter via the expansion context, see e.g. the tests about code_path: https://github.com/ocaml-ppx/ppxlib/blob/main/test/code_path/test.ml . Have you seen that already?

@panglesd
Copy link
Collaborator

I was also puzzled by the fact that "with_path_arg" is not part of code_path, but it is actually something different, about only the name of the extension point: for instance [%ext_name.Additional.Path] has path_arg Additional.Path.

@pitag-ha
Copy link
Member

about only the name of the extension point: for instance [%ext_name.Additional.Path] has path_arg Additional.Path.

Yes, but what's the use case for that? I'm assuming that the usual/intended use case for it in "V1" was to be able to pass in the module path manually given that the rewriter didn't have access to what we now call expansion context. I'm wondering what the use case of manually passing in a path argument is now that we do have the accurate code_path via the expansion context.

@ELLIOTTCABLE
Copy link
Contributor Author

ELLIOTTCABLE commented Jun 24, 2023

Er, the "path arg" is, imho, badly named, because code-path now exists — I think out of two possible meanings of the word 'path', the current Code_path module is a much more obvious meaning.

By contrast, the "path_arg" was a explicit module path argument, in the sense of "argument" meaning "provided by the user" — completely unrelated to Code_path, which cannot (and should not be) affected by the user.

e.g. in this example, Code_path basically encodes Abc.Xyz, whereas path_arg is explicitly Foo.Bar:

module Abc = struct
   module Xyz = struct
      let%ext.Foo.Bar = (* ... *)
   end
end

fwiw, I think now would be a fantastic time to rename the path_arg, a change I can make in this PR if y'all agree — V3's API, thanks to the omission of this feature thus far, can use a different naming convention that doesn't clash so confusingly with the new Code_path.

wdyt?


As for use-cases, who knows what all someone might overload that explicit "argument" to mean; but my usage (in ppx_trace) is effectively identical to that of ppx_let; e.g. their docs:

Alternatively, the extension can use values from a Let_syntax module other than the one in scope. If you write %map.A.B.C instead of %map, the expansion will use A.B.C.Let_syntax.Let_syntax.map instead of Let_syntax.map (and similarly for all extension points).

(This is a fantastic feature, and the primary reason we're still using ppx_let at @ahrefs over more "modern" syntactic monadic binds in recent OCaml versions — if you genuinely need to operate with a few monads interleaved simultaneously in scope, something like let%bind.Lwt and let%bind.Error is much, much clearer than trying to memorize the difference between let*, let+, and let% or whatnot.)

@pitag-ha
Copy link
Member

Thanks for explaining the use case, sounds all good!

fwiw, I think now would be a fantastic time to rename the path_arg, a change I can make in this PR if y'all agree

Sounds good as well. What name would you use?

Btw, about the CI failures:

  • Could you add a changelog entry (i.e. an entry to CHANGES.md)? We forgot to add an unreleased section after the 0.30.0 release. So I think now the easiest would be if you could add that unreleased section on top of Changes.md and add your entry to that section. Does that sound good?
  • We use DCO, so you need to sign all your commits. You can do that at the very end if that's more convenient.
  • The ocaml-ci failure is unrelated to your PR.

@ELLIOTTCABLE
Copy link
Contributor Author

Okay, I chose, simply, "additional_arg" — although, yes, only a module-path will technically be accepted in this position, that's actually somewhat orthogonal?

Let me know if that naming pleases you. I also added notes to the now-deprecated interfaces so people can find the new one.

I forgot to ask — is there an appropriate test file that does get run on current versions? Somewhere better I can add tests for this?

@ELLIOTTCABLE ELLIOTTCABLE changed the title Add Extension.V3.declare_with_path_arg Add Extension.V3.declare_with_additional_arg (mirroring declare_with_path_arg) Jun 27, 2023
@panglesd
Copy link
Collaborator

Let me know if that naming pleases you. I also added notes to the now-deprecated interfaces so people can find the new one.

To be honest, I think it has more disadvantages than advantages:

  • It makes us have two names for the same concept
  • additional_args is much less specific than path_arg, and the argument can only be a path (and additional_path_arg is too long!)

So, I would be in favour of not changing the name.

I forgot to ask — is there an appropriate test file that does get run on current versions? Somewhere better I can add tests for this?

I think the test is not run because of a change in the display of error (ocaml/ocaml#9657). But I don't think that's a good reason to not test on OCaml version > 4.12.

So we should make this test run on all versions. One possibility is to manipulate the string returned by the expect test, but that's ad-hoc for each compiler change of displayed errors, and requires maintainance time that we don't have.
The other approach is to just have different files for the different versions. You can find an example of such approach in for instance https://github.com/ocaml-ppx/ppxlib/tree/main/test/deriving
I could do the test bump myself if you prefer.

@ELLIOTTCABLE
Copy link
Contributor Author

Okay, I think your arguments hold water — wasn't too sure myself.

Pushed a reversion of the renaming; and added 4.12+ tests, mirroring the approach elsewhere in the repo. :D

Thanks for the hand-holding. ❤️

@ELLIOTTCABLE ELLIOTTCABLE changed the title Add Extension.V3.declare_with_additional_arg (mirroring declare_with_path_arg) Add Extension.V3.declare_with_path_arg Jun 28, 2023
Copy link
Collaborator

@panglesd panglesd left a comment

Choose a reason for hiding this comment

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

I finally had a look at the code, looks good to me! (unsurprisingly)

There are still some things to do to satisfy the CI, before merging... I can do them if you are tired of this!

  • the test/driver/transformations/test_412.ml file should be added to the .ocamlformat-ignore file (or a glob for all .ml files in this directory)
  • The 5.1 CI is still not happy with the test. We might need to add a test_501.ml file... (this method of having different tests for every breaking change in OCaml output is pretty annoying, but less than the other solutions in my opinion).

@ELLIOTTCABLE
Copy link
Contributor Author

Okay! Take 5! 🤞

@panglesd panglesd merged commit 3695773 into ocaml-ppx:main Jul 5, 2023
@panglesd
Copy link
Collaborator

panglesd commented Jul 5, 2023

Thanks @ELLIOTTCABLE ! (and sorry for the delay...)

@ELLIOTTCABLE
Copy link
Contributor Author

You're totally fine, @panglesd ❤️

No pressure at all, just for my planning purposes — what's the general release-cadence likely to be for this to go up onto the public opam repo? We're already using this in production at Ahrefs (it's no big deal, we already have ... a lot of opam overrides 😅); but it's also blocking me being able to release ppx_trace to the public, and some other related ecosystem work around ocaml-trace.

@panglesd
Copy link
Collaborator

panglesd commented Sep 5, 2023

Until now, mostly @pitag-ha has been taking care of the releases... She is currently on holiday.

I think that with the release of ocaml 5.1, we will need to release a compatible version of ppxlib soon! So hopefully, you'll be able to release ppx_trace soon 😅.

@pitag-ha
Copy link
Member

Yep, let's cut a release (as soon as we've merged the functor application migration fix).

avsm pushed a commit to ocaml/opam-repository that referenced this pull request Oct 5, 2023
CHANGES:

- Fix support for OCaml 5.1: migrated code preserves generative
  functor warnings, without creating more. Locations are better
  preserved. (ocaml-ppx/ppxlib#432, @pitag-ha, @panglesd)

- Driver: Add `-unused-code-warnings` command-line flag. (ocaml-ppx/ppxlib#444, @ceastlund)

- Add `?warning` flag to `Deriving.Generator.make`. (ocaml-ppx/ppxlib#440, @jacksonzou123 via @ceastlund)

- Restore the "path_arg" functionality in the V3 API (ocaml-ppx/ppxlib#431, @ELLIOTTCABLE)

- Expose migration/copying/etc. functions for all AST types needed by `Pprintast` (ocaml-ppx/ppxlib#454, @antalsz)

- Preserve quoted attributes on antiquotes in metaquot (ocaml-ppx/ppxlib#441, @ncik-roberts)

- Attribute namespaces: Fix semantics of reserving multi-component namespaces (ocaml-ppx/ppxlib#443, @ncik-roberts)
nberth pushed a commit to nberth/opam-repository that referenced this pull request Jun 18, 2024
CHANGES:

- Fix support for OCaml 5.1: migrated code preserves generative
  functor warnings, without creating more. Locations are better
  preserved. (ocaml-ppx/ppxlib#432, @pitag-ha, @panglesd)

- Driver: Add `-unused-code-warnings` command-line flag. (ocaml-ppx/ppxlib#444, @ceastlund)

- Add `?warning` flag to `Deriving.Generator.make`. (ocaml-ppx/ppxlib#440, @jacksonzou123 via @ceastlund)

- Restore the "path_arg" functionality in the V3 API (ocaml-ppx/ppxlib#431, @ELLIOTTCABLE)

- Expose migration/copying/etc. functions for all AST types needed by `Pprintast` (ocaml-ppx/ppxlib#454, @antalsz)

- Preserve quoted attributes on antiquotes in metaquot (ocaml-ppx/ppxlib#441, @ncik-roberts)

- Attribute namespaces: Fix semantics of reserving multi-component namespaces (ocaml-ppx/ppxlib#443, @ncik-roberts)
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.

3 participants