Skip to content

Fix handling of Printexc.raise_with_backtrace under partial application#1465

Closed
nojb wants to merge 4 commits intoocaml:trunkfrom
nojb:fix_raise_with_backtrace_partial_application
Closed

Fix handling of Printexc.raise_with_backtrace under partial application#1465
nojb wants to merge 4 commits intoocaml:trunkfrom
nojb:fix_raise_with_backtrace_partial_application

Conversation

@nojb
Copy link
Copy Markdown
Contributor

@nojb nojb commented Nov 5, 2017

See MPR#7666 and #378. The case of the primitive %raise_with_backtrace being partially applied was not being handled, which would end up being considered as a (partially-applied) C primitive and fail.

This PR adds the missing case and a corresponding test.

@gasche
Copy link
Copy Markdown
Member

gasche commented Nov 5, 2017

I believe that the fix is correct, but I find it unsatisfying.

  1. The logic of the primitive is now duplicated in the Texp_ident and Texp_apply cases of transl_exp0. You should factor it out in its own function and call it from the two places -- in particular it would make it obvious that one is just an eta-expansion of the other.

  2. This is more of an open question, but can we change the code structure so that a similar error would have been caught at compile-time in the future? For example we could have a variant type of "primitives that must be handled specially" that we match exhaustively over in the two cases.

  3. transl_primitive, which gets called in the fallback/default case of Texp_indent, already has a final default case that does the eta-expansion. Why is this case not reached, why is the fix not to make sure that raise_with_backtrace reaches it, and can we change the code so that it is reached by default for new primitives? (I guess that could be a way to answer question (2)).

@gasche
Copy link
Copy Markdown
Member

gasche commented Nov 5, 2017

(Looking more at the code of transl_primitive, I now suppose that the fallback case is reached and eta-expansion happens, but what is does in the body of the generated function is simplistic. Just calling transl_primitive_application may be better, but having it use the logic currently located in Texp_apply case would require more refactoring -- if that even is the right thing to do.)

(cc @let-def and @bobot who may have an opinion about this code)

@nojb
Copy link
Copy Markdown
Contributor Author

nojb commented Nov 5, 2017

Thanks for the review @gasche. Indeed, I did not overlook the code duplication. But I held off doing it in the first try because 1) I wanted to make sure the fix was correct before refactoring, and 2) there are a couple other "special" primitives that would also profit from this kind of refactoring.

I will give some thought to refactoring along the lines of your 2. and 3.

transl_exp e
| `Float ->
| `Float ->
(* We don't need to wrap with Popaque: this forward
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whilst looking at this PR I noticed the (unrelated) thing that maybe this comment is wrong when the float array optimization is disabled, as it may be in 4.06 onwards. @chambart ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if this is the case, but this might change. We should indeed take the safe way here.

@bobot
Copy link
Copy Markdown
Contributor

bobot commented Nov 7, 2017

@gasche Your solution 1. is the simplest. We could reuse Simplif.beta_reduce params body args in Texp_apply case and at the same time check more correctly the arities (instead of List.hd or assert false)

@nojb Thank you for fixing that.

@gasche
Copy link
Copy Markdown
Member

gasche commented Nov 7, 2017

I think (1) is a necessary first step (I don't really agree with @nojb's view that explicit duplication helps ensure that the patch is correct, because I have to check that the two places do the same thing to review it, whereas a function abstraction would make that immediate), but that it does not solve the longer-term problem that the addition of any additional primitive is likely to be broken in the same way if we don't make try to rule this error out.

@bobot
Copy link
Copy Markdown
Contributor

bobot commented Nov 7, 2017

but that it does not solve the longer-term problem that the addition of any additional primitive is likely to be broken in the same way if we don't make try to rule this error out.

I don't see why, send* functions could not also be added to solution 1., so new primitive will also be added once to solution 1.

@nojb
Copy link
Copy Markdown
Contributor Author

nojb commented Nov 7, 2017

@gasche FWIW, I do not think it helps check the patch is correct, but the refactoring itself is not completely trivial so I thought it would be better to separate the two.

damiendoligez added a commit to damiendoligez/ocaml that referenced this pull request Nov 10, 2017
-no-flat-float-array.
Problem reported by Mark Shinwell in
  ocaml#1465 (review)
@nojb nojb force-pushed the fix_raise_with_backtrace_partial_application branch from f23a761 to 7754923 Compare December 24, 2017 21:20
@nojb
Copy link
Copy Markdown
Contributor Author

nojb commented Jan 4, 2018

Closing this to concentrate efforts on #1557 which is a much more general solution to fixing the issues addressed by this PR.

@nojb nojb closed this Jan 4, 2018
damiendoligez added a commit to damiendoligez/ocaml that referenced this pull request Apr 23, 2018
-no-flat-float-array.
Problem reported by Mark Shinwell in
  ocaml#1465 (review)
damiendoligez added a commit to damiendoligez/ocaml that referenced this pull request May 31, 2018
-no-flat-float-array.
Problem reported by Mark Shinwell in
  ocaml#1465 (review)
damiendoligez added a commit that referenced this pull request Jun 5, 2018
…#1471)

Fix interaction between lazy and float when configured with
-no-flat-float-array.
Problem reported by Mark Shinwell in
  #1465 (review)
damiendoligez added a commit that referenced this pull request Jun 5, 2018
…#1471)

Fix interaction between lazy and float when configured with
-no-flat-float-array.
Problem reported by Mark Shinwell in
  #1465 (review)
EmileTrotignon pushed a commit to EmileTrotignon/ocaml that referenced this pull request Jan 12, 2024
Co-authored-by: Christine Rose <christinerose@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants