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

Dealias an applied match alias #19854

Closed
wants to merge 2 commits into from

Conversation

dwijnand
Copy link
Member

@dwijnand dwijnand commented Mar 2, 2024

Fixes #19821

Builds on #19867

dwijnand added 2 commits March 4, 2024 12:05
This patch fixes a recursion situation in collectParts, by
reimplementing a previous fix.  Recursion is already attempted to be
cutoff with `partSeen`, and `handleRecursion` is also used to prevent
any unhandled recursion situations (like the one fixed here) from
crashing the compiler.

For context, AppliedType aren't hash-consed (i.e. the flyweight pattern)
which means that every time you apply the same type arguments to the
same type constructor you get a fresh AppliedType.  Using i18171 as an
example, the sequence of events where this matters is:

0. When typing BAZ, so much earlier than the collectParts call, because
   the MatchType on the rhs of BAZ reduces at definition site, the RHS
   is reduced to the `DFVal[BAZREC[T]]`, which means that BAZ's info is
   a TypeAlias rather than a MatchAlias, meaning it can dealias.
1. `BAZREC[Any]` is extracted by MatchType.InDisguise, which applies the
   Any to return a fresh MatchType
2. `Tuple.Map[Any, BAZ]` is also extracted by MatchType.InDisguise,
   which returns its own fresh MatchType
3. `BAZ[h]` dealiases to a fresh `DFVal[BAZREC[h]]` instance (see step 0)
4. `BAZREC[h]` is extracted by MatchType.InDisguise, repeating the cycle

The reason that the cases with MatchType.InDisguise and MatchType were
introduced is i17395.  Looking back, it seems the only need is to
capture any parts that are in the reduction of an applied MatchType.
With this patch applied in the case of i18171, this now cuts off
quickly, as `BAZREC[Any]` doesn't reduce to anything.  In the case of
i17395, `ExtractPart[ValuePartHolder]` reduces to `Value`, so `Value` is
successfully recorded as a part.
@dwijnand dwijnand force-pushed the dealias-applied-match-alias branch from 38d2524 to 64d6ec7 Compare March 4, 2024 12:54
@dwijnand dwijnand marked this pull request as ready for review March 4, 2024 15:21
@dwijnand dwijnand requested a review from EugeneFlesselle March 4, 2024 15:22
@dwijnand
Copy link
Member Author

Let's go with #19871

@dwijnand dwijnand closed this Mar 12, 2024
@dwijnand dwijnand deleted the dealias-applied-match-alias branch March 12, 2024 11:25
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.

Match type scrutinee is not dealiased (enough)
2 participants