Skip to content

[CSSyntaticElement] Desugar types before collecting "in scope" type v… #65048

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

Merged
merged 1 commit into from
Apr 11, 2023

Conversation

xedin
Copy link
Contributor

@xedin xedin commented Apr 10, 2023

…ariables

Generic type aliases, unless desugared, could bring unrelated type variables into the scope i.e.
TypeAlias<$T, $U>.Context is actually _Context<$U>. These variables could be inferrable
only after the the body the closure is solved. To avoid that, let's adjust TypeVariableRefFinder
to desugar types before collecting referenced type variables.

Resolves: rdar://107835060

…ariables

Generic type aliases, unless desugared, could bring unrelated type variables
into the scope i.e. `TypeAlias<$T, $U>.Context` is actually `_Context<$U>`.
These variables could be inferrable only after the the body the closure is
solved. To avoid that, let's adjust `TypeVariableRefFinder` to desugar types
before collecting referenced type variables.

Resolves: rdar://107835060
@xedin
Copy link
Contributor Author

xedin commented Apr 10, 2023

@swift-ci please test

@xedin xedin merged commit 6b3a17b into swiftlang:main Apr 11, 2023
// For example `Typealias<$T, $U>.Context` which desugars into
// `_Context<$U>` would bring in `$T` that could be inferrable
// only after the body of the closure is solved.
type = type->getDesugaredType();
Copy link
Contributor

Choose a reason for hiding this comment

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

I think getDesugaredType() only unwraps one level of sugar, but you might have type aliases in nested position. Maybe you should use getCanonicalType() instead? Are other callers of getTypeVariables() also affected by this? Perhaps getTypeVariables() should canonicalize the type itself first.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Other callers of getTypeVariables() don't really care because only closures are solved in isolation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, getDesugaredType would only unwrap N levels of sugar if they occur in sequence... I'll switch this to getCanonicalType().

xedin added a commit to xedin/swift that referenced this pull request Apr 11, 2023
…riables

Follow-up to swiftlang#65048

`getDesugaredType` unwraps sugar types that appear in sequence,
to remove sugar from nested positions we need to get a canonical type.

Thanks to @slavapestov for pointing it out.
xedin added a commit to xedin/swift that referenced this pull request Apr 11, 2023
…riables

Follow-up to swiftlang#65048

`getDesugaredType` unwraps sugar types that appear in sequence,
to remove sugar from nested positions we need to get a canonical type.

Thanks to @slavapestov for pointing it out.
meg-gupta pushed a commit to meg-gupta/swift that referenced this pull request Apr 14, 2023
…riables

Follow-up to swiftlang#65048

`getDesugaredType` unwraps sugar types that appear in sequence,
to remove sugar from nested positions we need to get a canonical type.

Thanks to @slavapestov for pointing it out.
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.

3 participants