Skip to content

[6.0] Sema: Fix existential-metatype-to-Any conversion #72808

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

Conversation

slavapestov
Copy link
Contributor

@slavapestov slavapestov commented Apr 3, 2024

6.0 cherry-pick of #72762 and #72789.

  • Description: The type checker incorrectly used the instance type of a metatype instead of the metatype itself when looking up a conformance, which caused an invariant violation in the SILCloner. This PR supersedes an earlier workaround. This PR also cherry-picks some regression tests for bugs that are already fixed on the 6.0 branch.

  • Scope of the issue: Various projects hit this specifically with the any Any.Type to Any conversion.

  • Origination: This was a regression since enablement of non copyable generics and didn't ship in a release.

  • Radar: rdar://125460667

  • Reviewed by: @kavon

We were incorrectly unwrapping too many levels of metatype, and
our ErasureExpr would end up with conformances for the instance
type and not the metatype itself.

In the old universe, this was not a problem, but now Any has two
protocol conformance members, so suddently this violated invariants.

This was a regression, introduced in 6027bf4.

Fixes rdar://125460667.
When erasing a pseudogeneric value in SILGen, we actually treat
the value as if it had the type `any AnyObject`, while in Sema,
it's an archetype. This requires SILGen to look up conformances
again instead of using the ones in the ErasureExpr.
We should check if the type parameter actually conforms to our
protocol before we do the global lookup, otherwise we might
return an abstract conformance instead of an invalid conformance.

I don't know if there's any way to exercise this today though.
I didn't realize it at the time, but this was actually fixed by
bc85d66.
@slavapestov slavapestov requested a review from a team as a code owner April 3, 2024 18:57
@slavapestov
Copy link
Contributor Author

@swift-ci Please test

@slavapestov slavapestov merged commit 061eaed into swiftlang:release/6.0 Apr 4, 2024
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