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

Clean up the way we read recursive types. #291

Merged
merged 3 commits into from
Apr 25, 2023

Conversation

sjrd
Copy link
Contributor

@sjrd sjrd commented Apr 25, 2023

For RecType/RecThis, use the infrastructure for enclosing binders in the localCtx, like we do for LambdaTypes.

For the THIS references to the enclosing refinement class, we now create the magic refinement class symbols along with all the other symbols, and then we specially treat REFINEDtpt in readType position to fetch that symbol.

For `RecType`/`RecThis`, use the infrastructure for enclosing
binders in the `localCtx`, like we do for `LambdaType`s.

For the `THIS` references to the enclosing refinement class, we
now create the magic refinement class symbols along with all the
other symbols, and then we specially treat `REFINEDtpt` in
`readType` position to fetch that symbol.
@sjrd sjrd requested a review from bishabosha April 25, 2023 09:59
@@ -1185,6 +1183,15 @@ private[tasties] class TreeUnpickler(
val scrutinee = readType
val cases: List[MatchTypeCase] = reader.until(end)(readMatchTypeCase)
MatchType(upperBound, scrutinee, cases)
case REFINEDtpt =>
Copy link
Member

Choose a reason for hiding this comment

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

what's the test case that exercises this?

Copy link
Member

@bishabosha bishabosha Apr 25, 2023

Choose a reason for hiding this comment

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

or at least what's some source code to reproduce tasty with this in type position?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Any refinement type tree written in the source code that contains a recursive this reference. We already have tests for that. The this references are THIS nodes containing a SHAREDtype that points to the REFINEDtpt. It's absurd, IMO, but that's how it is.

Copy link
Member

Choose a reason for hiding this comment

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

ok that makes sense

Previously, a different `sharedTypesCache` was created for every
instance of `TreeUnpickler`... which means at every `fork`. The
cache was therefore not used in many cases where it should be.

Now, we make sure to preserve caches across instances of
`TreeUnpickler`.
See the comment for the rationale.

This was found in the wild (in the published artifacts of
`perspective` in particular) but it is not clear how to reproduce
it.
@sjrd
Copy link
Contributor Author

sjrd commented Apr 25, 2023

I added two more commits that support more recursive stuff.

@sjrd sjrd requested a review from bishabosha April 25, 2023 13:34
throw TastyFormatException(s"Unexpected member $otherDef in refinement type")
}
RefinedTypeTree(parent, refinements, cls)(spn)
/* It is possible to find SHAREDterm's referencing REFINEDtpt's.
Copy link
Member

@bishabosha bishabosha Apr 25, 2023

Choose a reason for hiding this comment

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

I thought the point of SHAREDterm and SHAREDtype is that its literally a shared reference that the parser should reuse, and never re-parse - aka tasty ast should not have observable mutability :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You might think so, but even dotc disagrees. It truly caches Types, but it re parses Trees and TypeTrees. And in this case, it will in fact re parse trees defining the same symbols, creating something wrong in the compiler. 🤷‍♂️

@bishabosha bishabosha merged commit 9b7492b into scalacenter:main Apr 25, 2023
@sjrd sjrd deleted the clean-up-reading-rec-types branch April 25, 2023 14:28
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.

2 participants