BREAKING: Remove covariance and LINQ use from Grouping, #1059 - #1066
Conversation
48fd06f to
ffceff5
Compare
|
This old PR has been rebased against latest main. I intend to merge this this coming weekend if there is no further feedback. |
NightOwl888
left a comment
There was a problem hiding this comment.
Not a full review, but there are some old comments that I had in a draft that I am posting so they aren't lost.
There was one issue I found on the first pass where it would have made sense to make a method into an extension method so it could expose the underlying type, but I was unable to locate it when I went back to find it again. I am hoping to locate it while this is still a PR.
This is going to take some dedicated time for a full review, though.
9849a70 to
f0d186b
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR removes covariance and LINQ usage from the Grouping module to align with the original Java code and improve performance. The main changes involve:
- Converting generic covariant interfaces to non-generic interfaces with explicit implementations
- Replacing
IEnumerable<T>withICollection<T>/IList<T>for better performance - Adding casting adapter classes to bridge type conversions
- Breaking
GroupingSearchinto specialized subclasses
Reviewed Changes
Copilot reviewed 30 out of 31 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
Support/CastingSetAdapter.cs |
New adapter class for type-safe casting between set types |
Support/CastingListAdapter.cs |
New adapter class for type-safe casting between list types |
Support/CastingEnumeratorAdapter.cs |
New adapter class for type-safe casting between enumerator types |
Support/CastingCollectionAdapter.cs |
New adapter class for type-safe casting between collection types |
Tests |
Updated test files to use concrete types instead of covariant interfaces |
Grouping |
Refactored interfaces to be non-generic with explicit implementations |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
This still needs XML doc comments, but this breaks the GroupingSearch "god class" into three subclasses that implement a common abstract class. This should allow us to not need covariant interfaces for the return types. In order to randomly switch between these classes with incompatible generic type arguments, the test shows how you can use a delegate to work around this limitation.
…ionGroupingSearch<T> class
…s, one failing test
…ldcard generic erasure for null
|
After several iterations of review and improvement, I now think this PR is good to go. Below is the final PR review by Claude Code (Opus 4.6). My responses follow its review.
My responses: Breaking Public API Without Compatibility Shim (Medium)This is intentional, and "only" breaks prior betas. While we don't relish in breaking changes, it is acceptable during the beta period, and is necessary to accomplish this refactoring. It is also called out as such in the PR title and label (which will put it in a Breaking Changes section of the release notes). Unreachable Null Checks in Factory Methods (Low)The parameter/field are not in a part of the file with nullable checking enabled, so it is possible that these are null in this case currently. Narrow
|
Removes the covariance and LINQ use from Grouping, breaks GroupingSearch into subclasses
Fixes #1059
Description
See #1059 for rationale. This PR breaks GroupingSearch into three child classes (with some abstract base classes for common configuration properties) so that we can remove the covariance in the interfaces that were added to get this working in the original port. This keeps most of the interfaces but makes them non-generic (and thus, not covariant) for cases where you might need to have them in a common variable or collection. These were also needed for usage in the tests, where the test code randomly switches implementations that otherwise would not have common generic type parameters.
LINQ was removed, and
IEnumerable<T>was changed toICollection<T>/IList<T>to match the original Java code. This should improve performance a little bit by being able to reference Count etc. directly.