Skip to content

Fix invariant #2013

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

Closed
wants to merge 1 commit into from
Closed

Fix invariant #2013

wants to merge 1 commit into from

Conversation

hhugo
Copy link
Member

@hhugo hhugo commented May 22, 2025

Effects

The effects pass was previously leaving unused blocks behind.

Inlining

The issue

I do not have a good grasp on what's is going on but it seems that a parent closure can sometimes be optimized before the closures it contains (recursive cycles).

function A () 
   fun B() {  A () }
   fun C() { B () }
   C();
}
  • We first optimize A and decide nothing happens
  • Then C and decide to inline B and B becomes dead
  • We need to cleanup A but we already visited it

The fix

  • We maintain a table for a closure to the block it is declared into.
  • We collect the names of all inlined closures, filter out the one that are still live
  • We map the dead closures to their block and rewrite theses blocks only.

@@ -409,7 +420,8 @@ and should_inline ~context info args =
|| Option.equal Var.equal info.enclosing_function context.current_function
|| (not !(context.has_closures))
&& Option.equal Var.equal info.enclosing_function context.enclosing_function
| `Wasm, _ | `JavaScript, `Double_translation -> true
| `JavaScript, `Double_translation -> true
Copy link
Member Author

Choose a reason for hiding this comment

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

@vouillon, I think we need a comment explaining this line

@hhugo hhugo requested a review from vouillon May 22, 2025 16:39
@hhugo
Copy link
Member Author

hhugo commented May 27, 2025

This invariant has been fixed in other PRs

@hhugo hhugo closed this May 27, 2025
@hhugo hhugo deleted the fix-invariant branch May 27, 2025 19:52
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.

3 participants