Commit Graph

1905 Commits

Author SHA1 Message Date
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
zoecarver
b280d26a7b [cxx-interop] Fix class template instantiation.
Lazily instantiate class template members. This means we no longer
reject some programs that clang accepts, such as the following:

```
template<class T> struct Foo { void fail(T value) { value.fail(); } };
using Bar = Foo<int>;
```

The above program will not error so long as `Bar::fail` isn't called.
(Previously, we'd fail to import `Bar`.)
2021-02-24 11:25:45 -08:00
Zoe Carver
bc6a7a6696 Merge pull request #35963 from zoecarver/cxx/bail-on-large-templates
[cxx-interop] Bail on deep template specializations.
2021-02-17 10:47:41 -08:00
zoecarver
2f0e7fc698 [cxx-interop] Bail on deep template specializations.
If a template specialization is more than 8 types deep, bail.

In future we could make this number (much) greater than 8 but first
we'll need to somehow make instantiating these types much fater.
Currently, I think there is some exponential type behavior happening so
this is super slow.
2021-02-16 10:34:52 -08:00
swift-ci
8cc5e96d08 Merge pull request #35990 from zoecarver/cxx/gardening/count-to-find 2021-02-15 23:49:35 -08:00
zoecarver
e70fb00f06 [nfc] Replace count() with find().
Addresses the post commit review comment in #35964 and replaces "count()"
with "find() != end()".
2021-02-15 21:10:53 -08:00
Doug Gregor
3d4091ccaa Merge pull request #35982 from DougGregor/clang-importer-concurrency-tweaks 2021-02-15 19:56:51 -08:00
Doug Gregor
a8f91c4efa [Clang importer] Allow @UIActor as an alias for @MainActor.
We've flip-flopped on the name a bit. Accept both for now.
2021-02-15 15:29:46 -08:00
Doug Gregor
c732ba3bf9 [Clang importer] Make @actorIndependent on imported macros implicit.
This prevents it from printing in Swift interfaces, which is a bit noisy.
2021-02-15 15:18:53 -08:00
Zoe Carver
6eb00d5c39 Merge pull request #35964 from zoecarver/cxx/another-double-add-fix
[cxx-interop] Skip already-imported sub decls.
2021-02-15 09:54:04 -08:00
Zoe Carver
ea9ce7e8d5 Merge pull request #35085 from zoecarver/cxx/central-cxx-module
[cxx-interop] Re-implement namespaces using enums + extensions.
2021-02-14 21:19:49 -08:00
zoecarver
bd96959d14 [cxx-interop] Re-implement namespaces using enums + extensions.
C++ namespaces are module-independent, but enums are owned by their module's in Swift. So, to prevent declaring two enums with the same name, this patch implements a new approach to namespaces: enums with extensions.

Here's an example:
```
// Module A
namespace N { void test1(); }
// Module B
namespace N { void test2(); }
// __ObjC module
enum N { }
// Swift module A
extension N { func test1() }
// Swift module B
extension N { func test1() }
```

Thanks to @gribozavr for the great idea.
2021-02-14 16:54:24 -08:00
swift-ci
f5e32aa610 Merge pull request #35957 from DougGregor/remove-hasAnyUnsafePointerParameters 2021-02-12 18:56:09 -08:00
zoecarver
fc33728613 [cxx-interop] Skip already-imported sub decls.
Rather than skipping non-definitions, we should just check whether we've
already seen this decl. This not only fixes the specific problem with
class templates but also is a more general fix for other sub decls.
2021-02-12 16:32:41 -08:00
Doug Gregor
62c10b1896 Remove unused function hasAnyUnsafePointerParameters() 2021-02-12 16:02:32 -08:00
Doug Gregor
71e0b1d90c [Clang importer] Don't suppress properties due to async method imports.
The Clang importer had some logic to suppress the import of a property that
had the same name as a method with no parameters. This logic
inadvertently meant that an async import of a completion-handler method
could prevent a (non-async) property of the same name to not be
imported, breaking existing code. In such cases, don't suppress the
property import.

Fixes rdar://73326019.
2021-02-12 13:19:16 -08:00
Doug Gregor
e4986a3514 [Clang importer] Remove @asyncHandler inference for Objective-C methods
The rule was inconsistent and required a lot of auditing, and could
cause surprises. We can consider bringing it back at another time.
2021-02-11 23:33:54 -08:00
Doug Gregor
abb5fbf1ce [Clang importer] Remove @asyncHandler inference for Objective-C methods
The rule was inconsistent and required a lot of auditing, and could
cause surprises. We can consider bringing it back at another time.
2021-02-11 22:37:28 -08:00
Evan Wilde
fc41826da9 Rename 'actor class' -> 'actor'
This patch softly updates the spelling of actors from `actor class` to
`actor`. We still accept using `actor` as a modifying attribute of
class, but emit a warning and fix-it to make the change.

One of the challenges that makes this messier is that the modifier list
can be in any order. e.g, `public actor class Foo {}` is the same as
`actor public class Foo {}`.

Classes have been updated to include whether they were explicitly
declared as an actor. This change updates the swiftmodule serialization
version number to 0.591. The additional bit only gets set of the class
declaration was declared as an actor, not if the actor was applied as an
attribute. This allows us to correctly emit `actor class` vs `actor`
emitting the code back out.
2021-02-10 08:05:57 -08:00
Doug Gregor
e2893cf138 [Concurrency] Disable async imports for Apple APIs deprecated by ~2018.
Implements rdar://73620586.
2021-02-09 14:43:45 -08:00
Zoe Carver
74b7341b2d Merge pull request #32378 from zoecarver/cxx/copy-const
[cxx-interop] Use user defined copy constructor to copy C++ objects.
2021-02-03 22:39:57 -08:00
zoecarver
b2b7f7b853 [cxx-interop] Use user defined copy constructor to copy C++ objects.
If a user-defined copy constructor exists, use that to copy imported C++
types.
2021-02-03 14:34:07 -08:00
swift-ci
e349794517 Merge remote-tracking branch 'origin/main' into rebranch 2021-01-27 04:12:41 -08:00
Marcel Hlopko
4f5c75a236 [cxx-interop] Instantiate C++ class templates from Swift (#33284)
This PR makes it possible to instantiate C++ class templates from Swift. Given a C++ header:

```c++
// C++ module `ClassTemplates`
template<class T>
struct MagicWrapper {
  T t;
};

struct MagicNumber {};
```

it is now possible to write in Swift:

```swift
import ClassTemplates

func x() -> MagicWrapper<MagicNumber> {
  return MagicWrapper<MagicNumber>()
}
```

This is achieved by importing C++ class templates as generic structs, and then when Swift type checker calls `applyGenericArguments` we detect when the generic struct is backed by the C++ class template and call Clang to instantiate the template. In order to make it possible to put class instantiations such as `MagicWrapper<MagicNumber>` into Swift signatures, we have created a new field in `StructDecl` named `TemplateInstantiationType` where the typechecker stores the `BoundGenericType` which we serialize. Deserializer then notices that the `BoundGenericType` is actually a C++ class template and performs the instantiation logic.

Depends on https://github.com/apple/swift/pull/33420.
Progress towards https://bugs.swift.org/browse/SR-13261.
Fixes https://bugs.swift.org/browse/SR-13775.

Co-authored-by: Dmitri Gribenko <gribozavr@gmail.com>
Co-authored-by: Rosica Dejanovska <rosica@google.com>
2021-01-27 13:01:20 +01:00
swift-ci
f309608ccc Merge remote-tracking branch 'origin/main' into rebranch 2021-01-26 15:32:32 -08:00