Skip to content

[cxx-interop] Add support for C++ increment decrement operations #41232

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

Closed

Conversation

cabmeurer
Copy link
Contributor

@cabmeurer cabmeurer commented Feb 6, 2022

Support imported C++ ++ and -- operators in Swift.

Refs #32333

@cabmeurer
Copy link
Contributor Author

cabmeurer commented Feb 6, 2022

@hyp
@zoecarver

@zoecarver zoecarver added the c++ interop Feature: Interoperability with C++ label Feb 7, 2022
@zoecarver zoecarver self-assigned this Feb 7, 2022
@zoecarver
Copy link
Contributor

@swift-ci please smoke test.

@zoecarver
Copy link
Contributor

This looks great! Thank you!

@zoecarver
Copy link
Contributor

@swift-ci please smoke test.

@zoecarver
Copy link
Contributor

(You don't have to update this PR but) for future PRs, would you mind squashing all your commits into one commit? (Or one commit per "thing," i.e., one commit for increment and one commit for decrement.)

Thanks again for your contribution!

@cabmeurer
Copy link
Contributor Author

For sure! Happy to help where I can! 🙌

Copy link
Contributor

@zoecarver zoecarver left a comment

Choose a reason for hiding this comment

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

Sorry, I didn't read this PR very clearly.

@cabmeurer cabmeurer force-pushed the cxx/increment-decrement-op branch from 2defa94 to 9fc1cfd Compare February 7, 2022 20:08
@cabmeurer cabmeurer requested a review from zoecarver February 7, 2022 20:08
@hyp
Copy link
Contributor

hyp commented Feb 7, 2022

The increment and decrement operators were removed from Swift (https://github.com/apple/swift-evolution/blob/master/proposals/0004-remove-pre-post-inc-decrement.md). I don't think we would want to bring them over from C++ as this doesn't seem Swifty. WDYT @zoecarver ?

@cabmeurer
Copy link
Contributor Author

I was wondering about that, I had this conversation with another developer. About how the interop could possibly be some what more limited to encourage a "common language overlap". To generally make it easier for swift developers to interact with c++.

@hyp
Copy link
Contributor

hyp commented Feb 7, 2022

I was wondering about that, I had this conversation with another developer. About how the interop could possibly be some what more limited to encourage a "common language overlap". To generally make it easier for swift developers to interact with c++.

That's a good point, but I think we should still err on the side of importing something that Swift has affordances for. I think operators like ++ and -- are valuable when working with iterators for example, but it might be better to bring them over through other means:

  • bridging std::next and std::prev can cover a lot of uses cases.
  • adding extension to the owning type that match index(after:) and index(before:) would also be a good way to make the iterator increments/decrements Swifty. We might want to bridge the operators in that case to give access to the implementor of the extension, but I could see them being bridged over as some increment/decrement methods on the iterator instead of ++ and --.
    Wdyt?

@cabmeurer
Copy link
Contributor Author

cabmeurer commented Feb 7, 2022

I was wondering about that, I had this conversation with another developer. About how the interop could possibly be some what more limited to encourage a "common language overlap". To generally make it easier for swift developers to interact with c++.

That's a good point, but I think we should still err on the side of importing something that Swift has affordances for. I think operators like ++ and -- are valuable when working with iterators for example, but it might be better to bring them over through other means:

  • bridging std::next and std::prev can cover a lot of uses cases.
  • adding extension to the owning type that match index(after:) and index(before:) would also be a good way to make the iterator increments/decrements Swifty. We might want to bridge the operators in that case to give access to the implementor of the extension, but I could see them being bridged over as some increment/decrement methods on the iterator instead of ++ and --.
    Wdyt?

For sure! That sounds like a great approach to me. I will do some more investigating.

Edit: Bridging std::next and std::prev, sounds like a good initial approach, that being said im not super familiar with this space so whatever you think is best.

@cabmeurer cabmeurer closed this Feb 8, 2022
@cabmeurer cabmeurer deleted the cxx/increment-decrement-op branch February 8, 2022 17:57
@hyp
Copy link
Contributor

hyp commented Feb 8, 2022

Thanks! @cabmeurer it might be good to add some test cases that verify that we can bridge over std::next and friends. we can sync up with you on that next.

@cabmeurer
Copy link
Contributor Author

Thanks! @cabmeurer it might be good to add some test cases that verify that we can bridge over std::next and friends. we can sync up with you on that next.

Awesome! Sounds good

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.

3 participants