Skip to content

Back-end: emit let instead of var.#6102

Merged
cknitt merged 1 commit into
masterfrom
let
Apr 30, 2024
Merged

Back-end: emit let instead of var.#6102
cknitt merged 1 commit into
masterfrom
let

Conversation

@cristianoc

@cristianoc cristianoc commented Mar 30, 2023

Copy link
Copy Markdown
Collaborator

Fixes #856

  • Need to check that no cases are missed where this could introduce regressions even if the tests appear to be passing

  • This will generate a huge amount of noise in the diff w.r.t. other versions of the compiler. It might not be ideal to have this change in an initial version of compiler v11 if other changes are important as they would get lost in the noise

  • Note that the transformation creating problems in Fix issue with generating async functions inside loops. #6479 can be removed

@cristianoc cristianoc requested a review from cknitt March 30, 2023 08:51
@cristianoc cristianoc added this to the v11.0 milestone Mar 30, 2023
@hhugo

hhugo commented Apr 3, 2023

Copy link
Copy Markdown
Contributor

You can then remove the previous fix (using IIFE) used to capture mutable variable

@cristianoc cristianoc modified the milestones: v11.0, v12 Apr 9, 2023
cristianoc added a commit that referenced this pull request Nov 9, 2023
The scope of `var` is per-function, requiring a transformation for closures inside loops when capturing loop variables.
This PR turns off the transformation.
This PR should go after #6102
@DZakh

DZakh commented Nov 9, 2023

Copy link
Copy Markdown
Member

I wonder how much it'll affect performance. But probably it won't be a big difference.

@fhammerschmidt

Copy link
Copy Markdown
Member

@DZakh did you see this: #856 (comment) ?

@DZakh

DZakh commented Nov 9, 2023

Copy link
Copy Markdown
Member

Wow, cool

cristianoc added a commit that referenced this pull request Nov 9, 2023
The scope of `var` is per-function, requiring a transformation for closures inside loops when capturing loop variables.
This PR turns off the transformation.
This PR should go after #6102
@cknitt

cknitt commented Apr 27, 2024

Copy link
Copy Markdown
Member

@cristianoc Could you rebase this? Now that 11.1 is out and development focus is shifting to v12, it would be great to get this merged.

@cristianoc cristianoc force-pushed the let branch 2 times, most recently from d9a369b to 698fbf5 Compare April 28, 2024 10:59
@cristianoc cristianoc requested review from cknitt and removed request for cknitt April 28, 2024 11:00

@cknitt cknitt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks a lot!

Let's remove "Test" from the commit message and PR title before merging though.

Comment thread CHANGELOG.md Outdated
@cknitt

cknitt commented Apr 29, 2024

Copy link
Copy Markdown
Member

Sorry, I'm afraid you'll also need to rebase again.

@cristianoc cristianoc changed the title Test emitting let instead of var. Back-end: emitting let instead of var. Apr 30, 2024
@cristianoc cristianoc changed the title Back-end: emitting let instead of var. Back-end: emit let instead of var. Apr 30, 2024
@cristianoc

Copy link
Copy Markdown
Collaborator Author

@cknitt ready to go

@cknitt cknitt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Great, thanks!

@cknitt cknitt merged commit 7bf97d9 into master Apr 30, 2024
cristianoc added a commit that referenced this pull request Apr 30, 2024
The scope of `var` is per-function, requiring a transformation for closures inside loops when capturing loop variables.
This PR turns off the transformation.
This PR should go after #6102
cometkim pushed a commit to cometkim/rescript that referenced this pull request May 23, 2024
@nojaf

nojaf commented Oct 22, 2024

Copy link
Copy Markdown
Member

Just want to make a quick note that this is improvement is a requirement for the React Compiler it seems to analyze the rules of React.

https://playground.react.dev/#N4Igzg9grgTgxgUxALhASwLYAcIwC4AEAVAQIZgEBKCpchAZjBBgQDogw13sDcrAdgPpR+dNBH4EA6qQA2AawQwwACixMsYAJQFgAggQBupGEYIBeAvwQB3AgBFSeBCq0A6PBACSAZQDyPngwaPwA5q5usghheAAWBAB8BABMfJIEaPQEKoY6eukG1LR4blBgCACi9PQIdCoqwqJ44pKuuvoGnV0GHd2dAL5aADQEANoAulppBv0CHZx4sJL8ULKyabOC1gAeOPgEACYI9KSrhDIKSmA8IP1AA

Changing var to let in the playground will trigger the compiler error.

@github-actions github-actions Bot deleted the let branch February 27, 2026 00:23
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.

Wrong compilation of closures

6 participants