Skip to content
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 1559 #1561

Merged
merged 6 commits into from
Feb 9, 2024
Merged

Fix 1559 #1561

merged 6 commits into from
Feb 9, 2024

Conversation

hhugo
Copy link
Member

@hhugo hhugo commented Feb 4, 2024

Fixing #1559

Exiting a for loop too early might result in invalid scope for functions declared inside the for-loop.
A function declaration inside inside a block is scoped to that block (in strict mode) and won't be visible outside.

A quick fix is to simply disable the exit-loop-early optimization until one find a proper fix for it.

@hhugo
Copy link
Member Author

hhugo commented Feb 5, 2024

@vouillon, do you have time to comment on the current approach ?

@rickyvetter
Copy link
Contributor

I tested 3556f36 locally and it fixes the issue with the actual code as well as the example I posted. Thank you! Happy to test other revisions as well if there are other ideas for solving.

@hhugo
Copy link
Member Author

hhugo commented Feb 9, 2024

I'd like to have a single pass to compute all free variables of closures.

edit: this has been implemented

@hhugo
Copy link
Member Author

hhugo commented Feb 9, 2024

@rickyvetter, I've pushed an alternative fix.

@hhugo hhugo merged commit 0aaec26 into master Feb 9, 2024
14 of 15 checks passed
@hhugo hhugo deleted the gh1559 branch February 9, 2024 13:18
Comment on lines +227 to +229
List.iter params ~f:(fun x -> Code.Var.ISet.add bound x);
iter_block_bound_vars (fun x -> Code.Var.ISet.add bound x) block;
List.iter args ~f:using;
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we move these two lines outside of function traverse?

            List.iter params ~f:(fun x -> Code.Var.ISet.add bound x);
            List.iter args ~f:using;

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed, fixed in #1565

hhugo pushed a commit to hhugo/opam-repository that referenced this pull request Feb 21, 2024
CHANGES:

## Features/Changes
* Mics: fix support for OCaml 5.2
* Compiler: no longer rely on IIFE for scoping variable inside loops
* Compiler: avoid parsing bytecode sections twice, jsoo counter part of ocaml#12599
* Lib: add ellipse to canvasRenderingContext2D (@FayCarsons, ocsigen/js_of_ocaml#1555)

## Bug fixes
* Compiler: fix global dead code elimination in a toplevel context
* Compiler: fix exit-loop-early optim in presence of closure (ocsigen/js_of_ocaml#1561)
* Compiler: remove quadratic behavior in generate.ml (ocsigen/js_of_ocaml#1531, ocsigen/js_of_ocaml#1567)
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.

3 participants