Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR changes how we deal with
for
loop typing by turning it into a two-step approach:of_texpr
).to_texpr
).We have to determine the type of the thing we're iterating over in order to properly declare the iteration variable, which we need in order to type the loop body. However, we do not necessarily have to do the actual optimization right away and there are cases where delaying it leads to better code generation.
For the time being, we still do step 2 right away. I have already tried the delay and it passes the unit tests, but I'm holding back on this change because I think that it leads to some duplicate typing. Once we get that right, it will address #3663.
What it does right now:
for (i in 0...5)
loops using the same cost calculations as array declaration unrolling does (example: https://i.imgur.com/psfa6qv.png)This comes with some temp var name changes, so diffs are a bit messy. Other than that, unit.js looks as expected.