-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[6.1][TypeChecker/SILGen] Allow any Sendable
to match Any
while matching generic arguments
#78272
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
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…ndable` Prevent generic arguments from being assigned `any Sendable` directly, that should only happen through inference. This is required because we allow `any Sendable` -> `Any` conversion in modes without strict concurrency enabled to maintain source compatibility and let the developers annotate existing APIs with `any Sendable` and other concurrency attributes. (cherry picked from commit 17093b3)
…ic arguments Allow `any Sendable` to match `Any` constraint while matching generic arguments i.e. `[any Sendable]` -> `[Any]` when `any Sendable` type comes from context that involves `@preconcurrency` declarations in non-strict concurrency compiler mode. Note that it's currently impossible to figure out precisely where `any Sendable` type came from. (cherry picked from commit c6a8cbf)
`UnsafeCastExpr` - A special kind of conversion that performs an unsafe bitcast from one type to the other. Note that this is an unsafe operation and type-checker is allowed to use this only in a limited number of cases like: `any Sendable` -> `Any` conversions in some positions, covariant conversions of function and function result types. (cherry picked from commit 1a5f00b)
…c arguments In non-strict concurrency mode when `@preconcurrency` declarations are involved `any Sendable` should be treated as `Any` in generic argument positions to support passing types that (partially) adopted concurrency annotations to types that haven't yet done so. (cherry picked from commit 5e08f7e)
…ith ManagedValue (cherry picked from commit cc13060)
Forwarding cast handles ownership correctly and doesn't disable optimizations unlike bitcast. (cherry picked from commit c4e4d4d)
… container types (cherry picked from commit a8146d6)
…ainst marker protocol This indicates that the type doesn't have appropriate annotations i.e. for concurrency or ownership. (cherry picked from commit 6f967da)
…of generic arguments Conversion restrictions like "deep equality" could produce a more narrow/actionable fixes. (cherry picked from commit 0772e4c)
…e same This helps to avoid spurious failures pointing to involved pattern types because they won't match exactly if shape types are not the same. (cherry picked from commit fb54682)
…ion in non-strict concurrency contexts (cherry picked from commit c8f3524)
…ction argument/result positions in generic argument context (cherry picked from commit 0de9e9c)
…l language modes (cherry picked from commit a2f711c)
any Sendable
to match Any
while matching generic arguments
@swift-ci please test |
…ected output format `struct_extract` and `unchecked_trivial_bit_cast` instructions are printed slightly differently on main.
@swift-ci please test |
airspeedswift
approved these changes
Dec 20, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Cherry-pick of #78171
Explanation:
It's currently impossible for libraries to adopt
any Sendable
in some positionswhen the type was
Any
before.For example if library had a member of dictionary type like:
and users added extensions to MyAPI that reflect the fact that
Value
genericparameter is always
Any
:It won't be possible for the authors of MyAPI to change value type to
any Sendable
i.e.
@preconcurrency public let myInfo: [String: any Sendable]
,while adopting type to Swift concurrency, without breaking existing clients.
To address this, allow
any Sendable
to matchAny
constraint while matchinggeneric arguments i.e.
[any Sendable]
->[Any]
whenany Sendable
type comes from context that involves
@preconcurrency
declarations.To facilitate that we need a new expression that models an unsafe bitcast
from one type to the other -
UnsafeCastExpr
. This expression is goingto be introduced by the solver during solution application phase to
erase
any Sendable
toAny
in generic argument positions.Main Branch PR: [TypeChecker/SILGen] Allow
any Sendable
to matchAny
while matching generic arguments #78171Resolves: rdar://140300022
Risk: Low (This is a narrow fix that applies only to generic argument contexts of @preconcurrency declarations and is limited to
any Sendable
->Any
directional conversions).Reviewed By: @hborla @atrick
Testing: Added new tests to the concurrency, SILGen, and interpreter test suites.