Rework MatchType recursion in collectParts #19867
Merged
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.
This patch fixes a recursion situation in collectParts, by
reimplementing a previous fix. Recursion is already attempted to be
cutoff with
partSeen
, andhandleRecursion
is also used to preventany 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:
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 isa TypeAlias rather than a MatchAlias, meaning it can dealias.
BAZREC[Any]
is extracted by MatchType.InDisguise, which applies theAny to return a fresh MatchType
Tuple.Map[Any, BAZ]
is also extracted by MatchType.InDisguise,which returns its own fresh MatchType
BAZ[h]
dealiases to a freshDFVal[BAZREC[h]]
instance (see step 0)BAZREC[h]
is extracted by MatchType.InDisguise, repeating the cycleThe 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 ofi17395,
ExtractPart[ValuePartHolder]
reduces toValue
, soValue
issuccessfully recorded as a part.
Fixes #19857
Fixes #18171