Skip to content
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

[cxx-interop] import static operator call from C++23 as member callAs… #76523

Merged
merged 3 commits into from
Sep 20, 2024

Conversation

compnerd
Copy link
Member

…Function functions in Swift to preserve source compatibility

…Function functions in Swift to preserve source compatibility
@compnerd compnerd requested a review from a team as a code owner September 17, 2024 17:55
@compnerd
Copy link
Member Author

@swift-ci please test

@compnerd
Copy link
Member Author

Explanation: Correct importing of operator ()() from C++ types into Swift.
Scope: This fixes a small C++ interop issue in the compiler which is required for use of std::hash on Windows.
Issue:
Risk: This is a pretty narrow change to how we handle static operator()() which was added in C++23. It impacts only the C++ interop path where this method is declared.
Testing: This has been on main for quite some time and we failed to bring it over for the release.
Reviewer: @egorzhdan @hyp @al45tair

egorzhdan and others added 2 commits September 17, 2024 11:23
This fixes an assertion failure:
```
Assertion failed: (isInstance() && "No 'this' for static methods!"), function getThisType, file DeclCXX.cpp, line 2636.
```

Clang changed it's handling of member call expressions in llvm/llvm-project@af47517 causing the assertion to fail when synthesizing a forwarding function declaration for `static operator()`.

rdar://133257179
Extracted from swiftlang#76235.

Co-authored-by: Alex Lorenz <arphaman@gmail.com>
@compnerd
Copy link
Member Author

@swift-ci please test

@airspeedswift
Copy link
Member

Can you link to the original PR on main? Thanks.

@DougGregor
Copy link
Member

Main PR is: #74279

@DougGregor
Copy link
Member

Explanation: The C++ standard library included in recent versions of Microsoft Visual Studio have adopted a C++23 feature "static operator()", which causes a source compatibility break for Swift/C++ interoperability on Windows. Implement support for static operator() in the Clang importer by importing it as an instance method callAsFunction. This ensures that the source-compatible change to C++23 code (from operator() to static operator()) will also be a source-compatible change for Swift/C++ interoperability.
Issue: compnerd/swift-build#808
Scope: This is a general addition to the Clang importer for C++ interoperability, although it's applicability is very narrow: static operator() is a new feature in C++23, and is not yet widely used.
Risk: Since static operator() is so new in C++23, and this fix is narrowly targeted at importing that feature, the likelihood of this affecting anything else is small.
Testing: CI, new tests
Reviewed By: @egorzhdan, me
Original PR: #74279

@shahmishal shahmishal merged commit 908890e into swiftlang:release/6.0.1 Sep 20, 2024
5 checks passed
@compnerd compnerd deleted the call-me-maybe branch September 20, 2024 22:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants