Skip to content

Conversation

@hamishknight
Copy link
Contributor

@hamishknight hamishknight commented Feb 10, 2022

We currently permit (but warn on) coercions of collections with unrelated element types in certain cases. This is done in an effort to preserve compatibility with pre-5.3 compilers that may have allowed such code to compile due to dropping constraints while solving (#30886).

This is limited to collection coercions as we emit somewhat reasonable code for them that performs a force cast of the elements at runtime. However, it turns out that in the case of collection literals, we peephole the element conversions in CSApply, leading to codegen crashes. As such, narrow down the condition of this compatibility logic to not apply to collection literals, as this never would have compiled properly.

Additionally, disable the compatability logic altogether in Swift 6 mode.

rdar://88334481

@hamishknight
Copy link
Contributor Author

@swift-ci please test

@hamishknight
Copy link
Contributor Author

@swift-ci please test source compatibility

Remove the unused `choice` parameter.
We currently permit (but warn on) coercions of
collections with unrelated element types in
certain cases. This is done in an effort to preserve
compatibility with pre-5.3 compilers that may have
allowed such code to compile due to dropping
constraints while solving.

This is limited to collection coercions as we
emit somewhat reasonable code for them that
performs a force cast of the elements at runtime.
However, it turns out that in the case of collection
literals, we peephole the element conversions in
CSApply, leading to codegen crashes. As such,
narrow down the condition of this compatibility
logic to not apply to collection literals, as this
never would have compiled properly.

rdar://88334481
This was only intended to preserve compatibility
for cases where the constraint system may have
previously accepted invalid code. Drop it in Swift 6
mode such that invalid collection coercions become
errors.
@hamishknight
Copy link
Contributor Author

@swift-ci please smoke test

@slavapestov
Copy link
Contributor

Can you disable the compatibility hack altogether in -swift-version 6 mode?

@hamishknight
Copy link
Contributor Author

@slavapestov Yup, 04b37ae does that. Let me add it to the PR description

@hamishknight hamishknight merged commit 6ea8763 into swiftlang:main Feb 11, 2022
@hamishknight hamishknight deleted the shortsighted branch February 11, 2022 10:52
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