Skip to content

Conversation

@Lluc24
Copy link

@Lluc24 Lluc24 commented Nov 20, 2025

Closes #24120: Refactor: Move MatchReducer to its own file

  • Decoupled File Structure: MatchReducer has been moved from TypeComparer.scala to a dedicated file: compiler/src/dotty/tools/dotc/core/MatchReducer.scala. The code movement is isolated in its own commit.
  • Inheritance Rationale: 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.
  • Cleanup: Removed the originating TODO comment from TypeComparer.scala.
  • Git History & Blame:
    • Why not .git-blame-ignore-revs? I did not add this commit to the ignore list because that mechanism forces Git to look at the file state immediately before the commit. Since MatchReducer.scala did not exist before this commit, Git hits a "dead end" and cannot trace the history back to TypeComparer.scala.
    • GitHub Limitation: The GitHub Web UI does not run git blame -C (copy detection) and will incorrectly display me as the author of the moved lines. To verify the original authors (Martin Odersky, etc.), please run the following locally:
git blame -C compiler/src/dotty/tools/dotc/core/MatchReducer.scala

MatchReducer modifies caseLambda variable of the superclass, and this modification is later needed when invoking methods of TypeComparer:

// compiler/src/dotty/tools/dotc/core/MatchReducer.scala, line 328
def matchLegacyPatMat(spec: MatchTypeCaseSpec.LegacyPatMat): MatchResult =
 val caseLambda = constrained(spec.origMatchCase, ast.tpd.EmptyTree)._1.asInstanceOf[HKTypeLambda]
 this.caseLambda = caseLambda
 ...

Mutable protected state caseLambda:

// compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala, line 44
** Potentially a type lambda that is still instantiatable, even though the constraint
*  is generally frozen.
*/
protected var caseLambda: Type = NoType

@mbovel
Copy link
Member

mbovel commented Nov 24, 2025

In its current state, it seems the .git-blame-ignore-revs doesn't work as expected:

image

Maybe it's due to the merge commit? Or maybe this is just the GitHub UI.

I'd try to rebase to avoid the merge commit, and have three commits: 1. move the match reducer, 2. add the move commit to .git-blame-ignore-revs and 3. remove the the todo (with an explanation in the commit description).

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.
@Lluc24 Lluc24 force-pushed the i24120-move-MatchReducer branch from 9be03a5 to 1e0c4e4 Compare November 26, 2025 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Separate MatchReducer from TypeComparer?

3 participants