Skip to content

Optimize simple mappings with binds and/or sequentials before single yield - #17419

Merged
vzarytovskii merged 8 commits into
dotnet:mainfrom
brianrourkeboll:collection-lowering-implicit-yields
Jul 27, 2024
Merged

Optimize simple mappings with binds and/or sequentials before single yield#17419
vzarytovskii merged 8 commits into
dotnet:mainfrom
brianrourkeboll:collection-lowering-implicit-yields

Conversation

@brianrourkeboll

@brianrourkebollbrianrourkeboll commented Jul 17, 2024

Copy link
Copy Markdown
Contributor

Description

Followup to #16832, #16948, #17067.

Before, with #16832, #16948, #17067, etc., when xs was a list (or an array, or an integral range, depending), an expression like this would get optimized to a fast while-loop

[for x in xs ->lety= z
x + y
]

as would

[for x in xs doyieldlety= z in x + y
]

but this would not

[for x in xs dolety= z
yield x + y
]

nor would

[for x in xs dolety= z
x + y
]

Now, the latter two are optimized as well.

Checklist

  • Test cases added.
  • Release notes entry updated.

Notes

  • This isn't a new optimization; it just ensures that the existing optimizations are applied in more scenarios.
  • I should probably come back someday and redo these emitted IL tests to be more systematic, comprehensive, and descriptively-named — maybe an approach similar to that taken in Some more active pattern error message improvements + tests #17186 would help, although there would be far more combinations at play here...

* Previously, the newer collection lowering optimizations were not being
applied when the body of the mapping involved one or more let-bindings
and an implicit yield. Now, they are.
```fsharp
[
for x in xs do
let y = z
x + y
]
```
@github-actions

github-actionsBot commented Jul 17, 2024

Copy link
Copy Markdown
Contributor

❗ Release notes required


✅ Found changes and release notes in following paths:

Change pathRelease notes pathDescription
src/Compilerdocs/release-notes/.FSharp.Compiler.Service/9.0.100.md

@brianrourkebollbrianrourkeboll changed the title Optimize simple mappings with let-bindings & implicit yieldOptimize simple mappings with let-bindings before yieldJul 17, 2024
@brianrourkebollbrianrourkeboll changed the title Optimize simple mappings with let-bindings before yieldOptimize simple mappings with binds and/or sequentials before single yieldJul 18, 2024
@brianrourkeboll
brianrourkeboll marked this pull request as ready for review July 18, 2024 15:07
@brianrourkeboll
brianrourkeboll requested a review from a team as a code ownerJuly 18, 2024 15:07

@psfinakipsfinaki left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good stuff, thanks for further tuning the optimization!

@vzarytovskiivzarytovskii 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.

Nice, thanks!

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

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants

@brianrourkeboll@vzarytovskii@psfinaki