Skip to content

[cxx-interop] Import rvalue references as consuming parameters #77878

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
Dec 3, 2024

Conversation

Xazax-hun
Copy link
Contributor

Unfortunately, importing them as is results in ambiguous call sites. E.g., std::vector::push_back has overloads for lvalue reference and rvalue reference and we have no way to distinguish them at the call site in Swift. To overcome this issue, functions with rvalue reference parameters are imported with 'consuming:' argument labels.

Note that, in general, move only types and consuming is not properly supported in Swift yet. We do not invoke the dtor for the moved-from objects. This is a preexisting problem that can be observed with move only types before this PR, so the fix will be done in a separate PR. Fortunately, for most types, the moved-from objects do not require additional cleanups.

rdar://125816354

@Xazax-hun Xazax-hun added the c++ interop Feature: Interoperability with C++ label Nov 29, 2024
@Xazax-hun
Copy link
Contributor Author

@swift-ci please smoke test

Copy link
Contributor

@egorzhdan egorzhdan left a comment

Choose a reason for hiding this comment

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

A couple of tiny comments, otherwise LGTM!

@@ -2448,7 +2449,7 @@ ClangImporter::Implementation::importParameterType(
return std::nullopt;
} else if (isa<clang::ReferenceType>(paramTy) &&
isa<clang::TemplateTypeParmType>(paramTy->getPointeeType())) {
// We don't support rvalue reference / universal perfect ref, bail.
// We don't universal perfect ref, bail.
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo: missing support

Unfortunately, importing them as is results in ambiguous call sites.
E.g., std::vector::push_back has overloads for lvalue reference and
rvalue reference and we have no way to distinguish them at the call site
in Swift. To overcome this issue, functions with rvalue reference
parameters are imported with 'consuming:' argument labels.

Note that, in general, move only types and consuming is not properly
supported in Swift yet. We do not invoke the dtor for the moved-from
objects. This is a preexisting problem that can be observed with move
only types before this PR, so the fix will be done in a separate PR.
Fortunately, for most types, the moved-from objects do not require
additional cleanups.

rdar://125816354
@Xazax-hun Xazax-hun force-pushed the gaborh/import-rval-ref branch from cffa122 to 1601564 Compare December 2, 2024 13:09
@Xazax-hun
Copy link
Contributor Author

@swift-ci please smoke test

Copy link
Contributor

@egorzhdan egorzhdan left a comment

Choose a reason for hiding this comment

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

LGTM!

@Xazax-hun Xazax-hun merged commit b744793 into main Dec 3, 2024
3 checks passed
@Xazax-hun Xazax-hun deleted the gaborh/import-rval-ref branch December 3, 2024 16:14
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