Commit Graph

2529 Commits

Author SHA1 Message Date
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
Varun Gandhi
6202dd65ee Merge pull request #36553 from zoecarver/cxx/fix-deep-template-spec
[cxx-interop] Improve performance of deep template instantiations.
2021-03-23 22:44:45 -07:00
swift-ci
a4db7c8c27 Merge pull request #36560 from DougGregor/show-imported-main-actor 2021-03-23 20:06:41 -07:00
Doug Gregor
a109736937 Make sure that imported @MainActor shows up in the interface.
... but don't show the (unsafe) part outside of Swift interfaces, because
it's messy and we don't want people to use it.
2021-03-23 17:29:58 -07:00
zoecarver
3cd6c80268 [cxx-interop] Improve performance of deep template instantiations.
If there are more than 10,000 instantiations of the same class template
then we need to bail because it will take to long to mangle,
instantiate, etc.
2021-03-23 16:58:39 -07:00
zoecarver
41743222a2 [cxx-interop] Don't instantiate empty class template specializations.
If we try to instantiate the static data members of an empty class
template specialization we'll crash because there is no template param
pattern.
2021-03-23 11:25:34 -07:00
Doug Gregor
da4b28dabe Merge pull request #36512 from DougGregor/isolation-inference-fallthrough
[Concurrency] Don't let "unsafe" inference block other inference.
2021-03-22 13:29:00 -07:00
Egor Zhdan
586c675286 C++ Interop: import subscript operators
This change adds support for calling `operator[]` from Swift code via a synthesized Swift subscript.

Fixes SR-12598.
2021-03-21 19:25:41 +03:00
Zoe Carver
3b064380d4 Merge pull request #35962 from zoecarver/cxx/fix-invalid-decls
[cxx-interop] Don't crash when importing invalid decl.
2021-03-19 21:41:04 -07:00
zoecarver
794c0ea1f0 [cxx-interop] Don't crash when importing invalid decl.
If we see an invalid decl, rather than potentially crashing, simply
bail.
2021-03-19 11:38:18 -07:00
Doug Gregor
e316a8ef90 [Importer] While pretty-printing decls for diagnostics, don't emit diagnostics.
The diagnostics system doesn't allow a diagnostic to be emitted while
another diagnostic is in flight. Doing so will cause an assertion in
the diagnostics machinery.

There's a longstanding cycle here when diagnostics emission
pretty-prints declarations that are imported from a Clang module, and
the Clang Importer emits a diagnostic. Squash this cycle forcefully,
dropping the diagnostic that the Clang importer would emit.
2021-03-19 09:33:55 -07:00
Zoe Carver
79f7745bc3 Merge pull request #36343 from zoecarver/fix/inherit-deleted-copy-ctor
[cxx-interop] Bail earlier when importing invalid records.
2021-03-17 23:31:16 -07:00
zoecarver
abab6b3332 [cxx-interop] Bail earlier when importing invalid records.
If we have a C++ record decl that's invalid (because of a deleted
destructor or copy constructor), bail before we import any of its
members or cache the decl. This way, we don't accidentally import any
"nested" decls.
2021-03-17 11:25:07 -07:00
Doug Gregor
7f6b681ced [Parser] Parse custom attributes on types.
Extend the parsing of custom attributes to apply to types. Improve the
lookahead for the arguments so we don't arbitrarily consume the parameter
list of a function type as an attribute argument, or consume a tuple type
as the attribute argument.

Doesn't actually change behavior, because after parsing the custom
attribute on a type, we reject it as an unknown attribute.
2021-03-16 19:52:05 -07:00
David Zarzycki
c0ec6c3235 [AST] NFC: Make ExtInfo param Optional<>
While it is very convenient to default the ExtInfo state when creating
new function types, it also make the intent unclear to those looking to
extend ExtInfo state. For example, did a given call site intend to have
the default ExtInfo state or does it just happen to work? This matters a
lot because function types are regularly unpacked and rebuilt and it's
really easy to accidentally drop ExtInfo state.

By changing the ExtInfo state to an optional, we can track when it is
actually needed.
2021-03-09 05:57:39 -05:00
Zoe Carver
3981a7c198 Merge pull request #35222 from zoecarver/cxx/fix-using-shadow
[cxx-interop] Using shadow with class template.
2021-03-07 13:51:39 -08:00
zoecarver
655c381b32 [cxx-interop] Using shadow with class template.
Fail correctly if we can't import a shadow decl properly. We can
probably support this in the future, but right now, it's more important
that we don't crash while importing.
2021-03-07 10:55:38 -08:00
Slava Pestov
2a1b985f9e AST: PrettyStackTraceConformance doesn't need to take the ASTContext 2021-03-05 21:30:14 -05:00
Egor Zhdan
7141ae24cf C++ Interop: import call operators
This change adds support for calling `operator()` from Swift code.

As the C++ interop manifesto describes, `operator()` is imported into Swift as `callAsFunction`.
2021-03-02 21:13:57 +03:00
Zoe Carver
f64b7c4d75 Merge pull request #35819 from zoecarver/cxx/fix-full-inst
[cxx-interop] Fix class template instantiation.
2021-02-26 12:14:41 -08:00
Doug Gregor
451e6cc1f5 [Concurrency] Add support for @GlobalActor(unsafe).
Allow us to tag declarations that are meant to be in a global actor, but
for which we don't yet want to enforce everything. This will be used for
better staging-in of global actor annotations, but for now it's a fancy
way to document @actorIndependent(unsafe).

Stages in the syntax for rdar://74241687 without really implementing it.
2021-02-25 22:41:32 -08:00
Doug Gregor
77105a4ee5 Enable SE-0297: Concurrency Interoperability with Objective-C 2021-02-24 14:18:16 -08:00