-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Release bytecode only after backtrace has been recorded #10803
Conversation
When an exception happens bytecode has been released before the backtrace is recorded and so all the debugging information related, because of that the backtrace information for the script that has just been compiled was not being found, which resulted on showing 'unknown location' instead of the actual location. Enable debug flag for running a file on toplevel
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 believe that this is a correct bugfix to a regression we introduced in 4.12 -- see the discussion in #9701 (comment) .
toplevel/byte/topeval.ml
Outdated
@@ -87,13 +87,16 @@ let load_lambda ppf lam = | |||
match | |||
may_trace := true; | |||
Fun.protect | |||
~finally:(fun () -> may_trace := false; | |||
if can_free then Meta.release_bytecode bytecode) | |||
~finally:(fun () -> may_trace := false) |
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 would be in favor of completely removing the Fun.protect
call here, if only because it shows up in the user-visible backtrace.
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.
Sure, removed.
@gasche I would like to have a regression test for that. But couldn't figure that out from what is present on testsuite/tests/tool-toplevel/. |
Re. testing: there is a flag |
I was able to add the test, but not to make sure that's right. I couldn't make it fail when the reference file is different from the actual output of the script. |
ocaml_exit_status = "2" | ||
* setup-ocaml-build-env | ||
** ocaml | ||
*) |
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.
You need to add a check-ocaml-output
step (see for example tests/typing-shadowing-of-pervasives-submodules/redefine_largefile_top.ml
).
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.
Thank you very much
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.
Done
Looks like that test is failing because of the backslash Windows uses for paths,
|
A simpler workaround might be to fix the filename by adding a line directive at the start of the script: #1 "pr9701.ml"
Printexc.record_backtrace true;; |
It's odd that Windows is using But yes I would go for @Octachron's workaround, or just disable the test under Windows for now. |
Gonna try @Octachron's workaround first, it seems to work locally. |
What's the status on this PR? It looks like a bug fix, so it should be given some attention for 4.14. |
@@ -109,6 +109,7 @@ let load_file = load_file false | |||
(* Execute a script. If [name] is "", read the script from stdin. *) | |||
|
|||
let run_script ppf name args = | |||
Clflags.debug := true; |
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.
Is this related to the bug fix or an independent change?
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.
Without this, the toplevel wouldn't collect debug information and show no line numbers after an exception.
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 still don't understand. Is this change visible to users? If so it should have been discussed as part of this PR and it should be described as such in the Changes file.
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 understand this as a minor fix to an inconsistency in the toplevel code: Toploop.loop
, called by interactive usage of the toplevel, sets Clflags.debug := true
on entry, but (until this change) ocaml foo.ml
would behave differently. With this change, both Toploop entry points from Topmain do the same thing.
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 will affect the output of shebang ocaml scripts, which is a known area for surprising bug reports (cf. the still-smouldering, if closed, stuff around #2155). That sounds worth an explicit entry in Changes, therefore?
Thanks for the ping! I guess we got distracted by other stuff. I fixed the Changes conflict and will merge in 4.14 if the CI comes back green. |
It should be really to go. Although I think location for scripts could be really improved, this specific bug should be fixed. |
When an exception happens bytecode has been released before the
backtrace is recorded and so all the debugging information related,
because of that the backtrace information for the script that has
just been compiled was not being found, which resulted on showing
'unknown location' instead of the actual location.
Enable debug flag for running a file on toplevel.
Resolves #9701