Commit Graph

2428 Commits

Author SHA1 Message Date
Egor Zhdan
3e75fd207d Revert "[cxx-interop] Enable virtual function calling from Swift to C++"
This partially reverts commit 128064f3
2024-02-29 22:33:27 +00:00
Ben Barham
1306f2b32a Merge pull request #71863 from bnbarham/remove-makearrayref
Use the new template deduction guides rather than `makeArrayRef`
2024-02-25 21:06:51 -08:00
Slava Pestov
21313d47f5 ClangImporter: Don't call getDirectlyInheritedNominalTypeDecls() on a protocol 2024-02-24 07:25:59 -05:00
Slava Pestov
7909d83229 AST: Refactor directReferencesForTypeRepr() to track inverses 2024-02-24 07:25:59 -05:00
Ben Barham
f292ec9784 Use the new template deduction guides rather than makeArrayRef
LLVM has removed `make*ArrayRef`, migrate all references to their
constructor equivalent.
2024-02-23 20:04:51 -08:00
Ben Barham
5637284e48 Merge pull request #71368 from bnbarham/std-optional-all-the-things
Migrate llvm::Optional to std::optional
2024-02-21 16:54:00 -08:00
Ben Barham
ef8825bfe6 Migrate llvm::Optional to std::optional
LLVM has removed llvm::Optional, move over to std::optional. Also
clang-format to fix up all the renamed #includes.
2024-02-21 11:20:06 -08:00
Alex Lorenz
6312fc05cc [interop] adopt a swift-6 interoperability mode for new features in the next release 2024-02-21 09:27:45 -08:00
Becca Royal-Gordon
8621508098 Merge pull request #71320 from beccadax/globally-lazy-maximum
[ClangImporter] Support lazy member loading for import-as-member globals in extensions
2024-02-08 12:13:32 -08:00
Pavel Yaskevich
8bb6846285 Merge pull request #71419 from xedin/rdar-114052705
[ClangImporter] Import NSNotificationName constants as `nonisolated`
2024-02-08 09:30:36 -08:00
Pavel Yaskevich
5f0a9c475b [ClangImporter] Import NSNotificationName constants as nonisolated
These constants could be used with observer APIs from a different isolation
context, so it's more convenient to import them as `nonisolated` unless
they are explicitly isolated to a MainActor.

Resolves: rdar://114052705
2024-02-07 10:04:34 -08:00
Slava Pestov
d46bd335de Merge pull request #71371 from slavapestov/ncgenerics-fixes-3
Non-copyable generics fixes, part 3
2024-02-06 08:35:07 -05:00
Slava Pestov
af50d7e6b8 AST: Add allowInverses flag to AbstractGenericSignatureRequest 2024-02-05 18:43:06 -05:00
Andrew Trick
e738b8a77e Merge pull request #71353 from meg-gupta/initlifetimedep
Support for lifetime dependence specifiers on initializers
2024-02-05 08:55:54 -08:00
Meghana Gupta
c8ece100ba Handle explicit lifetime dependence specifiers in initializers 2024-02-02 11:50:10 -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
Allan Shortlidge
b6d41046de NFC: Address a couple of unused variable warnings. 2024-02-01 18:15:42 -08:00
Becca Royal-Gordon
6e44517af0 [NFC] Make insertMembersAndAlternates more specific
This will help when ClangImporter::Impl::loadNamedMembers() starts having to handle a lot more import-as-members names, but it’s NFC in this commit.
2024-02-01 12:41:42 -08:00
Egor Zhdan
db424e23cb Merge pull request #71243 from apple/egorzhdan/std-vector-bridging-header
[cxx-interop] Make automatic conformances work with the bridging header
2024-02-01 13:14:10 +00:00
Alex Hoppen
b3f9e08255 Merge pull request #71237 from ahoppen/ahoppen/attribute-parser-changes
Disallow spaces between `@`, attribute name and `(` in Swift 6
2024-01-31 20:53:34 -08:00
Egor Zhdan
c26fe86754 [cxx-interop] Make automatic conformances work with the bridging header
For C++ types that are defined in the bridging header, or are `#include`-d from the bridging header, we did not generate the automatic conformances to `CxxSequence`, `CxxRandomAccessCollection` protocols.

To check whether we should try to conform a C++ type to those protocols, the compiler checks for the presence of `requires cplusplus` in the module declaration in a modulemap file. This check is there to prevent us from accidentally pulling in `Cxx`/`CxxStdlib` modules when a client is importing a C library.

This change makes sure those conformances are generated.

rdar://121927459
2024-01-31 13:56:18 +00:00
Alex Hoppen
cc5e79b521 [Parse] Disallow space between @ and attribute name in Swift 6 mode 2024-01-29 22:54:29 -08:00
Ian Anderson
288f37b2c1 [Concurrency] [shims] Don't declare exit in the concurrency shims
Don't delete the OS declaration of `exit` because the concurrency shims aren't always imported, and so the shim declaration might not always be available.
Don't override the OS declaration of `exit` in the concurrency shims since we can't just delete the OS one. Instead, set up internal shims just for building Concurrency that forward declares `exit`.
2024-01-29 16:25:46 -08:00
Egor Zhdan
7103d27675 [cxx-interop] Emit default expressions in symbolic interfaces
This makes sure we print `= cxxDefaultArg` for parameters that have a default expression on the C++ side.

Note that we can't run the safety heuristic that we use during normal compilation, since we don't know all of the types involved.

rdar://121440191
2024-01-26 14:59:56 +00:00
Rick van Voorden
f8ae46b3f3 [inclusive-language] changed sanity to soundness 2024-01-25 18:18:02 -08:00
Hamish Knight
c97d80b1c3 [AST] NFC: Add convenience constructors for ReturnStmt
Add `ReturnStmt::createParsed` and `createImplict`.
2024-01-23 19:30:18 +00:00
Becca Royal-Gordon
0683f3985a [ClangImporter] Break cycle in IAM extensions
Under a set of circumstances that I cannot fully characterize, it was possible for `ClangImporter::Implementation::importDeclContextOf()` to end up recursing until stack overflow while trying to import a global as a member.

The cycle was caused by `addExtension()` using a newly-created extension’s lazy member loader to load its members before the extension had been added to ClangImporter’s `extensionPoints` table. Loading the members would try to import the IAM members again, which would cause `importDeclContextOf()` to try to create another extension to contain them, which `addExtension()` would force to load those members. Repeat until stack overflow.

I have fixed this bug by registering the extension in the `extensionPoints` map before its member loader is set. This ensures that if `importDeclContextOf()` gets called for any reason after that point, it will return the existing extension instead of creating a new one, avoiding the cycle.

Unfortunately, I was not able to figure out the exact conditions that were necessary to reproduce this bug, so I have not included a test. However, I have tested with the affected project locally and confirmed that this change lets it build. All existing tests pass.

Fixes rdar://120854030.
2024-01-18 19:26:17 -08:00
Anthony Latsis
96ee57b00b Merge pull request #70623 from AnthonyLatsis/init-sema
Move unqualified `init` diagnosis from Parse to Sema
2024-01-18 03:53:33 +03:00
Pavel Yaskevich
6cdab78028 Merge pull request #70867 from xedin/dynamic-enforcement-of-witness-isolation-with-preconcurrency
[TypeChecker/SILGen] Dynamic enforcement of witness/objc isolation with @preconcurrency attribute
2024-01-17 10:01:37 -08:00
Egor Zhdan
206164013b Merge pull request #70772 from apple/egorzhdan/std-function-initial-tests
[cxx-interop] Initial tests for `std::function` usage
2024-01-17 13:25:02 +00:00
Pavel Yaskevich
e8b7a26eac [AST] Add a flag to indicate that the conformance is @preconcurrency 2024-01-16 11:51:42 -08:00
Pavel Yaskevich
233d279a5c [AST] Support @preconcurrency attribute on test/extension inheritance entries 2024-01-16 10:30:58 -08:00
Pavel Yaskevich
8f8e856ea6 [ClangImporter] Account for Sendable attributes on generic parameter requirements 2024-01-12 11:32:06 -08:00
Egor Zhdan
4ca4b9a290 [cxx-interop] Check for type completeness consistently
`clangSema.isCompleteType` checks for decl visibility according to the module visibility rules, which we don't actually need. What we need to check is whether the record has a definition – this is the check we already use elsewhere in ClangImporter.

This makes sure that we can import `std::function` on Windows.

rdar://103979602
2024-01-11 20:53:45 +00:00
Anthony Latsis
bd2f48d9d2 [NFC] AST: Introduce and use Identifier::isConstructor 2023-12-25 21:09:17 +03: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
65eaafe7da [cxx-interop] Keep pulling in the entire libc++
libc++ recently split the `std` module into many top-level modules: 571178a21a

Previously if a C++ module had `#include <iosfwd>`, importing that module in Swift would make the entire C++ stdlib visible from Swift, since it was a single top-level Clang module. After libc++ got split it doesn't automatically do so, but we need to preserve the current behavior for Swift users.

rdar://119270491
2023-12-14 15:58:15 +00:00
Egor Zhdan
06f9c012c0 Merge pull request #70411 from apple/egorzhdan/libcxx-requires-cplusplus
[cxx-interop] Adjust detection of C++ modules after changes in libc++
2023-12-13 17:02:21 +01:00
Egor Zhdan
01670cdb62 Merge pull request #70325 from apple/egorzhdan/friend-operator-lookup
[cxx-interop] Add friend operators to the lookup table properly
2023-12-13 14:24:58 +01:00
Egor Zhdan
24b0d6e91e [cxx-interop] Adjust detection of C++ modules after changes in libc++
libc++ recently split the `std` module into many top-level modules: 571178a21a

This prevented the conformances to `CxxSet`, `CxxVector`, etc. from being synthesized with a fresh libc++ version.

rdar://119270491
2023-12-13 13:15:31 +00:00
Doug Gregor
2ca67e0e0a Merge pull request #70414 from DougGregor/clang-importer-special-names
[Clang importer] Map imported names via the user-facing name
2023-12-13 00:31:06 -08:00
Alex Lorenz
c19ea96809 [interop] allow virtual methods only for the 'upcoming-swift' release 2023-12-12 17:20:53 -08:00
Doug Gregor
7e30d54deb [Clang importer] Map imported names via the user-facing name
Swift names provided via C attributes or API notes can be parsed as
special names, such as `init` or `subscript`. However, doing so would
cause the Clang importer to crash, because it assumes that these names
are always identifiers. In these places, we actually want to treat
them as identifiers, where special names are mapped back to their
keywords. Introduce a function to do that, and use it consistently.
2023-12-12 14:22:02 -08:00
Egor Zhdan
4a77ae849c [cxx-interop] Fix incorrect diagnostic for non-imported functions
If a C++ function cannot be imported into Swift, we try to emit a diagnostic that explains why. This diagnostic wasn't always correct: for functions that return a C++ struct, we emitted a note saying "function uses foreign reference type in a return type which breaks 'swift_shared_reference' contract" even if the return type is a trivial struct without any attributes. This was emitted unless there was another diagnostic that we also provided for the same function.
2023-12-12 17:05:42 +00:00
Holly Borla
e4436bac7e Merge pull request #70348 from hborla/cxx-generic-subscript
[cxx-interop] Allow imported subscript to have generic parameters.
2023-12-10 13:51:25 -08:00
Holly Borla
450e59c797 [cxx-interop] Allow imported subscript to have generic parameters. 2023-12-08 21:26:11 -08:00
Egor Zhdan
c8017e7d9f [cxx-interop] Add friend operators to the lookup table properly
Previously, `friend` operators declared in C++ classes were added to the lookup table when the class is being imported.

The operators were added to the wrong lookup table if the class is declared in a C++ namespace. Since a namespace can span across multiple Clang modules, its contents should be added to a translation unit level lookup table, not to a module level lookup table.

This change makes sure we add `friend` operators to the lookup table earlier, when we are actually building the lookup table. Note that this is not possible for class template instantiations, because those are instantiated later, so for templates we still handle `friend` operators when importing the instantiation.

rdar://116349899
2023-12-08 18:48:58 +00:00
Hamish Knight
5e7854f46b [AST] Remove static loc and spelling kind from AccessorDecl
The spelling kind was only ever set to
`StaticSpellingKind::None`, and the static location
was never used for anything (and should be queried
on the storage anyway). This doesn't affect the
computation of `isStatic` since `IsStaticRequest`
already takes the static-ness from the storage for
accessors.
2023-12-08 17:59:44 +00:00