-
Notifications
You must be signed in to change notification settings - Fork 89
Fix ocamlcfg builds #163
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 ocamlcfg builds #163
Conversation
We need to keep all the instructions that can change the trap depth (you can see that The other point is that most of the instructions that never fallthrough (like |
Thanks for the explanation. Just to double-check: we need |
Normally you wouldn't need the extra |
Ok, thanks, I'll leave |
608b2a6
to
964bcf2
Compare
The CI is green again, including the new cfg workflows!
The first 2 changes is for cmm traps in #72. The last change is for |
I didn't make the new terminator into a separate PR because I wanted to see that it passes the new CI workflows. |
Change 2 above reverts a change made as part of #72 in |
Doesn't this suggest the need for a kind of join operation? |
The third change looks fine, but can you elaborate on why it is needed? |
I thought a bit more on this, and I'm not convinced this change is needed. I think the In a way the |
@lthls you are right, the generated assembly would be fine when The CFI directive would be correct with and without the propagation. What do you think about leaving the propagation/optimization of CFI directives for a separate PR that would also makes the corresponding changes in
I've deleted the Lbranch case from adjust_trap_depths. |
|
Ah, I see the context. If it's not too complicated, you might want to propagate the trap stacks computed on the |
Sorry to insist, but #163 (comment) explains that we have |
An assertion in
The error message is
|
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 approving change 3, and would prefer to let @lthls approve 1-2.
Yes, propagating |
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.
Change 2 is fine.
Change 1 is correct, but:
- The change from
discard_dead_code n
tolinear env i.Mach.next n
was likely a mistake during rebase. In my upstream traps branch (which is based on an old trunk commit), the first case is used when spacetime is not in use, and the second one when it is. The traps branch only adapted the existing code to pass the extraenv
parameter. I assume that when rebasing it on flambda-backend, which does not have spacetime, the wrong branch was kept. (Note that I don't even know why there was a different path with spacetime; as far as I could tell even with spacetime a tailcall instruction was always followed byIend
, at least after runningSelection
). - I still don't see how we could end up with the problematic case. I'll try reproducing the error, as I suspect it likely hides another problem.
The changes proposed in this PR do not introduce any bugs that I could find though, so I'm fine with merging as it is.
Thank you very much! |
I was including it in my review of Change 2. I should probably have been more specific. |
I think this discussion shows that these changes should have been separate PRs... |
Revert a line from flambda-backend#72
Blocks that end with Iextcall that does not return can be generated by Flambda2 (e.g., bounds check) and result in a block without terminator.
31d4904
to
c130fe0
Compare
@gretay-js Please make a note somewhere to ensure we don't forget what Vincent is looking at, namely that there might be another hidden problem relating to Change 1. |
I've actually finished my investigation. When compiling an if-then-else, unless it falls into one of the special cases |
* Discard dead code after Itailcalls and Iextcalls that don't return Revert a line from flambda-backend#72 * Don't propagate Ladjust_trap_depth past Llabel * Add terminator "Throw" for invoking a continuation Blocks that end with Iextcall that does not return can be generated by Flambda2 (e.g., bounds check) and result in a block without terminator. * Rename Cfg.terminator.Throw to Call_no_return * Don't propagate Ladjust_trap_depth past Lbranch * Revert to pre-Cmm-traps version of discard_dead_code after Itailcall
* Discard dead code after Itailcalls and Iextcalls that don't return Revert a line from flambda-backend#72 * Don't propagate Ladjust_trap_depth past Llabel * Add terminator "Throw" for invoking a continuation Blocks that end with Iextcall that does not return can be generated by Flambda2 (e.g., bounds check) and result in a block without terminator. * Rename Cfg.terminator.Throw to Call_no_return * Don't propagate Ladjust_trap_depth past Lbranch * Revert to pre-Cmm-traps version of discard_dead_code after Itailcall
Compilation with
-ocamlcfg
flag with an assertion violation in Linear_to_cfg. For example:This PR fixes the failure.
This PR is currently on top of #159, to check ocamlcfg in the new CI workflow (but should probaby be merged before the changes in #159).
A change in #72 in linearize.ml:L141 breaks a nice invariant that was previously maintained by
Linearize
and checked by an assertion inLinear_to_cfg
translation. The invariant is "no dead code after a tail call". After #72, we get code fragment like this for the for the tail call above example (jmp .L104
followed by deadjmp .L101
):To restore the invariant, I added back a call to
discard_deadcode
. I am not sure it is the right fix. Note that it doesn't revert to the way Itailcalls were handled before #72. I do not understand why in #72n
was replaced withlinear env i.Mach.next n
in that line. Other cases inlinear
for an instructioni
that does not return still discard the rest ofi.next
(for example,Ireturn
). @lthls @mshinwell do you remember why the change was made?