Skip to content

[interop][SwiftToCxx] trap on moves of Swift values for now #61224

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 21, 2022

Conversation

hyp
Copy link
Contributor

@hyp hyp commented Sep 21, 2022

Move support will be added later once values are takeable.

@hyp hyp added the c++ interop Feature: Interoperability with C++ label Sep 21, 2022
@hyp hyp requested review from egorzhdan and zoecarver September 21, 2022 14:00
@hyp
Copy link
Contributor Author

hyp commented Sep 21, 2022

@swift-ci please test

printer.printBaseName(typeDecl);
os << "(";
printer.printBaseName(typeDecl);
os << " &&) = default;\n";
os << " &&) { abort(); }\n";
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we emit = delete instead? That might be more helpful for the user since accidentally using the move constructor would be a compile error instead of a runtime error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can't emit delete, as C++ will not compile the elided moves that are not actually runtime moves, that I need to return such type from the thunk wrapper .

Copy link
Contributor Author

Choose a reason for hiding this comment

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

inline SwiftType thunk() {
  auto result = SwiftType::make();
  $swiftFunction(&result);
  return result; // <-- this will not compile if the move constructor is deleted, but it's elided according to C++ rules so it does not trap.
}

Copy link
Contributor

Choose a reason for hiding this comment

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

I see, makes sense, thanks.

@hyp hyp merged commit 6424835 into swiftlang:main Sep 21, 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.

2 participants