Commit Graph

63 Commits

Author SHA1 Message Date
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
Hamish Knight
ee49794d0f [AST] Introduce Argument::implicitInOut
This will allow us to abstract away the creation
of InOutExpr for bits of code synthesis.
2022-08-08 15:10:51 +01:00
Egor Zhdan
1be0086413 [cxx-interop] Mark operator! as prefix func
Prefix operators in Swift need to be marked as `prefix func`.

For example, the lack of `prefix` attribute prevents the user from conforming a C++ type that defines `operator!` to a Swift protocol that requires `static prefix func !(obj: Self) -> Self`.
2022-07-15 14:50:36 +01:00
Egor Zhdan
d29b78eed1 [cxx-interop] Import increment operators
C++ pre-increment operator `T& T::operator++()` is mapped into a non-mutating function `successor() -> Self`.

The naming matches existing functions for `UnsafePointer`/`UnsafeMutablePointer`.

The purpose of this is to be used for iterator bridging: C++ requires iterators to define a pre-increment operator (https://en.cppreference.com/w/cpp/named_req/Iterator), which Swift will use to iterate over C++ sequences and collections.
2022-06-20 17:38:11 +01:00
Egor Zhdan
1839ddb115 [ClangImporter] NFC: extract Swift decl synthesis logic into a separate file
`ImportDecl.cpp` contained 10k+ lines of code, which caused slowdowns in incremental compilation and while editing the code in the IDE.

This change extracts a chunk of largely self-contained decl synthesis logic into a separate file.
2022-06-17 16:52:18 +01:00