Skip to content

Conversation

@hhugo
Copy link
Member

@hhugo hhugo commented Dec 5, 2023

@vouillon. @micahcantor #1503 breaks tail call as mentioned by @vouillon

The global DCE does not preserve tail calls. We don't care normally since JavaScript does not support tail calls, but this makes a difference for the CPS transformation.

Except the Generate_closure pass does care about tail calls as it rewrite mutually recursive functions using a trampoline.

Do you see any issue with the change proposed here ?

@hhugo hhugo requested a review from vouillon December 5, 2023 09:14
@hhugo
Copy link
Member Author

hhugo commented Dec 5, 2023

This issue was spotted by a single package (ezjsonm) during the opam release.
See ocaml/opam-repository#24888

Copy link
Contributor

@OlivierNicole OlivierNicole left a comment

Choose a reason for hiding this comment

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

I don’t exactly understand how global DCE broke tail calls and why this fixes it, so I won’t comment beyond the surface level.

@vouillon
Copy link
Member

vouillon commented Dec 5, 2023

The call to Generate_closure.f should be after the CPS transformation.
I think the second commit is enough to fix the issue.

@hhugo
Copy link
Member Author

hhugo commented Dec 5, 2023

The call to Generate_closure.f should be after the CPS transformation. I think the second commit is enough to fix the issue.

Can you explain the reasons ?
Moving it before seems to detect more deadcode (as show in 0fe4aab). It this invalid ?

@hhugo
Copy link
Member Author

hhugo commented Dec 5, 2023

The call to Generate_closure.f should be after the CPS transformation. I think the second commit is enough to fix the issue.

Can you explain the reasons ? Moving it before seems to detect more deadcode (as show in 0fe4aab). It this invalid ?

Obviously, it removes the deadcode introduced by generate_closure.

@hhugo hhugo force-pushed the restore-tco branch 2 times, most recently from d8fee6c to 5c1923f Compare December 5, 2023 12:51
@hhugo hhugo merged commit 31e5d22 into master Dec 5, 2023
@hhugo hhugo deleted the restore-tco branch December 5, 2023 13:45
@vouillon
Copy link
Member

vouillon commented Dec 5, 2023

The call to Generate_closure.f should be after the CPS transformation. I think the second commit is enough to fix the issue.

Can you explain the reasons ? Moving it before seems to detect more deadcode (as show in 0fe4aab). It this invalid ?

Generate_closure.rewrite_mutable is only needed for functions within loops. The partial CPS transformation will turn some loops into mutual function calls, making it unnecessary.

@hhugo
Copy link
Member Author

hhugo commented Dec 5, 2023

I've opened #1540 to get rid of rewrite_mutable. Is this the only reason ?

@vouillon
Copy link
Member

vouillon commented Dec 5, 2023

I think so. rewrite_tc is disabled in this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants