Commit Graph

597 Commits

Author SHA1 Message Date
Ikko Eltociear Ashimine
0c1ffb1a21 Fix typo in runtime-polymorphism.swift
comparision -> comparison
2024-02-19 00:49:30 +09:00
Kavon Farvardin
08b71e0136 NCGenerics: rebuild stdlib from its interface
When a NoncopyableGenericsMismatch happens between the compiler and
stdlib, allow the compiler to rebuild the stdlib from its interface
instead of exiting with an error.
2024-02-15 18:08:54 -08:00
Guillaume Lessard
114f235d17 Merge pull request #71167 from vanvoorden/vanvoorden/inclusive-language
[Inclusive Language][Comments][Documentation] migrate "sanity" checks to "soundness" checks
2024-02-02 10:27:34 -08:00
Kavon Farvardin
5f977ca763 NCGenerics: force module mismatches 2024-01-31 14:00:08 -08:00
Rick van Voorden
f8ae46b3f3 [inclusive-language] changed sanity to soundness 2024-01-25 18:18:02 -08:00
Allan Shortlidge
bb38de355b Add REQUIRES: asserts to NoncopyableGenerics tests. 2024-01-11 15:31:40 -08:00
Egor Zhdan
53979a2fcc [cxx-interop] More tests for move-only C++ types 2024-01-08 17:13:47 +00:00
Egor Zhdan
35e474d5d6 [cxx-interop] NFC: Remove leftover comment 2024-01-08 15:40:01 +00:00
Akira Hatanaka
14cfebc640 Fix a crash in ClangImporter::Implementation::DiagnosticWalker::TraverseDecl
The call to `D->getBeginLoc` crashes when `D` is null.

rdar://118899818
2023-12-19 15:58:42 -08:00
Egor Zhdan
233b80e431 Merge pull request #70503 from apple/egorzhdan/no-abstract-ctors
[cxx-interop] Do not import constructors of abstract C++ classes
2023-12-18 17:24:00 +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
Alex Lorenz
9261fa765d Merge pull request #70420 from hyp/eng/virtual-methods++
[cxx-interop] virtual method fixes
2023-12-16 06:37:44 -08:00
Egor Zhdan
73cf3be98c [cxx-interop] Do not import CxxShim explicitly in tests 2023-12-15 19:51:41 +00:00
Alex Lorenz
72db47239b [cxx-interop] enable the virtual methods irgen test on windows 2023-12-13 14:33:09 -08:00
Alex Lorenz
c19ea96809 [interop] allow virtual methods only for the 'upcoming-swift' release 2023-12-12 17:20:53 -08:00
Egor Zhdan
6ecaaa41c5 Merge pull request #70304 from apple/egorzhdan/conforms-to-derived-class
[cxx-interop] Propagate `CONFORMS_TO` attribute to derived classes
2023-12-07 22:00:44 +01:00
Egor Zhdan
45b22542d5 [cxx-interop] Propagate CONFORMS_TO attribute to derived classes
If `struct Base` is a public base class of `struct Derived`, and `Base` is annotated with `__attribute__((swift_attr("conforms_to:MyModule.MyProto")))`, `Derived` will now also get a conformance to `MyProto`.

rdar://113971944
2023-12-07 18:11:37 +00:00
Alex Lorenz
c7345d08cf Merge pull request #69790 from hyp/eng/move-only-is-back
[cxx-interop] enable support for move-only types
2023-12-06 09:43:43 -08:00
Alex Lorenz
623d3d2032 [cxx-interop] review fixes for non-copyable patch, ensure we only enable this in upcoming Swift 2023-12-05 14:16:30 -08:00
Alex Lorenz
ec931c82c4 [cxx-interop] non-copyable test windows workaround and no SIL verify for NC generic test 2023-12-05 13:42:13 -08: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
3a340c78f0 [cxx-interop] move-only: do not test consume with unsafeAddress accessors - they do not yet work 2023-12-03 18:11:07 -08:00
Alex Lorenz
580ecd0893 [cxx-interop] fix Egor's review comments for move-only patch 2023-11-30 10:12:11 -08:00
Alex Lorenz
b7158ea486 [cxx-interop] add SWIFT_NONCOPYABLE annotation 2023-11-29 18:13:31 -08:00
Alex Lorenz
6a47011b18 [cxx-interop] add IRGen test for field base accessors for non-copyable fields 2023-11-29 09:10:51 -08:00
Alex Lorenz
bacc58e0f7 [cxx-interop] provide correct referential access to non-copyable base fields from a derived value type 2023-11-28 20:10:07 -08:00
Alex Lorenz
51d0e84933 [cxx-interop] add a test to cover accessing non-copyable field 2023-11-28 14:07:44 -08:00
Alex Lorenz
fd6a5a20ef [cxx-interop] test accessing fields of a move-only C++ type 2023-11-28 12:26:48 -08:00
Hiroshi Yamauchi
897fae2b26 Merge pull request #69929 from hjyamauchi/methods-this-and-indirect-return-irgen-msvc
Fix test methods-this-and-indirect-return-irgen-msvc.swift for windows/aarch64
2023-11-27 10:54:05 -08:00
Hiroshi Yamauchi
e59fcc46dd Fix test methods-this-and-indirect-return-irgen-msvc.swift for windows/aarch64
Handle a slight LLVM IR difference in the second parameter (inreg) of
a function between x86_64 and aarch64. These are how Clang on windows
emits the code.
2023-11-16 13:34:36 -08:00
Alex Lorenz
3cdb4b1151 [cxx-interop] add some initial move only tests 2023-11-16 10:08:29 -08:00
zoecarver
70a353bd28 [tests][cxx-interop] Fix straggling test. 2023-11-16 10:08:26 -08:00
Hiroshi Yamauchi
7b21ed1b38 Merge pull request #69836 from hjyamauchi/winarm64test
Fix test msvc-abi-return-indirect-trivial-record.swift for windows aarch64
2023-11-16 09:44:47 -08:00
Hiroshi Yamauchi
a8424a03c4 Fix test msvc-abi-return-indirect-trivial-record.swift for windows aarch64
The test msvc-abi-return-indirect-trivial-record.swift fails on
windows aarch64 because the type of the third argument of
@"??YLoadableIntWrapper@@qeaa?AU0@U0@@z"
(@LoadableIntWrapper::operator+=(LoadableIntWrapper)) is i64 which
differs from i32 for x86_64. Accommodate this as this is how Clang
generates code. See https://godbolt.org/z/G76aMr5M9.
2023-11-14 16:02:44 -08:00
Egor Zhdan
efc008a2ca [cxx-interop] Import using decls that expose methods from private base classes
If a C++ type `Derived` inherits from `Base` privately, the public methods from `Base` should not be callable on an instance of `Derived`. However, C++ supports exposing such methods via a using declaration: `using MyPrivateBase::myPublicMethod;`.

MSVC started using this feature for `std::optional` which means Swift doesn't correctly import `var pointee: Pointee` for instantiations of `std::optional` on Windows. This prevents the automatic conformance to `CxxOptional` from being synthesized.

 rdar://114282353 / resolves https://github.com/apple/swift/issues/68068
2023-11-14 00:30:54 +00:00
Egor Zhdan
f9bf957594 [cxx-interop] Do not import inherited methods with rvalue this
We do not synthesize the inheritance thunks correctly for such methods. Do not try to synthesize them, as that causes issues when there are two overloads of the same method, one with rvalue this and one without.

The proper solution is tracked as https://github.com/apple/swift/issues/69745

Unblocks rdar://114282353
2023-11-09 13:42:59 +00:00
Egor Zhdan
879b04f2e7 Merge pull request #69327 from apple/egorzhdan/circular-requests
[cxx-interop] Avoid circular reference errors when importing C++ structs
2023-10-23 14:35:02 +01:00
Egor Zhdan
4632d894e6 [cxx-interop] Avoid circular reference errors when importing C++ structs
When importing a C++ struct, if its owning module requires cplusplus, Swift tried to auto-conform it to certain protocols from the Cxx module. This triggers name lookup in the clang struct, specifically for `__beginUnsafe()` and `__endUnsafe` methods, which imports all of the base structs including their methods.

This moves the import of base structs out of the name lookup request, preventing cycles.

rdar://116426238
2023-10-23 12:19:05 +01:00
Harlan Haskins
4ac34a40ea @retroactive conformance syntax and checking (#36068) 2023-10-20 14:27:03 -07:00
Alex Lorenz
be24516f85 [cxx-interop] Fix test failures after https://github.com/apple/swift/pull/68846
rdar://117205273
2023-10-19 12:33:24 -07:00
Alex Lorenz
41dc466108 Merge pull request #68846 from hyp/eng/base-member-cxx-synthesized-accessor
[cxx-interop] Use a synthesized C++ method when invoking a base metho…
2023-10-17 07:07:59 -07:00
Alex Lorenz
415045024c [cxx-interop] Use a synthesized C++ method when accessing a base field or subscript from a derived class synthesized method
The use of a synthesized C++ method allows us to avoid making a copy of self when accessing the base field or subscript from Swift
2023-10-16 14:34:37 -07:00
finagolfin
75bfa4422a [android][test] Fix five tests that are failing on the community Android CI (#69189)
Update the Android doc with info about the latest LTS NDK not working.
2023-10-16 10:44:56 -07:00
Egor Zhdan
041005af7c [cxx-interop] Use more correct type names in C++ template parameters
When importing a C++ class template instantiation, Swift translates the template parameter type names from C++ into their Swift equivalent.

For instance, `basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t>>` gets imported as `basic_string<Scalar, char_traits<Scalar>, allocator<Scalar>>`: `wchar_t` is imported as `CWideChar`, which is a typealias for `Scalar` on most platforms including Darwin. Notice that Swift goes through the `CWideChar` typealias on the specific platform. Another instantiation `basic_string<uint32_t, char_traits<uint32_t>, allocator<uint32_t>>` also gets imported as `basic_string<Scalar, char_traits<Scalar>, allocator<Scalar>>`: `uint32_t` is also imported as `Scalar`. This is problematic because we have two distinct C++ types that have the same name in Swift.

This change makes sure Swift doesn't go through typealiases when emitting names of template parameters, so `wchar_t` would now get printed as `CWideChar`, `int` would get printed as `CInt`, etc.

This also encourages clients to use the correct type (`CInt`, `CWideChar`, etc) instead of relying on platform-specific typealiases.

rdar://115673622
2023-10-09 14:57:10 +01:00
Alex Lorenz
ba5b1bab89 [cxx-interop] Use a synthesized C++ method when invoking a base method from a derived class synthesized method
The use of a synthesized C++ method allows us to avoid making a copy of self when invoking the base method from Swift
2023-09-29 13:52:10 -07:00
Alex Lorenz
6ecea1ac09 Merge pull request #68481 from hyp/eng/no-nocapture
[IRGen][interop] do not add 'nocapture' to not bitwise takable types
2023-09-26 07:52:05 -07:00
Alex Lorenz
4858cb6225 [IRGen][interop] do not add 'nocapture' to not bitwise takable types
The use of 'nocapture' for parameters and return values is incorrect for C++ types, as they can actually capture a pointer into its own value (e.g. std::string in libstdc++)

rdar://115062687
2023-09-25 17:43:34 -07:00
Kavon Farvardin
0944d46e65 [nfc] fix spelling; invertable -> invertible 2023-09-22 17:04:57 -07:00
Saleem Abdulrasool
88e62d7de2 Merge pull request #68134 from compnerd/fragility
Cxx: mark as fragile
2023-08-25 16:21:35 -07:00
Saleem Abdulrasool
dff40e9399 Cxx: mark as fragile
This library is still fragile as C++ Interop is in preview. Mark it as
fragile to match cxxStdlib.
2023-08-25 11:31:36 -07:00