Skip to content

Backporting std::string init for UnsafePointer? fixes to Swift 5.9 #65240

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 2 commits into from
May 6, 2023

Conversation

plotfi
Copy link
Contributor

@plotfi plotfi commented Apr 18, 2023

Backporting std::string init for UnsafePointer? fixes to Swift 5.9

plotfi and others added 2 commits April 17, 2023 21:19
Currently without an initializer for the unsafe char pointer type swiftc
hits an assert around not being able to handle conversions of unsafe
pointers with Any type. This patch adds the ability to convert to a
std::string.

This is to address issue swiftlang#61218

(cherry picked from commit 6180387)
This fixes a build failure that started occurring on CentOS after swiftlang#65057:
```
error: cannot find 'strlen' in scope
```

rdar://107987115
(cherry picked from commit 7774650)
@plotfi plotfi requested a review from a team as a code owner April 18, 2023 01:20
@plotfi plotfi requested review from hyp and egorzhdan April 18, 2023 01:21
@plotfi plotfi added the c++ interop Feature: Interoperability with C++ label Apr 18, 2023
@plotfi plotfi changed the title Release/5.9 Backporting std::string init for UnsafePointer? fixes to Swift 5.9 Apr 18, 2023
@plotfi plotfi requested a review from DougGregor April 18, 2023 01:22
@plotfi
Copy link
Contributor Author

plotfi commented Apr 18, 2023

@egorzhdan If there are no test failures in 5.9 I will leave the lit test as is, but for main I want to drop the name mangling part or replace it with a more robust regex.

@plotfi
Copy link
Contributor Author

plotfi commented Apr 28, 2023

@hyp Sorry for the delay on the Explanation. Will post soon once I get a moment.

@plotfi
Copy link
Contributor Author

plotfi commented Apr 30, 2023

  • Explanation: This fixes the issue where without an explicit unsafe char pointer initializer for String the compiler hits an assert around an Any type being casted as a UnsafePointer. Obviously here the compiler should be handling things better but this avoids the whole issue by providing an explicit swift initializer for the type as we are doing for all of the C++-Interop related additions to the Swift stdlib.

  • Scope: Only to serve use cases relating to C++-Interop.

  • Issue: [C++-Interop] Converting from NSString to std.string directly using .utf8String causes an unreachable in SILGenPoly.cpp #61218

  • Risk: Risk is low, but if there is any issue it would only happen when invoking String() with a type that used to cause a compiler crash/assert.

  • Testing: Lit test is included as well as a unit test.

  • Reviewer: @egorzhdan @hyp @DougGregor @zoecarver

@AnthonyLatsis AnthonyLatsis added 🍒 release cherry pick Flag: Release branch cherry picks swift 5.9 labels May 3, 2023
@drodriguez
Copy link
Contributor

@swift-ci please test

@hyp
Copy link
Contributor

hyp commented May 6, 2023

@swift-ci please test macos platform

@plotfi
Copy link
Contributor Author

plotfi commented May 6, 2023

@swift-ci please test macos platform

Thanks Alex

@plotfi plotfi merged commit f8cc3d4 into swiftlang:release/5.9 May 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ interop Feature: Interoperability with C++ 🍒 release cherry pick Flag: Release branch cherry picks swift 5.9
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants