Commit Graph

2550 Commits

Author SHA1 Message Date
swift-ci
ecd2566295 Merge remote-tracking branch 'origin/main' into rebranch 2021-07-29 05:53:06 -07:00
Hamish Knight
ebdae7ca00 Merge pull request #38504 from hamishknight/construction-site 2021-07-29 13:43:12 +01:00
Ben Barham
0389ea5b4e [ClangImporter] Add @available(*, renamed:) to imported async getters
The attribute was missing from functions with getters as their async
alternative. Only getters are imported like this, so no need to check
for the other accessors.

Resolves rdar://80612566
2021-07-29 15:07:23 +10:00
swift-ci
2d0de01eac Merge remote-tracking branch 'origin/main' into rebranch 2021-07-28 20:53:04 -07:00
Ben Barham
e7e9b57051 Replace @completionHandlerAsync with @available(*, renamed:)
Instead of a new attribute `@completionHandlerAsync`, allow the use of
the existing `renamed` parameter of `@available` to specify the
asynchronous alternative of a synchronous function.

No errors will be output from invalid names as `@completionHandlerAsync`
had, but if a function is correctly matched then it will be used to
output warnings when using the synchronous function in an asynchronous
context (as before).

Resolves rdar://80612731
2021-07-29 09:14:44 +10:00
Hamish Knight
72d4d9f1e9 [AST] Add some 'create' factory methods
This provides consistency with other AST nodes,
and will be useful for implementing ArgumentList
construction in the future.
2021-07-28 23:14:44 +01:00
Hamish Knight
c70f280e4a [AST] Add CallExpr::createImplicitEmpty
Add a convenience constructor for an implicit
nullary call. This will become more useful when
the argument parameter starts taking an
ArgumentList.
2021-07-28 23:14:43 +01:00
swift-ci
e25cb8a958 Merge remote-tracking branch 'origin/main' into rebranch 2021-07-28 12:17:04 -07:00
Egor Zhdan
e2985b64e8 Merge pull request #38618 from egorzhdan/cxx-mutating
C++ Interop: import const methods as non-mutating
2021-07-28 21:53:48 +03:00
swift-ci
7f01be19e6 Merge remote-tracking branch 'origin/main' into rebranch 2021-07-27 14:34:28 -07:00
Robert Widmann
a1b668b381 Merge pull request #38613 from CodaFi/extended-family-gathering
Nuke IgnoreNewExtensions From High Orbit
2021-07-27 14:32:39 -07:00
Egor Zhdan
a8f126f7cd C++ Interop: import const methods as non-mutating
This change makes ClangImporter import some C++ member functions as non-mutating, given that they satisfy two requirements:
* the function itself is marked as `const`
* the parent struct doesn't contain any `mutable` members

`get` accessors of subscript operators are now also imported as non-mutating if the C++ `operator[]` satisfies the requirements above.

Fixes SR-12795.
2021-07-25 15:18:33 +03:00
swift-ci
67017f7f6d Merge remote-tracking branch 'origin/main' into rebranch 2021-07-24 03:53:49 -07:00
Robert Widmann
babe52f512 Nuke IgnoreNewExtensions From High Orbit
This flag was always a hack to get clients that were not properly
handling circular constructions (module loading, associated type
inference) to stop crashing. Technically, it is unsound, but by sheer
coinicidence of the structure of the name lookup requests and the cache
faulting here we have never observed that unsoundness in the wild.
2021-07-23 15:35:24 -07:00
Egor Zhdan
cfc9483f1a C++ Interop: import namespaces redecls as separate extensions
Previously a namespace declaration was imported along with all of its redeclarations, and their members were added to a single Swift extension. This was problematic when a single namespace is declared in multiple modules – the extension belonged to only one of them.
For an example of this, try printing a module interface for `std.string`/`std.iosfwd` – it will be empty, even though the declarations from those modules are actually imported into Swift correctly.

This change makes sure that when we're importing different redeclarations of the same namespace, we're adding them as separate extensions to appropriate modules.
2021-07-23 23:38:46 +03:00
swift-ci
aa831950b4 Merge remote-tracking branch 'origin/main' into rebranch 2021-07-19 07:36:06 -07:00
Egor Zhdan
60a195e972 Merge pull request #38439 from egorzhdan/cxx-string-npos
C++ Interop: improve skipping already imported struct members
2021-07-19 10:27:30 +03:00
Egor Zhdan
fc2dc6aa17 C++ Interop: improve skipping already imported struct members
This fixes the issue that prevents `std::string::size_type` from being imported into Swift: `size_type` is imported before its parent struct, and  we're skipping it when importing the struct afterwards.

This is caused by an out-of-line decl for `std::string::npos`:
```cpp
template<class _CharT, class _Traits, class _Allocator>
_LIBCPP_FUNC_VIS
const typename basic_string<_CharT, _Traits, _Allocator>::size_type
               basic_string<_CharT, _Traits, _Allocator>::npos;

```
When importing `npos`, we first import `size_type`, which triggers the issue.
2021-07-17 14:45:22 +03:00
Evan Wilde
c75d19845f Merge pull request #38326 from etcwilde/ewilde/swift-rebranch
[Swift Rebranch] Cherry-picking swift changes from next branch
2021-07-12 13:24:29 -07:00
Doug Gregor
06bbc70b3e Module printing and serialization support for @unchecked Sendable 2021-07-11 12:29:54 -07:00
Doug Gregor
29f5d7a64a [SE-0302] Implement '@unchecked Sendable' syntax.
Parse and provide semantic checking for '@unchecked Sendable', for a
Sendable conformance that doesn't perform additional semantic checks
for correctness.

Part of rdar://78269000.
2021-07-11 12:29:53 -07:00
Evan Wilde
4046f61ba9 VK_RValue -> VK_PRValue
Clang updated the naming in commit
aef5d8fdc7d0d348125d5ecf4a13be5888eb1654 in order to be more consistent
with c++11 category naming.
2021-07-08 16:48:10 -07:00
Egor Zhdan
340c85503e Merge pull request #38121 from egorzhdan/cxx-init-static
C++ Interop: avoid adding static members to the value constructor
2021-06-29 22:09:55 +03:00
Egor Zhdan
0aebf79676 C++ Interop: avoid adding static members to the value constructor
Value constructors for C++ structs shouldn't try to initialize static members of the struct.
2021-06-28 21:35:08 +03:00
Doug Gregor
7a1ab7aa79 Merge pull request #37970 from DougGregor/clang-swift-attr-for-modifiers 2021-06-22 07:57:01 -07:00
Doug Gregor
6ba26292b1 [Clang importer] Import Swift declaration modifiers from swift_attr.
In addition to importing Swift attributes spelled with the C
`__attribute__((swift_attr("...")))`, also import declaration modifiers,
including `nonisolated`.

Fixes rdar://79402200.
2021-06-17 10:25:42 -07:00
Becca Royal-Gordon
05b9aecf3b Don’t crash from circular swift_name attributes
If a swift_name attribute’s context referred to the same declaration it was attached to, or a different declaration whose own swift_name referred to the current one, we would recurse infinitely and eventually overflow the stack. This commit makes us instead detect the cycle, diagnose it with a warning, and drop the affected declaration.

Fixes rdar://79370809.
2021-06-15 18:58:37 -07:00
Doug Gregor
03f55d7bb4 Revert "Revert "Remove @actorIndependent attribute.""
This reverts commit 7c0b50e8ea.
2021-06-03 14:03:57 -07:00
Karoy Lorentey
7c0b50e8ea Revert "Remove @actorIndependent attribute." 2021-05-24 14:43:32 -07:00
Zoe Carver
069e51d05e Merge pull request #37443 from egorzhdan/cxx-namespace-alias
C++ Interop: import namespace aliases
2021-05-22 20:44:05 -07:00
Doug Gregor
d6e8fd81f5 Remove @actorIndependent attribute.
`@actorIndependent` has been superseded by `nonisolated`. Remove
the old spelling entirely.
2021-05-17 12:21:10 -07:00
Egor Zhdan
51a8c473ff C++ Interop: import namespace aliases
Previously they weren't imported, now they are imported as typealiases to enums representing namespaces.

Fixes SR-12467.
2021-05-16 17:34:51 +03:00
Puyan Lotfi
7d7a6c6bcc [cxx-interop] Detect IndirectFields nested in non-importable anon-unions
This patch to the Clang Importer avoids an assert by detecting when an
IndirectField belongs to an anonymous union that is not importable. How
it does this is by determining if an IndirectFieldDecl's anonymous
parent field is non-importable (based on isCxxRecordImportable) and if
so skips importing the IndirectFieldDecl.

This avoids the mentioned assert because makeIndirectFieldAccessors
expects a FieldDecl of __Unnamed_union___Anonymous_field that is only
populated when the top-level union is imported from an
IndirectFieldDecl's parent. IndirectFieldDecls for the members of an
anonymous union are dependent on their parent and should not be imported
if their parent can not also be imported.

This corner case can happen in cases when an anonymous union contains an
ARC pointer, which results in a non-trivial but also inaccessible dtor.
2021-05-13 07:31:33 -10:00
Argyrios Kyrtzidis
25c366d8c7 Merge pull request #37170 from hamishknight/take-two
Mark imported @completionHandlerAsync attrs as implicit
2021-04-30 10:18:08 -07:00
Hamish Knight
f439275380 Mark imported @completionHandlerAsync attrs as implicit
Mark imported `@completionHandlerAsync` attrs as
implicit, which avoids printing them in generated
interfaces. And for the sake of completion,
serialize the implicit bit in case it's used
elsewhere in the future.

To make sure we continue to print
`@completionHandlerAsync` attributes explicitly
written by the user in Swift, add a SourceKit
interface test.

Resolves rdar://76685011
2021-04-30 11:14:50 +01:00
Doug Gregor
bf30b41e5b [Clang importer] Fix mirroring of protocol decls for 'async' imports.
The de-duplication checks to preventing redundant mirroring of protocol
declarations failed to consider that a given method could be
implemented as both 'async' and non-'async' declarations, and
therefore would fail to mirror the 'async' form. Account for this
distinction.

Fixes rdar://76799297.
2021-04-30 01:05:03 -07:00
Azoy
9ed732f0ab Introduce isDecl and getDeclType
fix enum logic issue

fix tests

guard against null types
2021-04-20 02:22:16 -04:00
Kavon Farvardin
4f6eb85fe3 allow type initializers to be 'async'
implicit calls to an async super.init are not allowed
2021-04-15 10:08:53 -07:00
Puyan Lotfi
864b3a47e3 [cxx-interop] Implement operator[] for value return types (SR-14351).
This builds on top of the work of Egor Zhdan. It implements
`T operator[]` and does so largely by taking a path very much like the
`const T &operator[]` path.
2021-04-08 00:18:27 -04:00
Kavon Farvardin
ab47660d75 allow ObjC methods with completion handlers be imported as effectful properties
either as an `async` or `async throws` property, by marking it
with swift_async_name("getter:PROPERTY_NAME()") where `PROPERTY_NAME`
will be the name of the property it will be imported as.

This is in lieu of being imported as an async method. It's still
imported as an `@objc` method as well.
2021-04-02 08:33:22 -07:00
swift-ci
ac88ce5072 Merge pull request #36655 from kavon/double-double-mainactor-style 2021-04-02 00:35:30 -07:00
Kavon Farvardin
64f6182cc7 prevent double @MainActor annotation in ClangImporter
This can lead to latent type errors for API users,
because a swiftmodule would otherwise be emitted,
without any diagnostics, containing imported decl
with two global actor annotations on it. Such
decls will always be an error to the typechecker
when its eventually encountered.

This patch drops all `@MainActor` annotations after
the first one in the ClangImporter, regardless of
whether its the safe or unsafe version, and emits
a warning when doing so.
2021-03-31 17:11:45 -07:00
Kavon Farvardin
5a29c056c1 fix argument ordering in call to AccessorDecl::create
async before throws, just like in language's syntax
2021-03-31 16:58:59 -07:00
Doug Gregor
b68f8555b3 [Concurrency] Introduce "unsafe" @Sendable and @MainActor parameters.
Introduce the notion of "unsafe" @Sendable parameters, indicated by the
hidden @_unsafeSendable parameter attribute. Closure arguments to such
parameters are treated as @Sendable within code that has already
adopted concurrency, but are otherwise enert, allowing them to be
applied to existing concurrency-related APIs to smooth the transition
path to concurrency.

Additionally, introduce the notion of an "unsafe" @MainActor closure,
for cases where we have determined that the closure will execute on
the main actor but it (also) isn't part of the type system.

Pattern-match uses of the Dispatch library's DispatchQueue to infer
both kinds of "unsafe" as appropriate, especially (e.g.) matching the pattern

  DispatchQueue.main.async { ... }

to treat the closure as unsafe @Sendable and @MainActor, allowing such
existing code to better integrate with concurrency.

Implements rdar://75988966.
2021-03-31 09:40:03 -07:00
Ben Barham
3de83aca66 [ClangImporter] Add @completionHandlerAsync for imported decls
Implicitly add the @completionHandlerAsync attribute for ObjCMethodDecl
that have a completion handler. Adds a link from the non-async to the
async function for use in diagnostics and refactorings.

Resolves rdar://74665226
2021-03-31 08:39:12 +10:00
Kavon Farvardin
1a370d0aaf fix broken merge 2021-03-30 14:32:35 -07:00
Egor Zhdan
d0879b9e3b Merge pull request #36365 from egorzhdan/cxx-operator-subscript
C++ Interop: import subscript operators
2021-03-30 22:57:44 +03:00
Kavon Farvardin
f9452b23f4 implement parsing for effects specifiers on 'get' accessors
An effectful 'get' accessor must be the only accessor for the
property.
2021-03-26 07:54:53 -07:00
Doug Gregor
c1bc4702ae Merge pull request #36580 from DougGregor/import-main-actor-sendable-closures 2021-03-25 07:30:33 -07:00
Doug Gregor
5f71e52146 [Clang import] Apply main-thread annotations from parameters to types.
Import a main-thread annotation on a function/method parameter in
(Objective-)C as a `@MainActor` function type.
2021-03-24 22:28:29 -07:00