Commit Graph

2550 Commits

Author SHA1 Message Date
swift-ci
447482505a Merge remote-tracking branch 'origin/main' into rebranch 2023-10-05 08:05:25 -07:00
Egor Zhdan
0b2048d096 Merge pull request #68578 from apple/egorzhdan/cxx-convertible-to-bool
[cxx-interop] Add conversion to Bool for types that define `operator bool()`
2023-10-05 15:52:03 +01:00
swift-ci
06f9a8a703 Merge remote-tracking branch 'origin/main' into rebranch 2023-09-30 11:33:40 -07:00
Doug Gregor
ef642098f2 [Typed throws] Parsing and AST representation for typed errors
Parse typed throw specifiers as `throws(X)` in every place where there
are effects specified, and record the resulting thrown error type in
the AST except the type system. This includes:
* `FunctionTypeRepr`, for the parsed representation of types
* `AbstractFunctionDecl`, for various function-like declarations
* `ClosureExpr`, for closures
* `ArrowExpr`, for parsing of types within expression context

This also introduces some serialization logic for the thrown error
type of function-like declarations, along with an API to extract the
thrown interface type from one of those declarations, although right
now it will either be `Error` or empty.
2023-09-29 10:51:51 -07:00
Egor Zhdan
f0be52accd [cxx-interop] Add conversion to Bool for types that define operator bool()
C++ `operator bool()` is currently imported into Swift as `__convertToBool()`, which shouldn't be used by clients directly.

This adds a new protocol into the C++ stdlib overlay: `CxxConvertibleToBool`, along with an intitializer for `Swift.Bool` taking an instance of `CxxConvertibleToBool`.

rdar://115074954
2023-09-18 14:54:45 +01:00
swift-ci
1b4375ff33 Merge remote-tracking branch 'origin/main' into rebranch 2023-09-12 17:00:25 -07:00
Alex Lorenz
786c78a895 [interop] do not synthesize special members for C++ records with incomplete fields
The incomplete fields will trigger different assertions when clang is sythensizing constructors/destructors

rdar://109417079
2023-09-11 11:01:51 -07:00
swift-ci
0407c3d3b2 Merge remote-tracking branch 'origin/main' into rebranch 2023-09-06 13:34:53 -07:00
Allan Shortlidge
0dd8f4c492 AST: Introduce abstraction for extension/type decl inheritance clauses.
Wrap the `InheritedEntry` array available on both `ExtensionDecl` and
`TypeDecl` in a new `InheritedTypes` class. This class will provide shared
conveniences for working with inherited type clauses. NFC.
2023-09-06 10:41:57 -07:00
swift-ci
632da182bd Merge remote-tracking branch 'origin/main' into rebranch 2023-08-30 08:36:11 -07:00
Egor Zhdan
9b7dbf2599 [cxx-interop] Introduce APINotes file for C++ stdlib
This adds an `std.apinotes` file that is installed into `lib/swift/apinotes` along with existing Darwin apinotes. This new file is installed on all platforms. It replaces a few special cases in the compiler for `cmath` and `cstring` functions.

This does not require the upcoming APINotes support for namespaces, however, this does require https://github.com/apple/llvm-project/pull/7309.

rdar://107572302
2023-08-29 23:34:36 +01:00
swift-ci
0a607cead8 Merge remote-tracking branch 'origin/main' into rebranch 2023-08-14 13:16:19 -07:00
Egor Zhdan
41e4a50126 Merge pull request #67873 from apple/egorzhdan/pthread_mutexattr_t
[cxx-interop] Make sure to create empty initializers for C++ structs
2023-08-14 21:09:14 +01:00
Egor Zhdan
4eb9c3be37 [cxx-interop] Make sure to create empty initializers for C++ structs
The existing synthesis mechanism had a bug: `cxxRecordDecl->hasDefaultConstructor()` returns true for C++ types with an implicit default constructor, for instance, `pthread_mutexattr_t`.

rdar://113708880
2023-08-14 17:46:57 +01:00
swift-ci
b87613bace Merge remote-tracking branch 'origin/main' into rebranch 2023-08-10 04:34:00 -07:00
Slava Pestov
50afb006ee ClangImporter: Remove unnecessary setGenericSignature() call 2023-08-09 17:42:58 -04:00
Slava Pestov
7f9a71cd15 AST: Rename ASTContext::getConformance() to getNormalConformance() 2023-08-09 17:42:25 -04:00
swift-ci
01bb951b0e Merge remote-tracking branch 'origin/main' into rebranch 2023-08-07 11:33:36 -07:00
Egor Zhdan
4acf9c8cf4 [cxx-interop] Add CxxVector protocol
This makes it possible to initialize `std::vector` from a Swift Sequence. This also conforms C++ vectors to `ExpressibleByArrayLiteral`, making it possible, for instance, to pass a Swift array to a C++ function that takes a vector of strings as a parameter.

rdar://104826995
2023-08-07 17:12:12 +01:00
swift-ci
ae4b70bf28 Merge remote-tracking branch 'origin/main' into rebranch 2023-08-04 18:59:37 -07:00
Slava Pestov
6ae2a1deee Merge pull request #67739 from slavapestov/var-decl-type-in-context
AST: Rename VarDecl::getType() to VarDecl::getTypeInContext()
2023-08-04 21:44:22 -04:00
swift-ci
3497832e24 Merge remote-tracking branch 'origin/main' into rebranch 2023-08-04 16:39:50 -07:00
Alex Lorenz
4fcaddb4d8 Merge pull request #67726 from hyp/eng/friends-no-more
[cxx-interop] do not add friend decls as a member of Swift type that …
2023-08-04 15:19:35 -07:00
Slava Pestov
9ebb5f2e03 AST: Rename VarDecl::getType() to VarDecl::getTypeInContext()
This is a futile attempt to discourage future use of getType() by
giving it a "scary" name.

We want people to use getInterfaceType() like with the other decl kinds.
2023-08-04 14:19:25 -04:00
Alex Lorenz
f8dbc01dc6 [cxx-interop] do not add friend decls as a member of Swift type that represents a C++ class 2023-08-03 14:03:45 -07:00
swift-ci
364c47fb6a Merge remote-tracking branch 'origin/main' into rebranch 2023-08-02 05:13:47 -07:00
Egor Zhdan
5f624d18fd Merge pull request #67618 from apple/egorzhdan/std-pair-init
[cxx-interop] Force creating a memberwise init for `std::pair`
2023-08-02 13:04:27 +01:00
swift-ci
6c12f59576 Merge remote-tracking branch 'origin/main' into rebranch 2023-08-01 11:34:57 -07:00
Egor Zhdan
6902041e34 [cxx-interop] Force creating a memberwise init for std::pair
In libc++, `pair()` and `pair(_T1 const& __t1, _T2 const& __t2)` are templated with `enable_if`, so these initializers are not imported into Swift.

There should be a way to call `std.pair.init` from Swift, so this change makes sure Swift synthesizes a memberwise initializer for `std.pair`.

rdar://113135110
2023-08-01 18:59:41 +01:00
Alex Lorenz
0eed1a944c [cxx-interop] correctly add and lookup enumerators added to enums that correspond to namespaces
Fixes https://github.com/apple/swift/issues/67604
2023-07-31 18:57:50 -07:00
swift-ci
88c4110b26 Merge remote-tracking branch 'origin/main' into rebranch 2023-07-28 16:17:39 -07:00
Egor Zhdan
9c22a7a530 [cxx-interop] Memberwise init is not synthesized for C++ type with templated using decl
When Swift fails to import a member of a struct, it checks to see if this member could affect the memory layout of the struct, and if it can, Swift doesn't synthesize the memberwise initializer for this struct. This logic was overly restrictive and treated templated using-decls as potentially affecting the memory layout of the struct.

rdar://113044949
2023-07-28 19:53:59 +01:00
swift_jenkins
3326d91a2c Merge remote-tracking branch 'origin/main' into next 2023-07-25 08:22:24 -07:00
Egor Zhdan
be34674915 Merge pull request #67375 from apple/egorzhdan/mutable-var-pointee
[cxx-interop] Import mutating dereference operators
2023-07-25 16:20:19 +01:00
swift_jenkins
a31c7211e6 Merge remote-tracking branch 'origin/main' into next 2023-07-24 09:43:25 -07:00
Egor Zhdan
43e6e97c1a Merge pull request #67482 from apple/egorzhdan/vector-of-string
[cxx-interop] Import iterator types that are not typedef-ed
2023-07-24 17:29:26 +01:00
Egor Zhdan
af014c02b3 [cxx-interop] Import iterator types that are not typedef-ed
This prevented `std::vector<std::string>` from being auto-conformed to `CxxRandomAccessCollection`.

If an iterator type is templated, and does not have an explicit instantiation via a typedef or a using-decl, its specialization will not have an owning Clang module. Make sure we treat it as a part of the Clang module that owns the template decl.

rdar://112762768 / resolves https://github.com/apple/swift/issues/67410
2023-07-24 11:25:15 +01:00
swift_jenkins
81614b11ec Merge remote-tracking branch 'origin/main' into next 2023-07-21 07:09:38 -07:00
Alex Lorenz
96806f4d44 [cxx-interop] Windows: unify address-only logic and mark non-trivial loadable C++ types as unavailable
Windows logic for determining address-only type layout for a C++ type is now unified with other platforms.
However, this means that on Windows, a C++ type with a custom destructor, but a default copy constructor
is now loadable, even though it's non-trivial. Since Swift does not support such type operations at the
moment (it can't be yet destroyed), mark such type as unavailable in Swift instead, when building for
the Windows target.

This fixes the Windows miscompilation related to such types when they were passed indirectly to C++
functions even though they're actually passed directly.
2023-07-20 14:58:02 -07:00
Egor Zhdan
8832d27e98 [cxx-interop] Import mutating dereference operators
C++ `T& operator*()` is mapped to a Swift computed property `var pointee: T`.

Previously `var pointee` only had a getter, after this change it will also have a setter if the C++ type declares an overload of `operator*` that returns a mutable reference.

rdar://112471779
2023-07-19 16:12:55 +01:00
Evan Wilde
8ce6ee8dd1 Updating API usages
LLVM deprecated, renamed, and removed a bunch of APIs. This patch
contains a lot of the changes needed to deal with that.

The SetVector type changed the template parameters.

APInt updated multiple names, countPopulation became popcount,
getAllOnesValue became getAllOnes, getNullValue became getZero, etc...

Clang type nullability check stopped taking a clang AST context.

The LLVM IRGen Function type stopped exposing basic block list directly,
but gained enough API surface that the translation isn't too bad.
(GenControl.cpp, LLVMMergeFunctions.cpp)

llvm::Optional had a transform function. That was being used in a couple
of places, so I've added a new implementation under STLExtras that
transforms valid optionals, otherwise it returns nullopt.
2023-07-17 10:53:42 -07:00
Alex Lorenz
a10332548c [cxx-interop] Do not add base class members that cause lookup ambiguities with a derived class member of the same name
Fixes https://github.com/apple/swift/issues/66323
2023-07-07 10:38:48 -07:00
Alex Lorenz
8ed840f9c1 [interop] do not warn about a template with too many specializations that can't be imported 2023-07-06 13:45:21 -07:00
Alex Lorenz
be65796b86 [interop] do not import function templates with template parameter not present in signature whose default value is dependent
rdar://107561753
2023-07-05 14:55:58 -07:00
Alex Lorenz
0be01c415f Merge pull request #67097 from hyp/eng/revert-8e0c17b27470de49fecf19d5a222ab247984d677
Revert "[interop] do not import functions whose return type is not imported"
2023-07-05 08:06:25 -07:00
Puyan Lotfi
936990864d [cxx-interop] Add-on commits to previous NS_OPTIONS fix PR
Add-on to address comments from #67036

Addresses some nits, test addons, and some code cleanups/improvement.
2023-07-03 15:41:50 -04:00
Alex Lorenz
14020201f5 Revert "[interop] do not import functions whose return type is not imported"
This reverts commit 8e0c17b274.
2023-07-03 10:06:54 -07:00
Puyan Lotfi
7cef628f94 [cxx-interop] Import ObjCPropertyDecl of type NS_OPTIONS fields a struct type
Try importing ObjCPropertyDecl field types the C++-Interop-NS_OPTIONS
way. This will fix cases such as:

```
import UIKit

func f(gesture: UISwipeGestureRecognizer,
       direction: UISwipeGestureRecognizer.Direction) {
  gesture.direction = direction // error
}
```

because it will make sure the field inside class UIGestureRecognizer is
of the enum-struct type and not the typedef-rawValue type when importing
an ObjC class.
2023-06-30 17:51:37 -04:00
Puyan Lotfi
ec5b7b0330 [NFC][cxx-interop] Refactor NS_OPTION type import handling code to be reusable.
Zoe did a nice fix on https://github.com/apple/swift/pull/66452
that I would like to reuse for ObjCPropertyDecl field types in
importObjCPropertyDecl as well. This will fix cases such as:

```
import UIKit

func f(gesture: UISwipeGestureRecognizer,
       direction: UISwipeGestureRecognizer.Direction) {
  gesture.direction = direction // error
}
```

because it will make sure the field inside class UIGestureRecognizer is
of the enum-struct type and not the typedef-rawValue type when importing
an ObjC class.
2023-06-30 16:40:43 -04:00
Zoe Carver
29c0b0d75f Merge pull request #66896 from zoecarver/fix-ambiguous-math-func
[cxx-interop] Pull over fix from 8e7766b and apply to strstr, sin, an…
2023-06-29 09:03:17 -07:00