Commit Graph

7 Commits

Author SHA1 Message Date
susmonteiro
b3e228845b [cxx-interop] Allow virtual methods to be renamed with swift_name 2025-07-02 16:09:02 +01:00
susmonteiro
25efb5fc04 [cxx-interop] Disable debug info in synthesized C++ methods
rdar://141167229
2025-03-19 18:02:50 +00:00
Egor Zhdan
8ead7224b7 [cxx-interop] Overhaul virtual method support
This adds a new implementation of virtual method dispatch that handles reference types correctly.

Previously, for all C++ types an invocation of a virtual method would actually get dispatched statically. For value types this is expected and matches what C++ does because of slicing. For reference types, however, this is incorrect, we should do dynamic dispatch.

rdar://123852577
2024-03-01 19:45:58 +00:00
Egor Zhdan
325868808b [cxx-interop] Do not import constructors of abstract C++ classes
Clang rejects code that tries to call a constructor of an abstract C++ class with an error: "Variable type 'Base' is an abstract class". Swift should reject this as well.

rdar://119689243
2023-12-18 14:52:32 +00:00
Puyan Lotfi
128064f31d [cxx-interop] Enable virtual function calling from Swift to C++
This is a forward-interop feature that wires up existing functionality for
synthesizing base class function calling to enable virtual function calling.
The general idea is to sythesize the pattern:

```
// C++ class:
struct S { virtual auto f() -> int { return 42; } };

// Swift User:
var s = S()
print("42: \(s.f())")

// Synthetized Swift Code:
extension S { func f() -> CInt { __synthesizedVirtualCall_f() } }

// Synthetized C/C++ Code:
auto __cxxVirtualCall_f(S *s) -> int { return s->f(); }
```

The idea here is to allow for the synthetized C++ bits from the Clang side to
handle the complexity of virtual function calling.
2023-12-04 01:55:30 -05:00
Alex Lorenz
c2315060b6 [interop] mark C++ virtual functions as unavailable in Swift
They're not yet supported
2023-04-10 11:51:38 -07:00
Egor Zhdan
6ca60b075e [cxx-interop] Emit IR for virtual methods
Even if a virtual method is not used directly from Swift, it might get emitted into the vtable, and in that case the IR for it should be emitted to avoid linker errors.

Fixes https://github.com/apple/swift/issues/61730.
2022-11-01 13:10:44 -07:00