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

Bias the mapping from magic to version towards the current version #409

Merged
merged 2 commits into from
Apr 4, 2023

Conversation

shym
Copy link
Contributor

@shym shym commented Apr 3, 2023

When mapping from magic numbers to versions, first check whether it is the current version, which is probably the most common case It has the added benefit that, when the mapping is ambiguous (mostly between the latest stable release and the development version), this strategy makes the good choice for the test suite

@shym shym mentioned this pull request Apr 3, 2023
@pitag-ha
Copy link
Member

pitag-ha commented Apr 3, 2023

Thanks, @shym! Does it sound good to you to add a changelog entry? Alternatively, I can write it and it and push it to your branch.

When mapping from magic numbers to versions, first check whether it is
the current version, which is probably the most common case
It has the added benefit that, when the mapping is ambiguous (mostly
between the latest stable release and the development version), this
strategy makes the good choice for the test suite

Signed-off-by: Samuel Hym <[email protected]>
@shym
Copy link
Contributor Author

shym commented Apr 3, 2023

I just updated the changelog. I assumed its entries are not sorted.

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.

Perfect, LGTM! The only nitpick (see below): I'd specify in the changelog that the change is about the driver, since library and driver are mixed in the same package in ppxlib and most user-facing changes are on the library.

CHANGES.md Outdated
Comment on lines 17 to 19
- Bias the mapping from magic to version towards the current version,
as it is usually the common case and it helps when magic numbers are
ambiguous (such as on development versions) (#409, @shym)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
- Bias the mapping from magic to version towards the current version,
as it is usually the common case and it helps when magic numbers are
ambiguous (such as on development versions) (#409, @shym)
- Driver: Bias the mapping from magic to version towards the current version,
as it is usually the common case and it helps when magic numbers are
ambiguous (such as on development versions) (#409, @shym)

@pitag-ha pitag-ha merged commit 499a836 into ocaml-ppx:main Apr 4, 2023
@shym shym deleted the current-magic branch April 5, 2023 10:10
@panglesd
Copy link
Collaborator

Just out of curiosity, is there a case where ppxlib is reading an AST which is not of magic number "Ocaml_current"? In other words, could (module OCaml_current : OCaml_version) :: all_versions be replaced with [(module OCaml_current : OCaml_version)]?

@shym
Copy link
Contributor Author

shym commented Apr 11, 2023

It does happen at least in the test suite, for instance in test/driver/run_as_ppx_rewriter_preserve_version/test.t/406_binary_ast. (But I admit I was wondering about the use case)

@pitag-ha
Copy link
Member

is there a case where ppxlib is reading an AST which is not of magic number "Ocaml_current"?

This is the case whenever the PPX executable is compiled with a different OCaml version than the project. So, in particular, that's never the case when people use dune. However, it's usually the case in the bucklescript/rescript ecosystem (although I'm not sure how much they still use PPXs). And it can also be the case for OCaml people who don't want to use dune and the standard Ppxlib driver workflow and instead produce their own PPX executables (with Ppxlib) and use a Makefile passing those PPX executable(s) to ocamlopt/ocamlc manually.

That being said, I don't think that's a problem for the following reason: on released Ppxlib versions, nothing has changed: released Ppxlib versions are still only compatible with stable compilers, among which the magic numbers are unique. So biasing or not doesn't make a difference in that context. And whenever we are in a context where we allow Ppxlib to be co-installable with trunk (such as the trunk-support branch), it is clear that we don't guarantee that things will work. In that context, we do our best. Thank to @shym's idea, in that context, Ppxlib can now be cross-compiler compatible whenever people use dune. When people use a manual set-up, they might have to make sure that things work manually.

tmattio added a commit to tmattio/opam-repository that referenced this pull request Jun 20, 2023
CHANGES:

- Adopt the OCaml Code of Conduct on the repo (ocaml-ppx/ppxlib#426, @pitag-ha)

- Clean up misleading attribute hints when declared for proper context. (ocaml-ppx/ppxlib#425, @ceastlund)

- Ast_pattern now has ebool, pbool helper, and a new map.(ocaml-ppx/ppxlib#402, @Burnleydev1)

- multiple errors are now reported in `metaquot`. (ocaml-ppx/ppxlib#397, @Burnleydev1)

- Add `Attribute.declare_with_attr_loc` (ocaml-ppx/ppxlib#396, @dvulakh)

- Add "ns" and "res" as reserved namespaces(ocaml-ppx/ppxlib#388, @davesnx)

- Make quoter `let` binding non-recursive (ocaml-ppx/ppxlib#401, @sim642)

- Fix failure of 'lift_map_with_context' in traverse by compile-time
  evaluation of 'fst' and 'snd' (ocaml-ppx/ppxlib#390, @smuenzel)

- Driver: Bias the mapping from magic to version towards the current version,
  as it is usually the common case and it helps when magic numbers are
  ambiguous (such as on development versions) (ocaml-ppx/ppxlib#409, @shym)

- Remove unnecessary test dependencies towards base and stdio (ocaml-ppx/ppxlib#421, @kit-ty-kate)

- Update description to reflect that `ppxlib` contains more than a library
  (ocaml-ppx/ppxlib#422, @pitag-ha)

- Add support for OCaml 5.1, excluding OCaml `5.1.0~alpha1` (ocaml-ppx/ppxlib#428, @shym, @Octachron , @pitag-ha, @panglesd)
- Driver: Fix `-locations-check` option for coercions with ground  (ocaml-ppx/ppxlib#428, @Octachron)
tmattio added a commit to tmattio/opam-repository that referenced this pull request Jun 20, 2023
CHANGES:

- Adopt the OCaml Code of Conduct on the repo (ocaml-ppx/ppxlib#426, @pitag-ha)

- Clean up misleading attribute hints when declared for proper context. (ocaml-ppx/ppxlib#425, @ceastlund)

- Ast_pattern now has ebool, pbool helper, and a new map.(ocaml-ppx/ppxlib#402, @Burnleydev1)

- multiple errors are now reported in `metaquot`. (ocaml-ppx/ppxlib#397, @Burnleydev1)

- Add `Attribute.declare_with_attr_loc` (ocaml-ppx/ppxlib#396, @dvulakh)

- Add "ns" and "res" as reserved namespaces(ocaml-ppx/ppxlib#388, @davesnx)

- Make quoter `let` binding non-recursive (ocaml-ppx/ppxlib#401, @sim642)

- Fix failure of 'lift_map_with_context' in traverse by compile-time
  evaluation of 'fst' and 'snd' (ocaml-ppx/ppxlib#390, @smuenzel)

- Driver: Bias the mapping from magic to version towards the current version,
  as it is usually the common case and it helps when magic numbers are
  ambiguous (such as on development versions) (ocaml-ppx/ppxlib#409, @shym)

- Remove unnecessary test dependencies towards base and stdio (ocaml-ppx/ppxlib#421, @kit-ty-kate)

- Update description to reflect that `ppxlib` contains more than a library
  (ocaml-ppx/ppxlib#422, @pitag-ha)

- Add support for OCaml 5.1, excluding OCaml `5.1.0~alpha1` (ocaml-ppx/ppxlib#428, @shym, @Octachron , @pitag-ha, @panglesd)
- Driver: Fix `-locations-check` option for coercions with ground  (ocaml-ppx/ppxlib#428, @Octachron)
tmattio added a commit to tmattio/opam-repository that referenced this pull request Jun 20, 2023
CHANGES:

- Adopt the OCaml Code of Conduct on the repo (ocaml-ppx/ppxlib#426, @pitag-ha)

- Clean up misleading attribute hints when declared for proper context. (ocaml-ppx/ppxlib#425, @ceastlund)

- Ast_pattern now has ebool, pbool helper, and a new map.(ocaml-ppx/ppxlib#402, @Burnleydev1)

- multiple errors are now reported in `metaquot`. (ocaml-ppx/ppxlib#397, @Burnleydev1)

- Add `Attribute.declare_with_attr_loc` (ocaml-ppx/ppxlib#396, @dvulakh)

- Add "ns" and "res" as reserved namespaces(ocaml-ppx/ppxlib#388, @davesnx)

- Make quoter `let` binding non-recursive (ocaml-ppx/ppxlib#401, @sim642)

- Fix failure of 'lift_map_with_context' in traverse by compile-time
  evaluation of 'fst' and 'snd' (ocaml-ppx/ppxlib#390, @smuenzel)

- Driver: Bias the mapping from magic to version towards the current version,
  as it is usually the common case and it helps when magic numbers are
  ambiguous (such as on development versions) (ocaml-ppx/ppxlib#409, @shym)

- Remove unnecessary test dependencies towards base and stdio (ocaml-ppx/ppxlib#421, @kit-ty-kate)

- Update description to reflect that `ppxlib` contains more than a library
  (ocaml-ppx/ppxlib#422, @pitag-ha)

- Add support for OCaml 5.1, excluding OCaml `5.1.0~alpha1` (ocaml-ppx/ppxlib#428, @shym, @Octachron , @pitag-ha, @panglesd)
- Driver: Fix `-locations-check` option for coercions with ground  (ocaml-ppx/ppxlib#428, @Octachron)
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