-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Remove TODO in MatchReducer
#24488
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
Merged
Merged
Remove TODO in MatchReducer
#24488
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Member
9be03a5 to
1e0c4e4
Compare
1e0c4e4 to
c9309e7
Compare
The suggested refactoring to composition over inheritance was blocked because MatchReducer requires modifying the mutable protected state (caseLambda) of its superclass, TypeComparer, before invoking dependent inherited methods.
mbovel
reviewed
Dec 4, 2025
mbovel
approved these changes
Dec 4, 2025
lidaisy
pushed a commit
to lidaisy/scala3
that referenced
this pull request
Dec 5, 2025
Closes scala#24120: remove the TODO comment. The TODO comment left by @odersky regarding `MatchReducer` was: https://github.com/scala/scala3/blob/c9309e730b6a261ea9ccc0ba86ca7de59ef3bd59/compiler/src/dotty/tools/dotc/core/TypeComparer.scala#L3597-L3601 ### Keep `MatchReducer` as a `TypeComparer` In the end, we _do_ need `MatchReducer` to be a `TypeComparer`. The refactoring to composition over inheritance was not possible because `MatchReducer` requires modifying the mutable protected field `caseLambda` of its superclass, `ConstraintHandling` (which is a superclass of `TypeComparer`), before invoking inherited methods that depends it. Mutable protected field `caseLambda`: https://github.com/scala/scala3/blob/c9309e730b6a261ea9ccc0ba86ca7de59ef3bd59/compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala#L44-L47 `MatchReducer` modifies `caseLambda` variable of the superclass, and this modification is later needed when invoking methods of TypeComparer: https://github.com/scala/scala3/blob/c9309e730b6a261ea9ccc0ba86ca7de59ef3bd59/compiler/src/dotty/tools/dotc/core/TypeComparer.scala#L3879-L3881 Maybe we could revisit this if we get rid of `matchLegacyPatMat` one day. ### Keep `MatchReducer` in the same file Moving `MatchReducer` to its own file creates significant issues with Git history tracking: - [.git-blame-ignore-revs](https://github.com/scala/scala3/blob/main/.git-blame-ignore-revs) Limitation: This mechanism only works for in-place refactorings. When a file is moved, Git looks at the file state immediately before the commit. Since `MatchReducer.scala` didn't exist before, Git cannot trace the history back to `TypeComparer.scala`. - GitHub UI Limitation: GitHub's web interface does not support `git blame -C` (copy detection), so the GitHub UI would incorrectly show the person who moved the file as the author of all lines, losing attribution to the original authors. - Loss of Context: Keeping `MatchReducer` in the same file as `TypeComparer` makes it easier to understand their tight coupling and why inheritance is necessary. - Local Workaround Required: Users would need to run `git blame -C` locally to see the correct history, which is not ideal for most contributors: ```bash git blame -C compiler/src/dotty/tools/dotc/core/MatchReducer.scala ``` --------- Co-authored-by: Matt Bovel <matthieu@bovel.net>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

Closes #24120: remove the TODO comment.
The TODO comment left by @odersky regarding
MatchReducerwas:scala3/compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Lines 3597 to 3601 in c9309e7
Keep
MatchReduceras aTypeComparerIn the end, we do need
MatchReducerto be aTypeComparer. The refactoring to composition over inheritance was not possible becauseMatchReducerrequires modifying the mutable protected fieldcaseLambdaof its superclass,ConstraintHandling(which is a superclass ofTypeComparer), before invoking inherited methods that depends it.Mutable protected field
caseLambda:scala3/compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala
Lines 44 to 47 in c9309e7
MatchReducermodifiescaseLambdavariable of the superclass, and this modification is later needed when invoking methods of TypeComparer:scala3/compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Lines 3879 to 3881 in c9309e7
Maybe we could revisit this if we get rid of
matchLegacyPatMatone day.Keep
MatchReducerin the same fileMoving
MatchReducerto its own file creates significant issues with Git history tracking:.git-blame-ignore-revs Limitation: This mechanism only works for in-place refactorings. When a file is moved, Git looks at the file state immediately before the commit. Since
MatchReducer.scaladidn't exist before, Git cannot trace the history back toTypeComparer.scala.GitHub UI Limitation: GitHub's web interface does not support
git blame -C(copy detection), so the GitHub UI would incorrectly show the person who moved the file as the author of all lines, losing attribution to the original authors.Loss of Context: Keeping
MatchReducerin the same file asTypeComparermakes it easier to understand their tight coupling and why inheritance is necessary.Local Workaround Required: Users would need to run
git blame -Clocally to see the correct history, which is not ideal for most contributors: