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

Migrate ocaml ppx context #478

Merged

Conversation

NathanReb
Copy link
Collaborator

@NathanReb NathanReb commented Feb 21, 2024

This PR adds migration of ocaml.ppx.context's load_path between 5.1 and 5.2.

No information is lost in the round-trip.

It comes with a test that should run only with the latest OCaml version, for now that's 5.2.
The test consists of adding a manually written ocaml.ppx.context to an ml file after an actual structure item so it is not discarded by the driver.
The custom driver will look for this floating attribute, manually migrate it to 5.01 (any version before 5.02 would do since the format was stable before that point), and pretty print to stdout. It will then manually migrate it to the compiler version (i.e. at least 5.02) and pretty print again.
The driver actual output is discarded.

The only downside to this approach is that we have to re-implement a small part of pprintast for 5.01 in the custom driver but I'd say it's acceptable since we don't have to do it for any other version and it makes the cram test quite simple.

Let me know what you think!

@NathanReb
Copy link
Collaborator Author

@Octachron it seems from our conversation during the last ppxlib dev meeting that the migration from 5.02 to 5.01 should include all load paths, both hidden and visible into the 5.01 load_path field, is that correct?

The migration currently discards the hidden ones. I'll change that if you confirm!

@Octachron
Copy link
Contributor

I think it would be better in term of backward compatibility: the idea of the hidden includes is to split the current list of includes between the direct dependencies (which should be fully visible) and the transitive dependencies (which should only be visible internally by the compiler). Thus, if we have a context that has been split into hidden and visible parts and we need to convert it to a pre-5.2 world, the closest approximation would be to make everything visible.

@NathanReb NathanReb force-pushed the migrate-ocaml-ppx-context branch 3 times, most recently from 357483b to 756429e Compare February 21, 2024 14:32
@NathanReb
Copy link
Collaborator Author

I changed the migration to merge visible and hidden when migrating down to 5.1!

@NathanReb
Copy link
Collaborator Author

We should probably wait on the outcome of the following discussion to decide whether we should merge this into trunk-support:
ocaml/ocaml#12246 (comment)

@NathanReb NathanReb force-pushed the migrate-ocaml-ppx-context branch from 9010ee8 to 031dd11 Compare March 11, 2024 13:19
@NathanReb
Copy link
Collaborator Author

We're going to go with this migration and keep the 5.2 changes on the OCaml side so we do need to get this merged!

Copy link
Member

@pitag-ha pitag-ha left a comment

Choose a reason for hiding this comment

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

Nice, thanks for both the implementation and the tests! The way the test works is a very good idea that makes a complicated test simple!

Apart from my one question about the location, it looks all good to me.

Btw, there's also a general question about what we'll want to do once we bump the AST to >=5.2. Once we do so, we could introduce a much simpler migration without track-keeping attr. We can discuss that once the time comes and I don't have a strong opinion, but I wanted to mention it already.

astlib/migrate_502_501.ml Outdated Show resolved Hide resolved
test/driver/ocaml-ppx-context-load-path-migration/dune Outdated Show resolved Hide resolved
@pitag-ha
Copy link
Member

Btw, thanks, @anmonteiro! Every help we can get is always appreciated!

A question out of curiosity: Have you been affected by the problem this PR solves? I'm asking because I know that in the past, some OCaml to JS compiler (concretely bucklescript) would have been affected. I'm not expecting melange to be affected, but am curious now.

@NathanReb NathanReb requested a review from pitag-ha March 19, 2024 09:29
Copy link
Member

@pitag-ha pitag-ha left a comment

Choose a reason for hiding this comment

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

Thanks, looks all good to me! 🚀

If you can still quickly address the version question below before merging, that's amazing, but merging sounds good to me already.

test/driver/ocaml-ppx-context-load-path-migration/dune Outdated Show resolved Hide resolved
@NathanReb NathanReb merged commit d7c5971 into ocaml-ppx:trunk-support Mar 20, 2024
4 checks passed
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.

4 participants