Commit Graph

254 Commits

Author SHA1 Message Date
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
Robert Widmann
2b9ad67029 Un-XFAIL a Passing Test on Windows 2021-04-20 17:14:56 -07:00
Egor Zhdan
5e1c8ea1b1 Merge pull request #36881 from egorzhdan/cxx-lookup-fix
C++ Interop: fix crash for Swift extensions of C++ classes declared in namespaces
2021-04-20 17:28:18 -04:00
Egor Zhdan
9adad3202e C++ Interop: add tests for extensions of C++ classes 2021-04-16 20:25:57 +03:00
John McCall
34d4ea6b3c Fix test member-inline-silgen.swift for the stripping of [serializable] 2021-04-09 01:38:06 -04:00
Saleem Abdulrasool
68ff55a07e Merge pull request #36688 from plotfi/cxx-operator-subscript
[cxx-interop] Implement operator[] for value return types (SR-14351).
2021-04-08 19:11:27 -07:00
Slava Pestov
1e8ce52736 SIL: Strip [serialized] flag from functions even at -Onone
While the comment is correct to state that this won't enable any
new optimizations with -Onone, it does enable IRGen's lazy
function emission, which is important for 'reasync' functions,
which we don't want to emit at all even at -Onone.

This fixes debug stdlib builds with the new reasync versions
of the &&, || and ?? operators.
2021-04-08 01:47:27 -04: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
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
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
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
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
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
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
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
Egor Zhdan
86dadacac1 Merge pull request #36144 from egorzhdan/cxx-operators-tests-cleanup
C++ Interop: cleanup operator tests (NFC)
2021-03-02 21:13:24 +03:00
zoecarver
58697677a4 [nfc] Fix class-template-uninstantiable-members-irgen for i386.
This is just a matter of changing the regex expression.
2021-03-01 12:41:38 -08: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
Egor Zhdan
6d5eba92b9 C++ Interop: cleanup operator tests (NFC) 2021-02-25 01:16:49 +03: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
43c7ad7f46 Merge pull request #34864 from zoecarver/cxx/fix/friends
[cxx-interop] Support forward declared records inside other records.
2021-02-22 22:06:34 -08:00
zoecarver
f6a31e0483 [cxx-interop][nfc] Support forward declared records inside other records.
The pattern:

    struct X { friend struct Y; }; struct Y {};

is fairly common. But before this commit we would crash while attempting
to add "Y" as a child of "X". This commit simply checks if the child
record is a declaration or definition. If the former, it bails (and the
"child" record will be imported where it's defined).
2021-02-22 13:02:02 -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
zoecarver
467ff0a796 [nfc][gardening] Add requires cplusplus to LinkedRecords module. 2021-02-15 21:02:37 -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
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
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
Daniel Rodríguez Troitiño
182a011ec7 [android][test] XFAIL memory-layout-silgen in Android ARMv7 (#35816)
Change the original UNSUPPORTED to XFAIL, to get signal if the test
starts working.

PR #35707 should allow this test to work properly.
2021-02-07 16:30:03 -08:00
buttaface
e6f5913772 [android] Move to the NDK's unified sysroot (#34491)
Since the NDK removes the platforms/ and sysroot/ directories in the latest NDK
22, switch to the unified sysroot in toolchains/llvm/ and take advantage of a
bunch of simplification that's now possible.
2021-02-07 09:19:18 -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
Mishal Shah
5210c3b38f Merge pull request #35663 from apple/pr-rebranch
Support new changes from swift/rebranch on llvm-project repo
2021-02-01 17:42:27 -08:00
Arnold Schwaighofer
d4591338dd Disable Interop/Cxx/value-witness-table/custom-destructors-non-virtual-irgen.swift on arm64e the 2nd
The previous PR missed the  part.

rdar://73755064
2021-02-01 12:22:39 -08:00
swift-ci
a996a1dc25 Merge remote-tracking branch 'origin/main' into rebranch 2021-02-01 09:28:17 -08:00
Mike Ash
503dd1832e [Test] Disable witness-layout-opts-irgen.swift, failing on 32-bit 2021-02-01 12:02:01 -05:00
Mike Ash
2b964b9086 [Test] Disable witness-layout-opts-irgen.swift on iOS simulators, not XFAIL, since it will probably pass on 64-bit simulators. 2021-02-01 11:36:08 -05:00
Mike Ash
60168363af [Test] XFAIL witness-layout-opts-irgen.swift on iOS simulators. 2021-02-01 11:30:31 -05:00
swift-ci
377520a031 Merge remote-tracking branch 'origin/main' into rebranch 2021-01-31 18:52:19 -08:00
Zoe Carver
23d6312034 Merge pull request #35548 from zoecarver/cxx/fix-static-function-templates
[cxx-interop] Correctly import static function templates.
2021-01-31 18:33:42 -08:00
zoecarver
ec2e130b0f [nfc] Add tests for witness table size optimizations. 2021-01-31 15:56:55 -08:00
zoecarver
02b5118199 [cxx-interop] Correctly import static function templates.
Handle static members the same way we handle other member function
templates. Also, set the "static"ness of the new (specialized) function decl.
2021-01-31 15:49:33 -08:00
swift-ci
7b283ebb33 Merge remote-tracking branch 'origin/main' into rebranch 2021-01-31 15:32:19 -08:00
Zoe Carver
06cd5bcaa0 Merge pull request #35547 from zoecarver/cxx/enable-member-templates-silgen-test
[nfc] Enable member function templates silgen test.
2021-01-31 15:28:39 -08:00
zoecarver
13ff0d63bb [nfc] Enable member function templates silgen test.
This test was dissabled until #30630 (support calling C++ constructors)
landed. That patch landed a while ago, so this test should be enabled.
2021-01-31 12:51:42 -08:00
zoecarver
de0871a654 [nfc] Fix member-templates-silgen.swift after c4da497.
c4da497 (#35416) changed the names of several member templates, this
commit fixes the disabled test to use those new names.
2021-01-31 12:51:41 -08:00