Skip to content

[release/6.0] ASTMangler: skip mangling Copyable dependents #76411

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

kavon
Copy link
Member

@kavon kavon commented Sep 11, 2024

  • Explanation: The Swift 6.0 compiler can crash when trying to check if a returned-value conforms to the constraint of an opaque return type. It triggers when a conformance requirement is conditional on Copyable. This results in a regression from Swift 5.10, for example, in the following program:
protocol Marked {
  func announce()
}
extension Marked {
  func announce() {}
}

struct MyType<Wrapped> {}
extension MyType: Marked where Wrapped: Marked {}

extension Optional: Marked {}

func makeWrapper<P>(wrapping _: P.Type) -> some Marked {
    MyType<Optional<P>>()
}

Typically, a conformance that is dependent on a conformance to a marker
protocol never reaches this point in the compiler, where we're mangling
the metadata for an opaque return type.

But with the invertible protocols like Copyable, we do permit them, so
we should avoid mangling Copyable as that's generally ABI incompatible
with existing code.

resolves rdar://135310019

(cherry picked from commit 6f6a46f)
@kavon
Copy link
Member Author

kavon commented Sep 11, 2024

@swift-ci test

@kavon kavon marked this pull request as ready for review September 11, 2024 20:50
@kavon kavon requested a review from a team as a code owner September 11, 2024 20:50
My previous fix in `6f6a46f` was the correct fix in theory, but in
practice it could accidentally change the mangling of something I
haven't considered, which would break ABI with Swift 6.0

I've narrowed that fix here to only affect dependent conformances
specifically for Copyable/Escapable. The existing code in
`appendDependentProtocolConformance` would always reach a trap because
we're mangling a conformance path that ends with Copyable/Escapable.

We can assume no such symbol has been successfully been mangled before,
thanks to the pre-existing skip in `conformanceRequirementIndex`, so
there's no risk of ABI change.

rdar://135310019
(cherry picked from commit 793b46f)
@kavon
Copy link
Member Author

kavon commented Sep 12, 2024

@swift-ci test

@kavon kavon enabled auto-merge September 12, 2024 17:30
@kavon kavon merged commit aaa632c into swiftlang:release/6.0 Sep 13, 2024
5 checks passed
@kavon kavon deleted the release/6.0-ncgenerics-opaque-dependent-conformance-mangling branch September 24, 2024 22:23
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