Skip to content

[CSApply] Allow marker existential to superclass conversions #75628

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
Aug 2, 2024

Conversation

xedin
Copy link
Contributor

@xedin xedin commented Aug 1, 2024

If existential is a protocol composition type where all of the protocols are @_marker, narrowly allow coercion to its superclass bound (if it matches). Both types have the same representation which makes it okay.

This is only a problem in Swift 5 mode without strict concurrency checks. In this mode @preconcurrency stripping happens outside of the solver which means that no conversion restrictions are recorded for members that got & Sendable stripped from their types.

For example:

struct S {
  @preconcurrency static let member: KeyPath<String, Int> & Sendable
}

func test() {
  _ = S.member
}

Since member is @preconcurrency its type would get concurrency annotations stripped, which includes & Sendable which means that the solver uses KeyPath<String, Int> type for the reference and not the original KeyPath<String, Int> & Sendable, this is a problem for ExprRewritter::adjustTypeForDeclReference because conversion between existential and its superclass bound requires a constraint restriction which won't be available in this case.

Resolves: rdar://132700409

If existential is a protocol composition type where all of the
protocols are `@_marker`, narrowly allow coercion to its superclass
bound (if it matches). Both types have the same representation
which makes it okay.

This is only a problem in Swift 5 mode without strict concurrency
checks. In this mode `@preconcurrency` stripping happens
outside of the solver which means that no conversion restrictions
are recorded for members that got `& Sendable` stripped from
their types.

For example:

```swift
struct S {
  @preconcurrency static let member: KeyPath<String, Int> & Sendable
}

func test() {
  _ = S.member
}
```

Since `member` is `@preconcurrency` its type would get concurrency
annotations stripped, which includes `& Sendable` which means that
the solver uses `KeyPath<String, Int>` type for the reference and
not the original `KeyPath<String, Int> & Sendable`, this is a problem
for `ExprRewritter::adjustTypeForDeclReference` because conversion
between existential and its superclass bound requires a constraint
restriction which won't be available in this case.

Resolves: rdar://132700409
@xedin xedin requested review from ktoso and hborla as code owners August 1, 2024 19:41
@xedin
Copy link
Contributor Author

xedin commented Aug 1, 2024

@swift-ci please test

@xedin
Copy link
Contributor Author

xedin commented Aug 1, 2024

@swift-ci please test source compatibility

@xedin
Copy link
Contributor Author

xedin commented Aug 2, 2024

@swift-ci please test Linux platform

@xedin xedin merged commit d48aecb into swiftlang:main Aug 2, 2024
7 checks passed
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