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

Conversation

Sergio0694
Copy link
Contributor

@Sergio0694 Sergio0694 commented May 20, 2025

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

@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.

@tannergooding
Copy link
Member

This was approved in tactics today. The C++/CLI issue that previously blocked this was resolved and will be available in a VS release by the time .NET 10 releases.

In the interim, a workaround for dotnet/wpf is required and is here: https://github.com/dotnet/wpf/tree/cppcli-workaround. It will need to be taken as part of the PR that pulls in the newer version of dotnet/runtime containing this change and can be reverted once the CI machines are updated to include the version of C++/CLI with the relevant fix.

A breaking-change doc still needs to be created and this needs to be included in the .NET 10 Preview 6 Release notes.

@tannergooding tannergooding merged commit e55370e into dotnet:main Jun 4, 2025
144 checks passed
@tannergooding tannergooding added breaking-change Issue or PR that represents a breaking API or functional change over a prerelease. needs-breaking-change-doc-created Breaking changes need an issue opened with https://github.com/dotnet/docs/issues/new?template=dotnet and removed blocked Issue/PR is blocked on something - see comments labels Jun 4, 2025
Copy link
Contributor

Added needs-breaking-change-doc-created label because this PR has the breaking-change label.

When you commit this breaking change:

  1. Create and link to this PR and the issue a matching issue in the dotnet/docs repo using the breaking change documentation template, then remove this needs-breaking-change-doc-created label.
  2. Ask a committer to mail the .NET Breaking Change Notification DL.

Tagging @dotnet/compat for awareness of the breaking change.

@tannergooding
Copy link
Member

The breaking change doc issue is logged here: dotnet/docs#46551

We will need to ensure this is included in the .NET 10 Preview 6 release notes and blog post.

tannergooding added a commit to tannergooding/runtime that referenced this pull request Jun 10, 2025
tannergooding added a commit that referenced this pull request Jun 11, 2025
…y collection interfaces" and related changes (#116497)

* Revert "Improve a few more IList/Collection => IReadOnlyList/Collection checks (#116313)"

This reverts commit ba462ce.

* Revert "Use throw stubs in ref assemblies for collection interfaces (#116309)"

This reverts commit 4e03c5a.

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

This reverts commit e55370e.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.Collections breaking-change Issue or PR that represents a breaking API or functional change over a prerelease. community-contribution Indicates that the PR has been added by a community member needs-breaking-change-doc-created Breaking changes need an issue opened with https://github.com/dotnet/docs/issues/new?template=dotnet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants