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

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

Merged

Conversation

brianrourkeboll
Copy link
Contributor

@brianrourkeboll brianrourkeboll commented Jul 17, 2024

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 ->
        let y = z
        x + y
]

as would

[
    for x in xs do
        yield let y = z in x + y
]

but this would not

[
    for x in xs do
        let y = z
        yield x + y
]

nor would

[
    for x in xs do
        let y = 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
  ]
  ```
Copy link
Contributor

github-actions bot commented Jul 17, 2024

❗ Release notes required


✅ Found changes and release notes in following paths:

Change path Release notes path Description
src/Compiler docs/release-notes/.FSharp.Compiler.Service/9.0.100.md

@brianrourkeboll brianrourkeboll changed the title Optimize simple mappings with let-bindings & implicit yield Optimize simple mappings with let-bindings before yield Jul 17, 2024
@brianrourkeboll brianrourkeboll changed the title Optimize simple mappings with let-bindings before yield Optimize simple mappings with binds and/or sequentials before single yield Jul 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 owner July 18, 2024 15:07
Copy link
Member

@psfinaki psfinaki left a comment

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!

Copy link
Member

@vzarytovskii vzarytovskii left a comment

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 free to 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