Skip to content

[cxx-interop] Fix inline operators of address-only types. #32869

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

zoecarver
Copy link
Contributor

No description provided.

@zoecarver zoecarver added the c++ interop Feature: Interoperability with C++ label Jul 14, 2020
@zoecarver zoecarver requested review from gribozavr and MForster July 14, 2020 04:27
@zoecarver zoecarver marked this pull request as draft July 14, 2020 04:38
@zoecarver zoecarver force-pushed the tests/cxx/address-only-operators branch 6 times, most recently from 3c646c3 to d40d337 Compare July 16, 2020 03:09
@zoecarver zoecarver changed the title [NFC] [cxx-interop] Add a test for inline operators of address-only types. [cxx-interop] Fix inline operators of address-only types. Jul 16, 2020
@zoecarver zoecarver marked this pull request as ready for review July 16, 2020 03:11
@zoecarver
Copy link
Contributor Author

This turned into a patch to actually fix operators for address-only instead of just add tests for them. Should be good to go, now. I may want to add a few more tests, though.

@@ -1549,6 +1549,19 @@ class DestructureInputs {
auto eltPattern = origType.getFunctionParamType(i);
auto flags = params[i].getParameterFlags();

// If we have an inline operator, when it was imported, it was turned
// from a method into a static function. So, we need to shift over the
// params by one and use "self" as the first param's type.
Copy link
Contributor

@gribozavr gribozavr Jul 20, 2020

Choose a reason for hiding this comment

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

I can't say what the right fix should be exactly, but I feel like this code is working around the problem more than solving it directly. Resetting NextOrigParamIndex does not feel right to me (so this code won't work for argument count greater than 2, I think?) Abstraction pattern and the code to handle self in this converter class are supposed to abstract away this issue, I think. Currently they handle the abstraction in the opposite direction (importing a C free function as a Swift method). Here, we have the opposite problem -- importing a C++ member function as a Swift static method.

WDYT about extending this code to skip both the Swift self which was mapped from C, and Swift parameters that correspond to C++ this, and letting the HandleForeignSelf handle them at the appropriate point?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

WDYT about extending this code to skip both the Swift self which was mapped from C, and Swift parameters that correspond to C++ this, and letting the HandleForeignSelf handle them at the appropriate point?

The issue is CXXMethodConventions creates a CFunctionTypeConventions object with the function type T(T) when it should be T(T, T). This means that there are the wrong number of arguments. I think we have two choices, either we can pass forSelf=true for the first argument, then decrement NextOrigParamIndex (still a bit of a hack but also less bad than what's currently in this PR), or we can pass a more "correct" type to CFunctionTypeConventions. WDYT would be better?

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've updated this PR to use the first solution I suggested but I can change it to use the second if you'd rather.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@hlopko @varungandhi-apple thoughts on the above conversation? I'd like to get this patch moving :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@gribozavr @hlopko ping. Once re-reviewed I'll rebase.

@shahmishal
Copy link
Member

Please update the base branch to main by Oct 5th otherwise the pull request will be closed automatically.

  • How to change the base branch: (Link)
  • More detail about the branch update: (Link)

@zoecarver zoecarver changed the base branch from master to main October 2, 2020 04:01
@zoecarver zoecarver requested a review from hlopko November 20, 2020 05:01
@zoecarver zoecarver force-pushed the tests/cxx/address-only-operators branch from 861d368 to 304c966 Compare January 31, 2021 21:58
@zoecarver zoecarver force-pushed the tests/cxx/address-only-operators branch from 304c966 to 34802ed Compare January 31, 2021 22:01
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.

4 participants