-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
[API Proposal]: Employ allows ref struct
in comparer interfaces
#103323
Comments
Tagging subscribers to this area: @dotnet/area-system-collections |
Having written Not sure if there's huge value in propagating this to all collection interfaces though, we did this with @stephentoub thoughts? |
Constraining the
We can't do I'm skeptical of other interfaces like |
@hamarb123 would it be possible to update the API proposal to reflect feedback? |
My understanding is that implementing
I don't really see what the issue is here - are you talking about the non-generic API overloads? Boxing is pretty easy to work around by using |
It is simply not possible to mark the
I wrote "at least not without changing other code in its implementation". If you try to mark the |
Ok, I have updated it - I missed the |
Even if technically feasible, I still question the value of allowing ref structs in the other collection interfaces, ref types seem fundamentally irreconcilable with these abstractions. IEnumerable is different in that respect since it can be used to implement streaming. Which reminds me -- we should add |
Those are already annotated. |
Oh, ok. I thought they had missed the first round. |
I don't think it's fundamentally irreconcilable at all - I think it makes perfect sense to have a readonly list where you're able to lookup a span at any index for example. |
I saw the example that you shared earlier, but I struggle to see how this could be considered a valid collection implementation or where it could be used meaningfully. Perhaps sharing the full implementation + a consuming application might illuminate things a bit more. |
I don't think we should do this for any of the readonly collection ones, either. From my perspective, it's a mistake of history that IReadOnlyCollection doesn't include members like CopyTo, and I'd like to reserve the ability to add those later as DIMs, plus possibly methods like ToArray. Making T here allows ref struct ptevents us from ever doing so. I don't believe the reward outweighs the risk. |
Yeah, okay, makes enough sense, I will remove them.
Sorry, I didn't get a chance to reply to this :) |
allows ref struct
in collections interfacesallows ref struct
in comparer interfaces
EDITED on 6/17/2024 by @stephentoub to add more interfaces
Background and motivation
Similar to #102671.
Similar to #103270.
I discovered this gap as I attempted to pre-emptively implement .NET 9
allows ref struct
on some of my own APIs behind a#if
to see which APIs missing it would cause me problems.We have done the same thing for
IEnumerable<T>
andIEnumerator<T>
already.API Proposal
API Usage
Alternative Designs
Also implement on readonly collection types:
Risks
These are interfaces, so none really.
The text was updated successfully, but these errors were encountered: