Skip to content

🍒[cxx-interop] Make std::string::append usable from Swift and avoid crashing for substitution failures #66805

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
Jun 21, 2023

Conversation

egorzhdan
Copy link
Contributor

@egorzhdan egorzhdan commented Jun 21, 2023

Explanation: This makes std::string::append callable from Swift. Previously this was causing a compiler crash, since it tried to substitute std::string as a templated parameter to an append overload that takes std::string_view as a parameter. This PR also prevents a compiler crash in this kind of cases.
Scope: This adds a Swift function append into the CxxStdlib overlay, and fixes the compiler crash.
Risk: Low, this only has an effect when C++ interop is enabled.

Original PR: #66749

rdar://107018724
(cherry picked from commit 4a1afa9)
(cherry picked from commit 6cd4b7c)

This code used to crash the compiler:

    var s = std.string("hi")
    s.append("foo")

`append` in this case resolves to a templated C++ method that accepts `std::string_view`, while we tried passing a Swift String to it as a parameter.

rdar://107018724
(cherry picked from commit 4a1afa9)
This adds a new Swift overload for `append` that takes another `std::string` as a parameter.

The original C++ overload for `append` is not exposed into Swift because it returns a mutable reference `string&`.

rdar://107018724
(cherry picked from commit 6cd4b7c)
@egorzhdan egorzhdan added the c++ interop Feature: Interoperability with C++ label Jun 21, 2023
@egorzhdan egorzhdan requested a review from a team as a code owner June 21, 2023 13:24
@egorzhdan
Copy link
Contributor Author

@swift-ci please test

@egorzhdan egorzhdan merged commit 9989e6c into release/5.9 Jun 21, 2023
@egorzhdan egorzhdan deleted the egorzhdan/5.9-string-append branch June 21, 2023 21:53
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++
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants