-
Notifications
You must be signed in to change notification settings - Fork 177
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 lwt_ppx backtraces with reraise #554
Conversation
To test this out I created a test file and ran Ocaml 4.03/4.05 with and without this change. Threw together my results in https://github.com/gabelevi/lwt_ppx_backtrace_test |
Thanks! I will review this now, but to immediately answer the question about 4.02: as I understand it, PPX already requires 4.02, and we pick this constraint up by depending on |
Actually, I guess one could argue that since |
@samwgoldman was concerned about the perf cost of those local modules. I'm not really sure how expensive they are. I suppose they probably could be moved inside of the |
The local module thing should be fine, I've also (ab)used it a lot. We could always run a small benchmark to see if they get optimized away - I suspect the compiler handles them intelligently. |
Let me know if you'd like me to look into it :) |
{pstr_desc = Pstr_value (Nonrecursive, vbs); _}]), _); _} -> | ||
mapper.structure_item mapper (Str.value Nonrecursive (gen_top_binds vbs)) | ||
| x -> default_mapper.structure_item mapper x); | ||
structure_item = (fun mapper stri -> |
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.
If you don't mind, I'll split this whitespace change out into a separate commit before merging. You don't have to do anything (unless you really want to), I'm happy to take care of it.
(The AppVeyor failure is not related to this PR) |
Trying the tests, I get this output on native 4.05.0 with the improved version of the PPX:
and replacing I am running with |
Hmm...I wonder what's different between our setups. Initially I only tested on my OSX 10.13 laptop, but I just tested on a CentOS 7 machine and it also works the same. I pushed an update to my test repo so that I also tried replacing the Here's what I have installed via opam And I can totally revert the whitespace changes! |
I'm pretty sure it's something wrong with my setup, as I don't remember the backtraces ever being as bad as I have now when I was also using OSX (I tried small test programs outside of Lwt, and got some pretty weird behavior). Everything else with the PR looks good :) I'll look into my problems a bit, then merge the PR. If my local problems take too long to figure out, I'll merge without waiting. Sorry to be a bit of a blocker here. |
You could try installing another version of opam into a different directory.
Don't forget to close the terminal or unset |
Ok, thanks a lot for this! The problem with "my setup" turned out to be that I started by using I ran some performance tests on the local module. There is no noticeable difference between that and an "ordinary" module. I dumped the assembly and it looks like the local module would actually have a miniscule advantage. An "ordinary" module incurs two extra |
Also, speculating and summarizing for future reference, I understand that the code the PPX generated before this PR, using ordinary
Fortunately, the explicit |
As others have noted, backtraces with lwt_ppx seem to be broken. I've seen it mentioned in a few places, but https://caml.inria.fr/mantis/print_bug_page.php?bug_id=7375 is the place that inspired me to see if switching from
raise exn
toreraise exn
would fix the issue.There were a few small challenges:
external reraise : exn -> 'a = "%reraise"
inlwt.ml
and passing it intoadd_loc
made the re-raise location always show up inlwt.ml
. So I decided to make ppx_lwt.ml put it into the transformed fileexternal
part of the grammar is a little tricky to stick inside of an expression, since it's basically a module item. Sticking it into a local module is kind of a hack, but seems to work.The
%reraise
primitive seems to be new to 4.02 so I probably should addavailable: [ocaml-version >= "4.02.0"]
to thelwt_ppx.opam
, right? Would that be ok? I suppose I could also use cppo to decay toraise
for older versions, if you feel strongly.Fixes #498 #171