Skip to content
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

Run all MatchType reduction under Mode.Type #17937

Merged
merged 1 commit into from
Jun 23, 2023

Conversation

dwijnand
Copy link
Member

@dwijnand dwijnand commented Jun 7, 2023

Transcribing and paraphrasing from @smarter's comment in
#16408 (comment) :

Type erasure assumes method signatures aren't simplified, since
simplification logic is implementation-defined. For instance, some
intersection types can be simplified down, but intersection types and
their simplification can erase to different types - prefering classes
over traits, for instance (for Java interop, as it matches Java's
erasure).

Also note, simplify doesn't simplify intersections and unions in Type
mode. But Match Types will cache their reduction without considering
the type mode as a cache input, thus the simplified reduction leaks even
when called in Type mode.

So we call simplified in Mode.Type, in both cases (another desire), so
only that result is cached instead.

Using normalise doesn't work because, for example, that doesn't
normalise match types that are applied type args (e.g. args of Pair).
And not caching the result of those reductions means that they'll get
repeat over and over.

@dwijnand dwijnand linked an issue Jun 7, 2023 that may be closed by this pull request
@dwijnand dwijnand changed the title Change MT reduction to call normalized rather than simplified Change MT reduction to simplify with Mode.Type Jun 8, 2023
@dwijnand dwijnand self-assigned this Jun 19, 2023
There are a number of calls to ".simplified", which changes behaviour
based on Mode.Type.  It does _less_ under Mode.Type, so we
conservatively call it all under Mode.Type.

Transcribing and paraphrasing from smarter's comment in
scala#16408 (comment) :

Type erasure assumes method signatures aren't simplified, since
simplification logic is implementation-defined.  For instance, some
intersection types can be simplified down, but intersection types and
their simplification can erase to different types - prefering classes
over traits, for instance (for Java interop, as it matches Java's
erasure).

Also note, simplify doesn't simplify intersections and unions in Type
mode.  But Match Types will cache their reduction without considering
the type mode as a cache input, thus the simplified reduction leaks even
when called in Type mode.

So we call simplified in Mode.Type, in both cases (another desire), so
only that result is cached instead.

Using normalise doesn't work because, for example, that doesn't
normalise match types that are applied type args (e.g. args of Pair).
And not caching the result of those reductions means that they'll get
repeat over and over.
@dwijnand dwijnand changed the title Change MT reduction to simplify with Mode.Type Run all MatchType reduction under Mode.Type Jun 20, 2023
@dwijnand dwijnand marked this pull request as ready for review June 21, 2023 09:55
@dwijnand dwijnand assigned smarter and unassigned dwijnand Jun 21, 2023
@dwijnand dwijnand requested a review from smarter June 21, 2023 09:56
@bblfish
Copy link

bblfish commented Jun 22, 2023

I look forward to a nightly build or something where I can try this out :-)

@smarter smarter merged commit b461c94 into scala:main Jun 23, 2023
17 checks passed
@dwijnand dwijnand deleted the mt/normalize-reducitons branch June 23, 2023 08:04
@Kordyjan Kordyjan added this to the 3.4.0 milestone Aug 1, 2023
This pull request was closed.
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.

Problem with Traits not being Matchable
5 participants