Fix migration of 5.4's Pexp_pack - #650
Conversation
8fa0caa to
2ec7eed
Compare
Location of attributes changed. Signed-off-by: David Allsopp <david.allsopp@metastack.com>
2ec7eed to
bf3917b
Compare
|
Thanks for the report @dra27-js -- taking a look :-) |
|
Hmm we do drop the package attributes here: ppxlib/astlib/migrate_504_503.ml Lines 460 to 468 in b9646cc And your fix re-adds them in the two places where a It would be good to add a quick test case for this, something like this in Happy to do that for you if you like @dra27-js ? |
|
It would be good to ensure the attributes are correctly preserved through round trips as well! Happy to take a look at that if needed! |
|
Sure - feel free to push this branch (or I can have a look later in the week) |
Signed-off-by: Patrick Ferris <patrick@sirref.org>
| Ast_503.Parsetree.ptyp_loc = loc; | ||
| Ast_503.Parsetree.ptyp_loc_stack = copy_location_stack ptyp_loc_stack; | ||
| Ast_503.Parsetree.ptyp_attributes = copy_attributes ptyp_attributes; | ||
| Ast_503.Parsetree.ptyp_attributes = |
There was a problem hiding this comment.
I'm concerned that this doesn't roundtrip very well, and this is a fact of not being able to unmix the core type attributes from the package type attributes. For example:
type t = (module S [@inner])[@outer]Has the following (summarised for clarity), AST on OCaml 5.4:
type_declaration "t"
ptype_manifest =
Some
core_type
attribute "outer"
[]
Ptyp_package
package_type "S"
[]
attribute "inner"
[]
When we pass it through ppxlib (using the fixes here) we get type t = (((module S))[@outer ][@inner ]) with the following AST:
type_declaration "t"
ptype_manifest =
Some
core_type
attribute "outer"
[]
attribute "inner"
[]
Ptyp_package "S"
[]
Which is better than without the fix where we were just dropping attributes! But maybe is not ideal. I wonder if we shouldn't have an encoding for package types with attributes that we can use instead in order to safely preserve these attributes when we migrate back from 5.3 to 5.4 (which should be doable via Ptyp_extension and Pexp_extension)? What do you think @NathanReb?
There was a problem hiding this comment.
I would avoid wrapping in an extension here since there's a valid migration (modulo attributes). If we do encode those with an extension, that means than building and preprocessing old code with new compiler won't work, which is what we're trying to avoid.
It's not the most statisfying of ways but could we split the attributes from the types and the attributes from package by inserting our own [@ppxlib.migration.split_package_attributes]?
We just add an extra attribute that everyone will ignore and when migrating back to 5.4, the migration knows to treat all attributes after this one differently.
Does that sound doable?
There was a problem hiding this comment.
That sounds good to me @NathanReb -- if you're happy enough I can push a commit to that effect @dra27-js.
In 5.4, ocaml/ocaml#13809 effectively changed where attributes appear on package types, and the migration back to 5.3 drops them:
gives:
for OCaml 5.4/5.5 before this patch and the correct
out: let f ((module K) : (((module S with type t = int))[@foo ])) = ()with it.