-
-
Notifications
You must be signed in to change notification settings - Fork 52
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
fix: move the UTF8 transform to the compiler core #995
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure i fully understand what the utf8 string processing does, but I have a couple of questions:
- Does this PR remove the need of ppx authors to process
j*
attrs? If yes, I understand it'll be done in another PR? couldn't find any refs to that in this one. - Should Melange be able to process utf strings like
\u{1F680}
? I tried on the playground but the ppx will error out. - Do you think it'd make sense to test the UTF8 end to end with the ppx? Right now I can see some direct tests of
Utf8_string.Interp.transform_test
but I can't find anything that uses thej
orjs
attrs. - Finally, what are the downsides of this approach vs the options we discussed in the original issue?
Thanks!
| ( Some ({ attr_name = { txt; loc }; _ } as attr), | ||
Pexp_constant (Pconst_string (s, _, Some dec)) ) -> ( | ||
match | ||
Melange_ffi.Utf8_string.Interp.transform ~loc ~delim:dec |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does the transform have to be moved from the expression to the structure item section?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not what's happening here. This code concerns only [@@mel.inline]
, which transforms let x = {j| ... |j} [@@mel.inline]
into an external with Ffi_inline_const (Const_string {s;unicode})
.
We perform this transformation in the PPX because there's code that can be inlined, and code that can't. Example:
let x = {j| foo |j} [@@mel.inline] (* <-- constant string, can be inlined *)
(* will be transformed into `"foo" ^ x`, which isn't a constant, and cannot be inlined *)
let y = {j| foo $(x) |j} [@@mel.inline]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not what's happening here.
I am confused. This code seems to have been moved from line 405, where it was inside the method! expression e
section, into this section, which is the method! structure_item str
one.
We perform this transformation in the PPX because there's code that can be inlined, and code that can't.
Makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It’s moved to structure item to catch the only the inlined cases. The remaining transformations happen in the core lib now
Yes, it does. By moving the transformation to the compiler, there are no longer cases where
This is not a Melange issue. It works if you use OCaml syntax, and it's not a feature of For Reason syntax, you're running into reasonml/reason#2337
These are tested in the runtime tests under
The downsides here are:
Other than that, I think this actually solves the problem quite cleanly and has the additional benefit of merging the utf8 string code back into one module in |
@@ -22,6 +22,7 @@ module Ppx_entry = struct | |||
|
|||
let rewrite_implementation (ast : Parsetree.structure) : Parsetree.structure = | |||
Ast_config.iter_on_mel_config_stru ast; | |||
let ast = Melange_ffi.Utf8_string.rewrite_structure ast in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think this will have impact on compilation times? Is there a way to measure it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don’t think so. What we were doing in the ppx before, we’re doing here now. The additional transformation is happening for Mel.inline which is a very small subset of cases
[@@mel.inline]
, as can be seen in the snapshotted test case