Skip to content

Re-revert "Make mutable generic collection interfaces implement read-only collection interfaces (#95830)" #115802

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Sergio0694
Copy link
Contributor

Completes #31001

This PR reverts #101644, which reverted #95830, and makes all built-in mutable collection/list/dictionary/set interfaces extend their relative counterparts, using DIMs (default interface method implementations) to implement them by default.

We have been working with the MSVC team, which is currently preparing a fix for this for C++/CLI, so that the change will not cause breaks in WPF applications. The fix will be ingested into a future MSVC update, and we're coordinating with them to ensure the timeline is aligned so it gets ingested in time for .NET 10, leaving enough time to validate things. In the meantime, we're opening this PR to merge the actual runtime/BCL changes earlier, so that we can get additional validation in other scenarios, and to have more time for the broader community to provide feedback as well.

cc. @richlander @tannergooding @stephentoub @jkotas @AaronRobinsonMSFT

@Copilot Copilot AI review requested due to automatic review settings May 20, 2025 20:39
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label May 20, 2025
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-collections
See info in area-owners.md if you want to be subscribed.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR re-applies the change that makes all mutable collection/list/dictionary/set interfaces extend their read-only counterparts via default interface method implementations. It updates LINQ fast-paths, core runtime dispatch, dynamic and collection classes, and adapts existing tests to exercise the new read-only APIs.

  • LINQ: Switch IList<T>/ICollection<T> checks to IReadOnlyList<T>/IReadOnlyCollection<T> in performance-sensitive methods.
  • Core and runtime: Simplify array generic interface method binding and add IReadOnlyDictionary to ExpandoObject.
  • Tests: Introduce CollectionAsserts helpers and wrap read-only interface assertions under #if !NETFRAMEWORK.

Reviewed Changes

Copilot reviewed 37 out of 37 changed files in this pull request and generated 3 comments.

File Description
src/libraries/System.Linq/src/System/Linq/*.cs Replace mutable interface checks with their read-only counterparts.
src/libraries/System.Linq.Expressions/src/System/Dynamic/ExpandoObject.cs Add IReadOnlyDictionary<string, object?> implementation and members.
src/libraries/Common/tests/System/Collections/CollectionAsserts.cs New test helpers to assert both mutable and read-only interface behavior.
src/coreclr/vm/array.cpp Simplify generic array interface dispatch; remove slot-based lookup.
Comments suppressed due to low confidence (1)

src/libraries/Common/tests/System/Collections/CollectionAsserts.cs:13

  • [nitpick] Many helper methods repeat the pattern of asserting on both mutable and read-only interfaces; consider consolidating the #if !NETFRAMEWORK block into a single helper or method attribute to reduce duplication.
internal static class CollectionAsserts

@jkotas
Copy link
Member

jkotas commented May 20, 2025

In the meantime, we're opening this PR to merge the actual runtime/BCL changes earlier

I do not see how we can merge this before the MSVC fixes are released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.Collections blocked Issue/PR is blocked on something - see comments community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants