Skip to content

[C++-Interop] Import const &T function parameters as @in_guaranteed #61000

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
Sep 14, 2022

Conversation

plotfi
Copy link
Contributor

@plotfi plotfi commented Sep 8, 2022

When passing value types as a const-ref to a C++ API, ensure that the caller is tasked with handling the lifetime of the instance passed in.

@hyp @zoecarver @drodriguez

@drodriguez
Copy link
Contributor

@swift-ci please smoke test

@drodriguez
Copy link
Contributor

Not for this PR necessarily, but we are still missing the one in the allocator/initializer case 😞

@hyp hyp added the c++ interop Feature: Interoperability with C++ label Sep 8, 2022
@plotfi plotfi requested review from zoecarver and hyp September 8, 2022 18:41
@plotfi plotfi force-pushed the const-ref-in_guaranteed branch 2 times, most recently from 8d8fac8 to 8bbf8f9 Compare September 8, 2022 22:13
@plotfi
Copy link
Contributor Author

plotfi commented Sep 8, 2022

Not for this PR necessarily, but we are still missing the one in the allocator/initializer case 😞

Added test/Interop/Cxx/reference/reference-silgen-cxx-objc-ctors+init.swift which shows that the ObjC init is Ok, but the C++ ctor is not getting any sort of @in or @in_guranteed so I added a FIXME to track this. Will file an issue too.

@@ -36,42 +36,34 @@ func testFunction() {

// RUN: %target-swift-frontend -c -enable-experimental-cxx-interop -enable-objc-interop -I %S/Inputs %s -emit-silgen -o - | %FileCheck %s

// COM: FIXME: should it be @in_guaranteed OptionsStruct? https://github.com/apple/swift/issues/60601
// CHECK: [[FN1:%[0-9]+]] = function_ref @$sSo19OptionsConsumerObjCC7optionsABSo0A6StructV_tcfC : $@convention(method) (OptionsStruct, @thick OptionsConsumerObjC.Type) -> @owned OptionsConsumerObjC
Copy link
Contributor

Choose a reason for hiding this comment

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

This one is the one that I was confused. IIUC $sSo19OptionsConsumerObjCC7optionsABSo0A6StructV_tcfC demangles to __C.OptionsConsumerObjC.__allocating_init(options: __C.OptionsStruct) -> __C.OptionsConsumerObjC which seems to be an Obj-C initializer, and it does not have @in nor @in_guaranteed. I don't know if this is required, or in this case it is fine to pass a copy.

But this one is different than in your new test, which shows a non-mangled name. I wonder if the designated initializer bit changes something.

@plotfi plotfi force-pushed the const-ref-in_guaranteed branch from 8bbf8f9 to 25aa850 Compare September 9, 2022 21:29
@bulbazord
Copy link
Contributor

@swift-ci please smoke test

@plotfi plotfi force-pushed the const-ref-in_guaranteed branch from 25aa850 to 834fe9a Compare September 10, 2022 00:50
@drodriguez
Copy link
Contributor

@swift-ci please smoke test

@plotfi
Copy link
Contributor Author

plotfi commented Sep 12, 2022

@hyp Do these changes look ok to you?

When passing value types as a const-ref to a C++ API, ensure that the
caller is tasked with handling the lifetime of the instance passed in.
@plotfi plotfi force-pushed the const-ref-in_guaranteed branch from 834fe9a to 84a69c4 Compare September 12, 2022 20:28
@plotfi
Copy link
Contributor Author

plotfi commented Sep 12, 2022

Addressed your comments @zoecarver

@bulbazord
Copy link
Contributor

@swift-ci please smoke test

Copy link
Contributor

@hyp hyp left a comment

Choose a reason for hiding this comment

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

LGTM

@plotfi plotfi merged commit 789e695 into swiftlang:main Sep 14, 2022
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.

5 participants