-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Add System.Linq.AsyncEnumerable #111685
Add System.Linq.AsyncEnumerable #111685
Conversation
Note regarding the
|
Note regarding the
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 125 out of 140 changed files in this pull request and generated no comments.
Files not reviewed (15)
- src/installer/pkg/sfx/Microsoft.NETCore.App/PackageOverrides.txt: Language not supported
- src/libraries/NetCoreAppLibrary.props: Language not supported
- src/libraries/System.Linq.AsyncEnumerable/Directory.Build.props: Language not supported
- src/libraries/System.Linq.AsyncEnumerable/System.Linq.AsyncEnumerable.sln: Language not supported
- src/libraries/System.Linq.AsyncEnumerable/ref/System.Linq.AsyncEnumerable.csproj: Language not supported
- src/libraries/System.Linq.AsyncEnumerable/src/Resources/Strings.resx: Language not supported
- src/libraries/System.Linq.AsyncEnumerable/src/System.Linq.AsyncEnumerable.csproj: Language not supported
- src/libraries/System.Linq.AsyncEnumerable/src/System/Linq/ContainsAsync.cs: Evaluated as low risk
- src/libraries/System.Linq.AsyncEnumerable/src/System/Linq/Chunk.cs: Evaluated as low risk
- src/libraries/System.Linq.AsyncEnumerable/src/System/Linq/Cast.cs: Evaluated as low risk
- src/libraries/System.Linq.AsyncEnumerable/ref/System.Linq.AsyncEnumerable.cs: Evaluated as low risk
- src/libraries/System.Linq.AsyncEnumerable/src/System/Linq/AsyncEnumerable.cs: Evaluated as low risk
- src/libraries/System.Linq.AsyncEnumerable/src/System/Linq/AverageAsync.cs: Evaluated as low risk
- src/libraries/System.Linq.AsyncEnumerable/src/System/Linq/Append.cs: Evaluated as low risk
- src/libraries/System.Linq.AsyncEnumerable/src/System/Linq/AggregateBy.cs: Evaluated as low risk
Comments suppressed due to low confidence (2)
src/libraries/System.Linq.AsyncEnumerable/src/System/Linq/AnyAsync.cs:56
- The predicate parameter should be checked for null before being used.
Func<TSource, bool> predicate
src/libraries/System.Linq.AsyncEnumerable/src/System/Linq/AnyAsync.cs:93
- The predicate parameter should be checked for null before being used.
Func<TSource, CancellationToken, ValueTask<bool>> predicate
Tip: Turn on automatic Copilot reviews for this repository to get quick feedback on every pull request. Learn more
eae2001
to
4862035
Compare
src/libraries/System.Linq.AsyncEnumerable/src/System/Linq/ToAsyncEnumerable.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Linq.AsyncEnumerable/src/System/Linq/Cast.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Linq.AsyncEnumerable/src/System/Linq/OfType.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Linq.AsyncEnumerable/src/System/Linq/SingleAsync.cs
Show resolved
Hide resolved
src/libraries/System.Linq.AsyncEnumerable/src/System/Linq/Select.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
@ViktorHofer, is this acceptable?
|
@idg10, @HowardvanRooijen, as maintainers of the existing System.Linq.Async, you stated you want to deprecate that and push developers to use an implementation built into .NET. Before we merge this, I just want to triple check that's still your desired outcome 😄 Any feedback before this merges? |
Very much so! It's been great to watch this PR & discussion. |
All other places in the repo reference the ValueTuple package for .NET Framework only:
|
src/libraries/System.Linq.AsyncEnumerable/src/System.Linq.AsyncEnumerable.csproj
Outdated
Show resolved
Hide resolved
src/libraries/System.Linq.AsyncEnumerable/src/System.Linq.AsyncEnumerable.csproj
Show resolved
Hide resolved
src/libraries/System.Text.Json/tests/System.Text.Json.Tests/System.Text.Json.Tests.csproj
Show resolved
Hide resolved
src/libraries/System.Linq.AsyncEnumerable/src/System.Linq.AsyncEnumerable.csproj
Outdated
Show resolved
Hide resolved
473c366
to
a494879
Compare
@pavelsavara, can you help me figure out what's going on in the wasm legs? Some of the tests are failing in strange ways:
Normally I'd look for trimming-related issues, but I'm not seeing the problem. |
What's being disposed here ? What the dispose code look like ? Does it try to Or maybe it's some shape of SIMD that we don't have on WASM yet? |
That's a compiler-generated dispose method for an async iterator. Here's what it looks like in sharplab. [DebuggerHidden]
ValueTask IAsyncDisposable.DisposeAsync()
{
if (<>1__state >= -1)
{
throw new NotSupportedException();
}
if (<>1__state == -2)
{
return default(ValueTask);
}
<>w__disposeMode = true;
<>v__promiseOfValueOrEnd.Reset();
<<Prepend>g__Impl|0_0>d<TSource> stateMachine = this;
<>t__builder.MoveNext(ref stateMachine);
return new ValueTask(this, <>v__promiseOfValueOrEnd.Version);
} It does not do any synchronous blocking.
There's no use of SIMD in this library. |
DisposeAsync doesn't, but I just pushed a commit that removes three occurrences of calls to an xunit |
@stephentoub question, why is for example TSource not annotated with allows ref struct when appropriate?, asking cause I have a library with ref struct as TSource. |
Can you share the cases you see where it would be appropriate? |
My open source csv library Sep, where row or column points to internal state that should not be stored on heap, to avoid programmer errors or similar. It seems backwards to me to ask for use case, though, why should TSource not be allowed ref struct when no issue with it? Use cases will come, can't predict all. |
I'm asking about which methods in this PR it would be relevant to. It wouldn't work for anything using an async iterator where the value would be yielded or otherwise captured, for example. Are you specifically asking about TSource rather than TResult and in cases where it wouldn't need to be stored, passed through a value task, etc? |
Yes with regards to TSource, Count() is an example, Sum(), Select() presumably too. I don't have a complete list. I'd suggest this being added also to sync LINQ, where also issue, afaik. |
Please feel free to open an API proposal for it. Note that as the code is written, most of those won't actually compile, either. It'd require either rewriting to not use WithCancellation and friends, or updating those as well to also support ref structs. |
How? |
They both do in .NET 9. |
Ah, I didn't realize. It's not shown on the documentation. https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.iasyncenumerable-1?view=net-9.0 |
API proposal #111830 |
Closes #79782
For the implementation, I've favored clarity/simplicity over lots of optimizations we don't know to be valuable in this context. We can add more specialization in as we see a strong need. The equation for LINQ over IAsyncEnumerable is different for over IEnumerable, where a) we're typically dealing with asynchronous streams of data rather than in-memory, contiguous collections and b) efficient implementations of the interfaces are complicated.
For the tests, I've mainly used the equivalent LINQ functionality as an oracle.
cc: @eiriktsarpalis, @idg10, @HowardvanRooijen