Skip to content

[cxx-interop] Estend _SwiftifyImport with basic std::span support #78352

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 1 commit into from
Jan 3, 2025

Conversation

Xazax-hun
Copy link
Contributor

This is a preliminary PR to transform nonescaping std::span parameters to Swift's Span type in safe wrappers. To hook this up with ClangImporter, we will need generalize the noescape attribute to non-pointer types (PR is already in review). To transform potentially escaping spans and spans in the return position, a follow-up PR will add lifetime annotation support. This is a building block towards rdar://139074571.

@Xazax-hun Xazax-hun added the c++ interop Feature: Interoperability with C++ label Dec 23, 2024
@Xazax-hun Xazax-hun requested a review from a team as a code owner December 23, 2024 12:37
This is a preliminary PR to transform nonescaping std::span parameters
to Swift's Span type in safe wrappers. To hook this up with
ClangImporter, we will need generalize the noescape attribute to
non-pointer types (PR is already in review). To transform potentially
escaping spans and spans in the return position, a follow-up PR will
add lifetime annotation support. This is a building block towards
rdar://139074571.
@Xazax-hun Xazax-hun force-pushed the gaborh/cxx-span-overload branch from d65bf9b to b0bb995 Compare December 23, 2024 14:08
@Xazax-hun
Copy link
Contributor Author

@swift-ci please smoke test

for (idx, param) in signature.parameterClause.parameters.enumerated() {
let typeName = try getTypeName(param.type).text;
if let desugaredType = typeMappings[typeName] {
if desugaredType.starts(with: "span") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will cause an issue if any type alias from C/C++ where the desugared type starts with "span", right? It's probably a good idea to add a cxxSpan option to the _SwiftifyInfo enum.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I wanted to update this code snippet. I don't think we need an enum for this, but I'll make the name matching more precise.

Copy link
Contributor Author

@Xazax-hun Xazax-hun Jan 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the meantime, I am working on a follow-up PR. The content of the string we are matching against depends on how we generate the typeMapping in ClangImporter. Would you be OK if this part would stay as is and I only changed it in the follow up where this starts to work end to end? Alternatively, I can backport some code to this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The follow-up PR where this logic changes: #78422

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That works for me!

@Xazax-hun Xazax-hun merged commit 6e84b8f into main Jan 3, 2025
3 checks passed
@Xazax-hun Xazax-hun deleted the gaborh/cxx-span-overload branch January 3, 2025 14:32
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