[5.7][stdlib] Work around binary compatibility issues with String index validation fixes in 5.7 #58993
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 picked from #58954)
Explanation: Swift 5.7 added stronger index validation for
String
, so some illegal cases that previously triggered inconsistently diagnosed out of bounds accesses now result in reliable runtime errors. Similarly, attempts at applying an index originally vended by a UTF-8 string on a UTF-16 string now result in a reliable runtime error.As is usually the case, adding new traps to the stdlib exposes some existing code that contains previously undiagnosed / unreliably diagnosed coding issues. This change allows invalid code inside binaries built with earlier versions of the stdlib to continue running with the 5.7 library by disabling some of the new traps based on the version of Swift the binary was built with.
In the case of an index encoding mismatch, allow transcoding of string storage regardless of the direction of the mismatch. (Previously we only allowed transcoding a UTF-8 string to UTF-16.)
Scope:
String
in the Standard Library; binary compatibility.Risk: Medium. While the change is relatively large, it merely loosens the Stdlib's preconditions, allowing entry points to succeed in more cases. The primary risk has to do with the introduction of the new bincompat checks, especially as they come with a new stdlib/runtime interface through
SwiftShims
additions.Issue: rdar://93379333
Reviewer: @glessard