-
Notifications
You must be signed in to change notification settings - Fork 91
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 and optimize quoter #327
Conversation
1bbd890
to
5f55b77
Compare
I'm not sure what to make of this failure diff with OCaml 4.14: - {Ppxlib__.Import.pos_fname =
- "_no"... (* string length 6; truncated *);
- pos_lnum = 1; pos_bol = 0; pos_cnum = -1};
+ {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; pos_bol = 0;
+ pos_cnum = -1}; Structurally it's the same thing, but the testing is fragile w.r.t. unrelated changes somewhere (EDIT: I guess this: ocaml/ocaml#10565). |
Thanks for the PR, @sim642! I'll have time to review it Thursday or Friday. |
Thanks @sim642, both for the bug fix and for the optimization! Apart from the failing CI and a missing changelog entry, this looks perfect. Would you mind rebasing over Also, I've read your conversation with gasche on the Btw, we should really add documentation to the quoter functions! |
Signed-off-by: Simmo Saan <simmo.saan@gmail.com>
Both done, but the CI still breaks for OCaml 4.14. I think the issue is that it's using toploop's own printing from the compiler instead of ppxlib's copy of |
Hey @sim642! This has taken a while, but the CI should be fixed now. Your branch needs to be rebased over |
Signed-off-by: Simmo Saan <simmo.saan@gmail.com>
From: ocaml-ppx/ppx_deriving#252. Signed-off-by: Simmo Saan <simmo.saan@gmail.com>
Signed-off-by: Simmo Saan <simmo.saan@gmail.com>
Done and the CI looks happy now. Weirdly, though, running locally in a OCaml 4.14 switch diff --git a/_build/default/test/base/test.ml b/_build/default/test/base/test.ml.corrected
index 7cf282a..77c27e5 100644
--- a/_build/default/test/base/test.ml
+++ b/_build/default/test/base/test.ml.corrected
@@ -106,17 +106,17 @@ let _ = convert_longident "Base.( land )"
let _ = convert_longident "A(B)"
[%%expect{|
-Exception: (Invalid_argument "Ppxlib.Longident.parse: \"A(B)\"")
+Exception: Invalid_argument "Ppxlib.Longident.parse: \"A(B)\"".
|}]
let _ = convert_longident "A.B(C)"
[%%expect{|
-Exception: (Invalid_argument "Ppxlib.Longident.parse: \"A.B(C)\"")
+Exception: Invalid_argument "Ppxlib.Longident.parse: \"A.B(C)\"".
|}]
let _ = convert_longident ")"
[%%expect{|
-Exception: (Invalid_argument "Ppxlib.Longident.parse: \")\"")
+Exception: Invalid_argument "Ppxlib.Longident.parse: \")\"".
|}]
let _ = Ppxlib.Code_path.(file_path @@ top_level ~file_path:"dir/main.ml") Doesn't seem to have bothered the CI though, so I'm not sure what that's about. EDIT: Looks like the difference between base v0.14.3 (no diffs) vs v0.15.0 (these extra diffs). I guess something additional to separately look into. |
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.
Perfect, thanks for this improvement, @sim642!
You seem to have version |
CHANGES: - Update expansion context to leave out value name when multiple are defined at once. (ocaml-ppx/ppxlib#351, @ceastlund) - Add support for OCaml 5.0 (ocaml-ppx/ppxlib#348, @pitag-ha) - Add `Code_path.enclosing_value` (ocaml-ppx/ppxlib#349, @ceastlund) - Add `Code_path.enclosing_module` (ocaml-ppx/ppxlib#346, @ceastlund) - Expand code generated by `~enclose_intf` and `~enclose_impl` (ocaml-ppx/ppxlib#345, @ceastlund) - Add type annotations to code generated by metaquot (ocaml-ppx/ppxlib#344, @ceastlund) - Fix typo in description field of dune-project (ocaml-ppx/ppxlib#343, @ceastlund) - Fix Ast_pattern.many (ocaml-ppx/ppxlib#333, @nojb) - Fix quoter and optimize identifier quoting (ocaml-ppx/ppxlib#327, @sim642) - Driver, when run with `--check`: Allow `toplevel_printer` attributes (ocaml-ppx/ppxlib#340, @pitag-ha) - Documentation: Add a section on reporting errors by embedding extension nodes in the AST (ocaml-ppx/ppxlib#318, @panglesd) - Driver: In the case of ppxlib internal errors, embed those errors instead of raising to return a meaningful AST (ocaml-ppx/ppxlib#329, @panglesd) - API: For each function that could raise a located error, add a function that return a `result` instead (ocaml-ppx/ppxlib#329, @panglesd)
Thinking about #317 again, I realized that quoting had already been ported to ppxlib, but I was completely unaware of it before (it was very easy to miss in the middle of all the autogenerated documentation).
This PR ports my optimization to the quoter from ppx_deriving to ppxlib: ocaml-ppx/ppx_deriving#252.
Before doing that, I realized that the existing implementation was actually broken: it was missing application of
()
to the quoted name, so I fixed that first.For identifier-only quoted expressions the two things somewhat cancel each other out, so the changes might be easier understood looking at the commits separately.
I guess nobody noticed it being broken for all these years because nobody is using
Ppxlib.Quoter
(also according to Sherlocode).