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

Fix #401: Avoid asSeenFrom for types/bounds that don't depend on the prefix. #404

Merged
merged 3 commits into from
Nov 30, 2023

Conversation

sjrd
Copy link
Contributor

@sjrd sjrd commented Nov 29, 2023

This mostly acts as a fast path. However, for the particular case of static recursive match types, it more critically cuts some infinite recursion.

Normally, when a match type refers to itself, it would do so through a ThisType. Computing asSeenFrom for a ThisType prefix already cuts the infinite recursion because it is, by construction, a no-op.

However, for static recursive match types, the compiler makes them refer to themselves through their public, static prefix. This caused the infinite recursion observed in #401.

To avoid the issue, we use another shortcut to asSeenFrom: if the type we map over does not contain any ThisType, we also know it will be a no-op. We store that as a lazy val isPrefixDependent of TermSymbol and TypeMemberSymbol, so that they can take a short cut in {type,bounds}AsSeenFrom.

@sjrd sjrd requested a review from adpi2 November 29, 2023 14:33
…end on the prefix.

This mostly acts as a fast path. However, for the particular case
of static recursive match types, it more critically cuts some
infinite recursion.

Normally, when a match type refers to itself, it would do so
through a `ThisType`. Computing `asSeenFrom` for a `ThisType`
prefix already cuts the infinite recursion because it is, by
construction, a no-op.

However, for static recursive match types, the compiler makes them
refer to themselves through their public, static prefix. This
caused the infinite recursion observed in scalacenter#401.

To avoid the issue, we use another shortcut to `asSeenFrom`: if
the type we map over does not contain any `ThisType`, we also
know it will be a no-op. We store that as a lazy val
`isPrefixDependent` of `TermSymbol` and `TypeMemberSymbol`, so
that they can take a short cut in `{type,bounds}AsSeenFrom`.
@sjrd sjrd force-pushed the fix-recursive-match-types-as-seen-from branch from 6b50872 to 060847e Compare November 29, 2023 14:43
Copy link
Member

@adpi2 adpi2 left a comment

Choose a reason for hiding this comment

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

LGTM!

@sjrd sjrd merged commit 1aca135 into scalacenter:main Nov 30, 2023
4 checks passed
@sjrd sjrd deleted the fix-recursive-match-types-as-seen-from branch November 30, 2023 09:04
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