Skip to content

New footprint calculation scheme #19639

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 2 commits into from
Feb 14, 2024
Merged

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Feb 7, 2024

Since match type reduction is expensive, it is cached. If a type is reduced (or not reduced) in tryNormalize we remember that decision and return the previous result - unless something in the context changed since the last attempt which could lead to a different outcome. Relevant here are:

  • constraints (regular and GADT) over type parameters
  • instantations of type variables

We keep track of these things in a so-called footprint calculation.

The old calculation clearly did not work. It either never worked or was broken by the changes to matchtype reduction.

I now changed it to a more straightforward scheme that computes the footprint directly instead of relying on TypeComparer to produce the right trace.

@odersky odersky marked this pull request as draft February 7, 2024 10:44
@odersky odersky force-pushed the fix-matchtype-footprint branch from 21fb6cb to 84ace9e Compare February 7, 2024 17:26
The old one clearly did not work. It either never worked or was
disabled by the changes to matchtype reduction.

I now changed it to a more straightforward scheme that computes the
footprint directly instead of relying on TypeComparer to produce the
right trace.
# Conflicts:
#	compiler/src/dotty/tools/dotc/core/Types.scala
@odersky odersky force-pushed the fix-matchtype-footprint branch from 84ace9e to d6ba9b2 Compare February 9, 2024 18:00
@odersky odersky marked this pull request as ready for review February 9, 2024 18:43
@odersky odersky requested a review from sjrd February 10, 2024 11:40
@odersky
Copy link
Contributor Author

odersky commented Feb 10, 2024

Looking at the code, I think the old footprint calculation probably did work, but was bypassed by the new matchtype implementation since it is now formulated in terms of baseType instead of subtyping constraints.

Copy link
Member

@sjrd sjrd left a comment

Choose a reason for hiding this comment

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

Beautiful. That is so much clearer than before!

@sjrd sjrd merged commit f95b57c into scala:main Feb 14, 2024
@sjrd sjrd deleted the fix-matchtype-footprint branch February 14, 2024 12:42
EugeneFlesselle added a commit to EugeneFlesselle/dotty that referenced this pull request Mar 25, 2024
This is another case which used to result in an unreported `ErrorType`
It is now detected only when enabling `-Yforce-sbt-phases -Xverify-signatures -Ycheck:all`

The error comes from:
```scala
type Names[X <: AnyNamedTuple] <: Tuple = X match
  case NamedTuple[n, _] => n
```
The `NamedTuple` pattern is legal as long as the type alias is opaque.
Following elimOpaque however, it is beta-reduced (as normal applied type aliases in match type patterns)
to a pattern which no longer contains an instance of the type capture `n`, making it an illegal pattern.
This used to return an `ErrorType`, which happened not be reported as in the other cases.

Also note this error could also be missed without the New footprint calculation scheme (scala#19639)

Given the changes to the footprint calculation and failed reduction reporting,
this is now the same issue as scala#19434.
@Kordyjan Kordyjan added this to the 3.4.2 milestone Mar 28, 2024
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.

3 participants