Commit Graph

1705 Commits

Author SHA1 Message Date
Egor Zhdan
d85d2e9e75 [cxx-interop] Synthesize conformances to UnsafeCxxInputIterator
This teaches ClangImporter to synthesize conformances of C++ iterator types to `UnsafeCxxInputIterator` protocol from the `Cxx` module.

We consider a C++ type to be an iterator if it defines a subtype (usually a typedef or a using decl) called `iterator_category` that inherits from `std::input_iterator_tag`.

rdar://96235368
2022-07-20 11:44:25 +01:00
swift-ci
9de631f94f Merge remote-tracking branch 'origin/main' into rebranch 2022-07-19 17:35:57 -07:00
zoecarver
ba7e6e44aa [cxx-interop] Fix predicate to find copy assignment operators. 2022-07-19 16:38:57 -04:00
zoecarver
09384be097 [cxx-interop] Simplify logic in IsSafeUseOfCxxDecl; fix bug for pointer types.
Previously types containing pointers would mark all C++ methods as unsafe.
2022-07-18 17:15:16 -04:00
zoecarver
3498ff9765 [cxx-interop] Remove UnsafeLifetimeOperation record semantic kind.
This makes "owned" the default kind for records that have custom copy constructors and no pointer-members.
2022-07-18 17:15:15 -04:00
zoecarver
ca5fa9aa9b [nfc] Clang format changes. 2022-07-18 17:15:15 -04:00
zoecarver
9d1d03124b [nfc][cxx-interop] Add diagnostics when something cannot be imported. 2022-07-18 17:15:15 -04:00
zoecarver
6acffbbee6 [cxx-interop] Flip the switch: only import safe APIs. 2022-07-18 17:15:15 -04:00
swift-ci
968e43db49 Merge remote-tracking branch 'origin/main' into rebranch 2022-07-08 07:34:44 -07:00
Egor Zhdan
59cc7c49e3 [cxx-interop] NFC: fix bad merge
`getModuleMapFilePath` and related logic was moved to `ClangIncludePaths.cpp` recently, but got resurrected in `ClangImporter.cpp` by accident.
2022-07-08 12:41:46 +01:00
swift-ci
d4005d615f Merge remote-tracking branch 'origin/main' into rebranch 2022-07-06 09:55:20 -07:00
zoecarver
3805828ad0 [cxx-interop] Add CxxShim library; move __swift_interopStaticCast into it. 2022-07-05 15:52:51 -07:00
swift-ci
02522806f2 Merge remote-tracking branch 'origin/main' into rebranch 2022-07-04 03:13:20 -07:00
Egor Zhdan
cf3354222d [Glibc] Use VFS to inject modulemap into Glibc include path
This will fix modularization issues caused by the presence of Glibc and libstdc++ in a single context.

Some Glibc headers were getting hijacked by the libstdc++ module, and the decls in them were incorrectly determined to be a part of libstdc++. This caused compiler errors when trying to use those decls.

After this change, we will be able to reference Glibc headers directly from the module map, without using an additional header (`SwiftGlibc.h`).
2022-07-01 23:49:12 +01:00
swift-ci
4107d01ef9 Merge remote-tracking branch 'origin/main' into rebranch 2022-06-30 11:34:11 -07:00
Egor Zhdan
a2fb2d0b78 [ClangImporter] NFC: extract Clang include path mapping logic into a separate file
This logic is going to be extended to inject the modulemap and the header of Glibc in addition to libstdc++. It doesn't depend on the rest of ClangImporter, so let's extract it to a separate file to make incremental builds and IDE features faster.
2022-06-30 15:50:33 +01:00
swift-ci
a12ece4179 Merge remote-tracking branch 'origin/main' into rebranch 2022-06-24 20:54:07 -07:00
Holly Borla
429488f6c9 [Sema] Use ExistentialType for Any and AnyObject. 2022-06-17 18:29:15 -07:00
swift-ci
55000f53be Merge remote-tracking branch 'origin/main' into rebranch 2022-06-17 10:15:14 -07:00
Becca Royal-Gordon
9b5f89963b [NFC] Serialize ObjC selectors for protocols
The ObjCMethodLookupTable for protocols was not being serialized and rebuilt on load, so NominalTypeDecl::lookupDirect() on selectors was not working correctly for deserialized types. Correct this oversight.
2022-06-16 14:07:49 -07:00
swift-ci
0c44504e3a Merge remote-tracking branch 'origin/main' into rebranch 2022-06-15 02:34:04 -07:00
Egor Zhdan
81b18d211d [cxx-interop] Pass --gcc-toolchain to Clang driver when determining include paths 2022-06-15 01:45:52 +01:00
swift-ci
40c801f236 Merge remote-tracking branch 'origin/main' into rebranch 2022-06-09 13:52:42 -07:00
Egor Zhdan
31381a352a [cxx-interop] Fix assertion failure when looking up C++ operators
Previously when looking up a C++ operator (e.g. `==`), `ClangImporter::Implementation::lookupValue` returned a Swift function with a generated name (e.g. `func __operatorEqualEqual`), while the caller expected the result to be a Swift operator (e.g. `func ==`).

This change makes sure that we're returning a synthesized Swift operator when looking for a C++ operator.

This fixes an assertion failure in the typechecker:
```
swift-frontend: /home/build-user/swift/lib/Sema/ConstraintSystem.cpp:1454: std::pair<Type, Type> swift::constraints::ConstraintSystem::getTypeOfReference(swift::ValueDecl *, swift::FunctionRefKind, swift::constraints::ConstraintLocatorBuilder, swift::DeclContext *): Assertion `func->isOperator() && "Lookup should only find operators"' failed.
```
2022-06-09 19:24:13 +01:00
swift-ci
604953d20a Merge remote-tracking branch 'origin/main' into rebranch 2022-06-02 12:14:21 -07:00
Ben Barham
65ed78d3e7 Merge branch 'main' into manually-merge-main 2022-06-02 10:14:57 -07:00
Ehud Adler
0d7a0416e7 Removed extra string include 2022-06-02 13:00:22 -04:00
Zoe Carver
4967cd58a1 Merge pull request #58910 from Huddie/update-cxx-operator-impl 2022-06-01 20:31:18 -07:00
Ehud Adler
54ed81c427 Format 2022-06-01 14:54:07 -04:00
Ehud Adler
1d1df27d4a Fix switch error + format 2022-06-01 14:40:27 -04:00
swift-ci
e46b2c3efe Merge remote-tracking branch 'origin/main' into rebranch 2022-06-01 08:13:51 -07:00
Zoe Carver
d48c5fbbb1 Merge pull request #59022 from skrtks/cxx_inherited_attributes 2022-06-01 08:08:23 -07:00
swift-ci
57042b20d7 Merge remote-tracking branch 'origin/main' into rebranch 2022-05-31 11:54:15 -07:00
Egor Zhdan
c70d8fdd9b Merge pull request #59050 from apple/egorzhdan/libstdcxx-sysroot
[cxx-interop] Pass sysroot to the Clang driver when detecting libstdc++ path
2022-05-31 19:40:39 +01:00
Egor Zhdan
07aec92198 [cxx-interop] Pass sysroot to the Clang driver when detecting libstdc++ path
The Swift build scripts pass `-sdk /` to the Swift compiler when building the Swift stdlib and the overlays, and this affects the default include paths of Clang. We need to make sure that libstdc++ path detected by ClangImporter is the same path that will be used by Clang during compilation. To do that, let's pass `--sysroot` to the Clang driver when detecting the libstdc++ path.
2022-05-31 16:22:25 +01:00
swift-ci
fc001b2fcc Merge remote-tracking branch 'origin/main' into rebranch 2022-05-31 03:33:46 -07:00
Egor Zhdan
127e29f365 [cxx-interop] Do not warn about missing libstdc++ on Android
Android uses libc++.

This fixes a few tests on Android.
2022-05-30 23:22:03 +01:00
Ehud Adler
16c1e1defa Format 2022-05-26 21:29:43 -04:00
Ben Barham
92b6dd24c2 Merge branch 'main' into manually-merge-main 2022-05-25 15:55:35 -07:00
swift-ci
645d73f27e Merge pull request #58480 from beccadax/so-i-put-versions-in-your-version-numbers
Update SWIFT_COMPILER_VERSION language features
2022-05-24 17:47:43 -07:00
Sam Kortekaas
e73bb6fd9d [cxx-interop] Import attributes on inherited C++ methods 2022-05-23 13:21:06 +02:00
Ehud Adler
3196ea9b39 Refactor and format 2022-05-21 21:44:07 -04:00
Ehud Adler
e7fe6f0fe7 Fix tests and re-enable support for CXX operators 2022-05-21 21:28:03 -04:00
swift-ci
b83cd2f0a9 Merge remote-tracking branch 'origin/main' into rebranch 2022-05-19 03:33:42 -07:00
Egor Zhdan
abf56bcb33 [cxx-interop] Extract libstdc++ installation path from Clang
To inject a modulemap into the libstdc++ directory, Swift needs to know the path of the libstdc++ installation. Previously it was assumed to be `/usr/include/c++/{version}`, however, this might not be the case. For example, on CentOS the stdlib is located at `/opt/rh/devtoolset-{version}/root/usr/include/c++/{version}`.

This change teaches Swift to extract the libstdc++ include paths from the Clang driver, and fixes C++ stdlib lookup on CentOS.

rdar://93341210
2022-05-18 19:27:29 +01:00
Ehud Adler
11730e8f07 Remap class operator function names (-/+/*....) to imported operator names __operator(Minus, Plus,...) and fix test cases 2022-05-18 10:31:04 -04:00
Ehud Adler
4267958d51 Mapping decl base name to imported name 2022-05-18 10:31:04 -04:00
Ehud Adler
e14e2fbc76 Add changes 2022-05-18 10:31:03 -04:00
swift-ci
ea3d49ce7f Merge remote-tracking branch 'origin/main' into rebranch 2022-05-14 10:13:56 -07:00
Arnold Schwaighofer
9cb25736e0 ClangImporter.cpp: Fix compilation on some linux systems 2022-05-14 08:07:20 -07:00