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

Enumerators fails to set state to "after" in various scenarios observable with GetEnumerator() #76089

Open
jcouv opened this issue Nov 26, 2024 · 2 comments
Assignees
Labels
Area-Compilers Code Gen Quality Room for improvement in the quality of the compiler's generated code
Milestone

Comments

@jcouv
Copy link
Member

jcouv commented Nov 26, 2024

[jcouv update:] From discussion with Stephen we need to prioritize this. The optimization is meant to only kick once, but the current implementation would allow it to happen again.
With the latest implementation, you can Dispose() and then GetEnumerator() again and it will not allocate a new instance. But we want it to.

The spec states that we should set state of the enumerator object to after in various scenarios:

  • when a yield break is encountered
  • when the end of the iterator body is encountered
  • when an exception is thrown and propagated out of the iterator block
  • when invoking Dispose causes an exception to be thrown

It is possible to observe whether the state was properly set to after by checking whether GetEnumerator() re-uses the current state machine instance or allocates a new one.

In the scenarios above, enumerators don't properly set the state to after.

The impact is not observable to my knowledge as we're making a change to ensure that Dispose() does set the state to after in non-exceptional cases, and this is only affecting an optimization.

@jcouv jcouv added Area-Compilers Code Gen Quality Room for improvement in the quality of the compiler's generated code labels Nov 26, 2024
@jcouv jcouv added this to the Backlog milestone Nov 26, 2024
@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged Issues and PRs which have not yet been triaged by a lead label Nov 26, 2024
@dotnet-policy-service dotnet-policy-service bot removed the untriaged Issues and PRs which have not yet been triaged by a lead label Nov 26, 2024
@jaredpar
Copy link
Member

jaredpar commented Dec 2, 2024

@jcouv why did you put this in Backlog?

@jcouv
Copy link
Member Author

jcouv commented Dec 2, 2024

@jaredpar My reasoning was: this is an old problem, it is only observable if you enumerate the same enumerator multiple times, and nobody reported it. So the impact seems limited.

@jcouv jcouv modified the milestones: Backlog, 17.13 Dec 4, 2024
@jcouv jcouv self-assigned this Dec 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Code Gen Quality Room for improvement in the quality of the compiler's generated code
Projects
None yet
Development

No branches or pull requests

2 participants