Commit Graph

54 Commits

Author SHA1 Message Date
Kuba (Brecka) Mracek
8792efedf0 Merge pull request #77115 from kubamracek/embedded-mangling-prefix
[Mangling] [NFC] Prepare for a new mangling prefix for Embedded Swift: $e
2024-12-03 08:10:49 -08:00
Kuba Mracek
6f4ae28520 [ASTMangler] Pass ASTContext to all instantiations of ASTMangler 2024-12-02 15:01:04 -08:00
Hamish Knight
73fb36f371 [AST] Split out "is compound" bit on FunctionRefInfo
FunctionRefKind was originally designed to represent
the handling needed for argument labels on function
references, in which the unapplied and compound cases
are effectively the same. However it has since been
adopted in a bunch of other places where the
spelling of the function reference is entirely
orthogonal to the application level.

Split out the application level from the
"is compound" bit. Should be NFC. I've left some
FIXMEs for non-NFC changes that I'll address in a
follow-up.
2024-12-02 14:11:33 +00:00
Hamish Knight
a4d51419ba [AST] NFC: Rename FunctionRefKind -> FunctionRefInfo 2024-12-02 14:11:32 +00:00
Egor Zhdan
6943986c71 [cxx-interop] Import private fields of C++ structs
While private and protected fields coming from C++ cannot be accessed from Swift, they can affect Swift typechecking.

For instance, the Swift typechecker mechanism that adds implicit `Sendable` conformances works by iterating over all of the struct's fields and checking whether all of them are `Sendable`. This logic was broken for C++ types with private fields, since they were never accounted for. This resulted in erroneous implicit `Sendable` confromances being added.

Same applies for `BitwiseCopyable`.

In addition to this, ClangImporter used to mistakenly mark all C++ structs that have private fields as types with unreferenceable storage, which hampered optimizations.

As a side effect of this change, we now also provide a better diagnostic when someone tries to access a private C++ field from Swift.

rdar://134430857
2024-11-12 12:47:26 +00:00
swift-ci
1b23f6a9b2 Merge remote-tracking branch 'origin/main' into rebranch 2024-08-29 20:55:52 -07:00
Akira Hatanaka
5bd7a27e96 [cxx-interop] Do not over-release objects returned by synthesized C++ methods (#76139)
Call Sema::BuildReturnStmt instead of ReturnStmt::Create so that an
implicit cast of kind ARCProduceObject is inserted in the AST.

rdar://133731973
2024-08-29 20:45:16 -07:00
Egor Zhdan
fc4f6480a8 [cxx-interop][rebranch] Do not crash for static operator()
This fixes an assertion failure:
```
Assertion failed: (isInstance() && "No 'this' for static methods!"), function getThisType, file DeclCXX.cpp, line 2636.
```

Clang changed it's handling of member call expressions in af4751738d causing the assertion to fail when synthesizing a forwarding function declaration for `static operator()`.

rdar://133257179
2024-08-15 16:31:17 +01:00
swift-ci
a32c1896dc Merge remote-tracking branch 'origin/main' into rebranch 2024-07-10 23:09:47 -07:00
Meghana Gupta
8137aed238 Rename LifetimeDependentReturnTypeRepr -> LifetimeDependentTypeRepr 2024-07-10 14:20:03 -07:00
swift-ci
b7921a8232 Merge remote-tracking branch 'origin/main' into rebranch 2024-07-06 14:34:09 -07:00
Slava Pestov
fae01d9776 AST: Remove ModuleDecl parameter from more places 2024-07-06 12:05:46 -04:00
Xi Ge
736ccef626 Merge remote-tracking branch 'apple/main' into rebranch 2024-06-20 15:16:55 -07:00
Tim Kientzle
1098054291 Merge branch 'main' into tbkka-assertions2 2024-06-18 17:52:00 -07:00
swift-ci
a2eb7713c4 Merge remote-tracking branch 'origin/main' into rebranch 2024-06-12 15:33:10 -07:00
Alex Lorenz
2039b8d254 [cxx-interop] import static operator call from C++23 as member callAsFunction functions in Swift to preserve source compatibility 2024-06-12 09:11:15 -07:00
Tim Kientzle
1d961ba22d Add #include "swift/Basic/Assertions.h" to a lot of source files
Although I don't plan to bring over new assertions wholesale
into the current qualification branch, it's entirely possible
that various minor changes in main will use the new assertions;
having this basic support in the release branch will simplify that.
(This is why I'm adding the includes as a separate pass from
rewriting the individual assertions)
2024-06-05 19:37:30 -07:00
swift-ci
a0dc01e3e5 Merge remote-tracking branch 'origin/main' into rebranch 2024-05-06 05:33:47 -07:00
Egor Zhdan
ae27e884d5 [cxx-interop] Do not crash when calling a subscript with unnamed parameter
This fixes a crash in SILGen when calling a C++ subscript that has an unnamed parameter from Swift.

The parameters from a C++ `operator[]` get carried over to the synthesized Swift subscript. If the Swift parameter has no name, there is no way to refer to it in SIL. However, the synthesized subscript accessor needs to pass this parameter to C++.

This change makes sure that we give a name to the Swift parameter if there isn't already a name on the C++ side.

rdar://83163841
2024-05-01 12:30:18 +01:00
Ben Barham
0c0c4ea7c3 [ClangImporter] Use new CXXThisExpr::Create function
The constructor takes a new arg which `Create` now handles. Use it
instead.
2024-04-08 08:58:58 -07: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
638abd991f [cxx-interop] Refactor: move synthesis logic elsewhere 2024-03-01 15:57:33 +00: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
Meghana Gupta
c8ece100ba Handle explicit lifetime dependence specifiers in initializers 2024-02-02 11:50:10 -08:00
Slava Pestov
af3ab14986 SILGen: Clean up substitution map construction to deal with Copyable 2024-01-31 21:55:52 -05:00
Kavon Farvardin
b8cd7effeb Merge pull request #70866 from kavon/ncgenerics-stdlib-building-v4
Build Stdlib with Noncopyable Generics (Part 4)
2024-01-25 07:09:38 -08:00
Kavon Farvardin
3e03c674c7 [NCGenerics] remove arg from isNoncopyable(DC)
It should be the responsibility of callers to map the type to a
contextual type, as needed. When it's not possible or repetitive to do
so, there is a special-purpose function `isInterfaceTypeNoncopyable` for
 Sema.
2024-01-23 22:42:38 -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
Egor Zhdan
494474b021 [cxx-interop] Support C++ default arguments
This allows calling a C++ function with default arguments from Swift without having to explicitly specify the values of all arguments.

rdar://103975014
2024-01-10 16:37: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
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
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
16a8ae42ef [cxx-interop] fix the use of '.pointee' with address accessors for derived-to-base synthesized accessors 2023-11-29 15:10:27 -08:00
Alex Lorenz
a913c4e10a [cxx-interop] fix support for value-only non-copyable type dereference 2023-11-27 14:04:26 -08:00
Alex Lorenz
5d2637a8fe [cxx-interop] add support for 'mutableAddress' pointee for non-copyable C++ types 2023-11-27 09:59:33 -08:00
Egor Zhdan
ece33a4d15 [cxx-interop] Import using decls that refer to member operators of a base class
This is required for proper support for `std::vector::iterator` on Windows.

rdar://118657936 / resolves https://github.com/apple/swift/issues/69990
2023-11-20 18:57:12 +00:00
Alex Lorenz
86e5556e91 [cxx-interop] add support for 'address' pointee for non-copyable C++ types 2023-11-16 10:08:30 -08:00
Priyansh Prajapat
81fdad9a47 fix: typo in SwiftDeclSynthesizer.cpp from intializers to initializers 2023-10-31 12:54:56 +05:30
Sophia Poirier
4c9a726183 nonisolated(unsafe) to opt out of strict concurrency static checking for global variables 2023-10-26 16:22:28 -07:00
Doug Gregor
5ad39c84e0 [Typed throws] Record thrown error types and conversions in the AST
For any operation that can throw an error, such as calls, property
accesses, and non-exhaustive do..catch statements, record the thrown
error type along with the conversion from that thrown error to the
error type expected in context, as appropriate. This will prevent
later stages from having to re-compute the conversion sequences.
2023-10-24 12:40:22 -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
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
Egor Zhdan
b860fddd52 [cxx-interop] Fix assertion failure in IRGen with mutable dereference operators
I discovered this when experimenting with `std::map::iterator`, which has a const overload of `operator*` that returns a non-const reference, and does not have a const overload of `operator*`.

rdar://112471779
2023-07-27 15:54:09 +01: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
Egor Zhdan
fec48f9e63 [cxx-interop] Synthesize a deprecated zero initializer for C++ structs
When importing a C header in the C++ language mode, Clang/Swift treat C structs as C++ structs.

Currently Swift synthesizes a default initializer that zero-initializes the backing memory of the struct for C structs, but not for C++ structs.

This is causing issues in existing projects that use C libraries and rely on having the default initializer available in Swift. This change enables the synthesis of a default initializer for C++ structs. Since many C++ structs are not designed to be initialized this way, the initializer is marked as deprecated in Swift.

rdar://109727620
2023-05-31 13:41:25 +01:00
Erik Eckstein
782b777658 clang importer: don't trigger stack protection when accessing an imported enum
rdar://108867547
2023-05-04 09:49:02 +02:00
Luciano Almeida
a95f60e387 [AST] Refactor generic parameter list parse logic for AccessorDecl 2022-10-07 09:43:08 -03:00
Hamish Knight
ff768b9024 [ClangImporter] Mark some synthesized Clang decls implicit
I was hoping this would be enough to avoid the
crash in rdar://82820628, as we shouldn't emit
coverage mappings for synthesized Clang decls,
but it seems it can still cause Clang to crash
(rdar://100172217). Regardless, it seems like
these should be implicit anyway, so mark them as
such.
2022-09-20 15:58:06 +01:00
Hamish Knight
6b9bcf3935 [AST] Change DotSyntaxCallExpr to take an Argument base
This allows us to more easily propagate inout
information to it, which will become a necessity
once InOutExpr is removed.
2022-08-08 15:11:00 +01:00