Commit Graph

597 Commits

Author SHA1 Message Date
Egor Zhdan
d04675aa46 Merge pull request #59613 from apple/egorzhdan/cxx-typecheck-iuo
[cxx-interop] Allow conforming C++ APIs that return IUO to Swift protocols
2022-06-27 20:34:31 +01:00
swift-ci
bf2d16f992 Merge remote-tracking branch 'origin/main' into rebranch 2022-06-27 10:33:36 -07:00
Saleem Abdulrasool
fc070c6167 platform: restructure visualc module
Restructure the `visualc` module into `vcruntime` in order to help
expose the various components (SAL, vcruntime, ucrt, corecrt, STL) for C++
modularization.  Include the `stdint.h` textually to deal with
redefinition of types in clang resources and MSVC.
2022-06-26 14:06:59 -07:00
Egor Zhdan
546accbcf9 [cxx-interop] Allow conforming C++ APIs that return IUO to Swift protocols
If a C++ method returns a pointer and is not annotated with `returns_nonnull`, ClangImporter imports its return type as implicitly unwrapped optional `UnsafePointer<T>!`. This happens, for example, for `begin()`/`end()` methods of C++ collection types.

We would like to be able to conform C++ collections to `Swift.Sequence`/`Swift.Collection`/... To make this work, we create Swift protocols that require `func begin() -> RawIterator` and `func end() -> RawIterator` where `RawIterator` is an associated type.

The problem is that currently if `RawIterator` is `UnsafePointer<T>?`, `begin()`/`end()` methods that return an implicitly unwrapped optional `UnsafePointer<T>!` won't satisfy the requirements. This change fixes that.
2022-06-21 19:41:15 +01:00
swift-ci
e46b2c3efe Merge remote-tracking branch 'origin/main' into rebranch 2022-06-01 08:13:51 -07:00
Sam Kortekaas
e73bb6fd9d [cxx-interop] Import attributes on inherited C++ methods 2022-05-23 13:21:06 +02:00
Ben Barham
e382e15f6a [next] Generalise interop tests that only care about name and types
Due to a now default-enabled `undef` pass (llvm/llvm-project
1b1c8d83d3567a60280291c0adb95d1d60335509), a whole bunch of interop
IRGen tests are failing due to missing `undefs`, even though they don't
matter in these tests at all. Add regex matches so that these tests just
check for the name and types of the functions they care about.
2022-05-13 14:39:26 -07:00
Egor Zhdan
7db3666e43 [cxx-interop] Fix test/Interop/Cxx/stdlib/use-std-string.swift
Temporarily disable the checks for mutable fields in a C++ struct. A better solution would be to use some heuristic to detect if a method mutates a mutable field, and allow the user to adjust mutability with the existing `nonmutating` annotation.

rdar://92621793
2022-05-03 16:36:40 +01:00
Sam Kortekaas
cd4856544b [cxx-interop][nfc] Fix failing test on Windows 2022-04-28 17:11:54 +02:00
Sam Kortekaas
91bc7534ea [cxx-interop] Add diagnostics for nonmutating attr that has no effect 2022-04-28 15:42:56 +02:00
Sam Kortekaas
23b2fa9753 [cxx-interop] Add diagnostic for contradicting mutability annotations 2022-04-28 15:42:56 +02:00
Sam Kortekaas
60fe6aae95 [cxx-interop] Add a "nonmutating" swift_attr attribute
Previously, the clang importer marked all const methods as mutating whenever a C++ record had mutable fields. This change allows overriding this behavior by using the "nonmutating" swift_attr attribute.

Fixes SR-15907.
2022-04-28 15:42:56 +02:00
Egor Zhdan
2285c518f7 Merge pull request #58428 from apple/egorzhdan/cxx-sil-deserialization
[cxx-interop] Fix SIL deserialization error
2022-04-27 20:31:20 +02:00
Egor Zhdan
2472dfc32e [cxx-interop] Fix SIL deserialization error
Make sure nested namespaces are added to the SwiftLookupTable when they are declared in a non-canonical redecl of the parent namespace.

This was blocking C++ interop adoption in SwiftCompilerSources.
2022-04-27 01:10:46 +01:00
Josh Soref
e75e5b5a03 Spelling interop (#42549)
* spelling: different

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: disappear

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: executable

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: instantiate

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: instantiation

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: member

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: parameter

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: section

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: trivia

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: unrelated

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

Co-authored-by: Josh Soref <jsoref@users.noreply.github.com>
2022-04-22 14:13:23 -07:00
Allan Shortlidge
9053f0e249 cxx-interop: Fix CHECK-LABEL spelling 2022-04-20 16:37:18 -07:00
Egor Zhdan
fca494e66d [cxx-interop] Ignore mutable fields when detecting method mutability
rdar://91961524
2022-04-19 18:23:32 +01:00
zoecarver
d2e3e0d4e1 [cxx-interop] Work with definition in VisitCXXRecordDecl.
This was previously un-noticed because VisitRecordDecl already handles this, but there are a couple checks that are specific to C++ records.
2022-04-18 11:57:48 -07:00
zoecarver
839839f924 [cxx-interop] Rename enable-cxx-interop -> enable-experimental-cxx-interop.
Also removes the driver flag, this will now also always be guarded on `-Xfrontend`.
2022-04-07 19:15:25 -07:00
zoecarver
5db8647911 [cxx-interop] Make sure to use TUScope when looking up clang decls.
When we look up a name directly, make sure we provide a scope, this is required when C++ interop is enabled.

This issue was exposed when we look up if an NSString is hashable. There is a special case for classes that inherit from NSObject, but we didn't see that, because we couldn't find NSObject (because lookup failed).
2022-03-17 16:26:57 -07:00
Alex
93c4c621b7 [cxx-interop] Walk initializer decls when walking constructor decls (#41584)
This addresses SR-15272.

When you have a function (e.g. 'foo') which is used in a constructor
initializer (e.g. constructor of some class 'Bar'), and you use the
constructor from swift code without directly using the function (e.g.
Bar's ctor is used from swift but foo isn't, foo is used from Bar's ctor),
you will get a link error. My fix is as follows:

When walking the clangAST to be imported, make sure you look at each
CXXCtorInitializer for each CXXConstructorDecl you see.
2022-03-14 09:56:55 -07:00
Daniel Rodríguez Troitiño
746080d6d1 [ClangImporter] Suffix ambiguous protocol names if C++ interop is enabled
The Clang Importer when C++ interop is not enabled, disambigate an Obj-C
class and protocol that are named the same by appending `Protocol` to
the protocol. This was not happening when C++ interop was enabled, but
should also apply to Obj-C++ modules.

The fix is providing an starting scope for the search, which the C++
name lookup need to actually find the similarly named counterpart.

Includes a test to avoid this problem creeping in again, and locally it
did not break any other tests.
2022-03-11 17:18:07 -08:00
Erik Eckstein
6a020f8f15 Stabilize and simplify SIL linkage and serialization
The main point of this change is to make sure that a shared function always has a body: both, in the optimizer pipeline and in the swiftmodule file.
This is important because the compiler always needs to emit code for a shared function. Shared functions cannot be referenced from outside the module.
In several corner cases we missed to maintain this invariant which resulted in unresolved-symbol linker errors.

As side-effect of this change we can drop the shared_external SIL linkage and the IsSerializable flag, which simplifies the serialization and linkage concept.
2022-03-09 15:28:05 +01:00
zoecarver
8ac98f62a6 [cxx-interop] Add remaining lifetime operations.
We used to only emit "destroy" and "initializeWithCopy". This commit adds support for emitting "assignWithCopy", "initializeWithTake" and "assignWithTake".
2022-03-04 15:22:53 -08:00
zoecarver
fc1e4df039 [cxx-interop] Empty base classes have zero offset.
Make sure empty base classes don't affect the offset of stored properties.
2022-03-03 15:47:15 -08:00
zoecarver
cc08a3124b [cxx-interop] Make sure to use the cannonical base class type. 2022-03-03 15:34:31 -08:00
Ehud Adler
428892d451 Merge pull request #41536 from Huddie/fix-cxx-mutable-lookup-failure
[cxx interop] Fix issue where const overloaded disambiguated methods were not in the lookup table
2022-02-28 11:51:03 -05:00
Ehud Adler
4d2a40b405 Removed ping from module interface test 2022-02-24 14:32:10 -05:00
Ehud Adler
be643437c6 Removed ping due to the const method being empty and therefore being optimizd out 2022-02-24 12:05:37 -05:00
Ehud Adler
43f757faf4 Clean up & add test 2022-02-23 19:45:27 -05:00
zoecarver
d067f076b3 [nfc] Fix enum tests on Windows.
On windows enum's use a signed int.
2022-02-19 17:41:42 -08:00
zoecarver
bb00e8dcfe [cxx-interop] Rudimentary support for importing base classes.
This commit adds very basic support for importing and calling base class methods, getting and setting base class fields, and using types inside of base classes.
2022-02-18 15:59:52 -08:00
zoecarver
283fc782ec Revert "Revert "[cxx-interop] A few cleanups and fixes for function templates.""
This reverts commit 5de09631ff.
2022-02-15 13:30:10 -08:00
Zoe Carver
5de09631ff Revert "[cxx-interop] A few cleanups and fixes for function templates." 2022-02-13 09:54:39 -08:00
Zoe Carver
0e7af7a7cd Merge pull request #41217 from zoecarver/cleanup-and-fixes-for-function-templates 2022-02-12 14:10:41 -08:00
zoecarver
83e465f763 Move up the Windows hack and fix it for static members/inits. 2022-02-11 20:51:11 -08:00
Zoe Carver
5e1e0c132e Merge pull request #41308 from Huddie/cxx-mutable-const-import
[cxx Interop] Disambiguate methods within the same class with same name but differing "constness"
2022-02-10 17:21:22 -08:00
Robert Widmann
f5bc40be10 Merge pull request #35707 from buttaface/droid
[android] Switch to new single-header modulemap for Bionic too
2022-02-10 15:50:19 -08:00
Ehud Adler
f3f75ba26e Change order of const/mutable in class to enhance test 2022-02-10 13:00:08 -05:00
Ehud Adler
6f93bc8a6c Remove required failure on windows for tests 2022-02-10 12:14:50 -05:00
Ehud Adler
18c6bdd212 [Cxx iterop] Disambiguate between methods with the same name but different constness 2022-02-09 19:49:02 -05:00
Ehud Adler
f8f8e16864 Start with writing failing tests 2022-02-07 12:49:27 -05:00
zoecarver
daceecfc75 [cxx-interop] Remove generateSpecializedCXXFunctionTemplate and just import the decl directly.
1) This unifies two code paths that do essentially the same thing.
2) This fixes how we import certain types (such as return types).
2022-02-04 16:18:02 -08:00
zoecarver
ed6bb594ea [cxx-interop] Re-enable some method tests. 2022-02-04 14:31:37 -08:00
zoecarver
1429cf3d29 [nfc][cxx-interop] Add some tests for calling C++ methods.
Finally 😅
2022-02-02 11:09:36 -08:00
Robert Widmann
0b4641d1fd Fixup Tests 2022-01-07 12:26:07 -08:00
zoecarver
036361d1e4 [cxx-interop] Add SIL function representation cxx_method; Support extending C++ types.
There are three major changes here:
    1. The addition of "SILFunctionTypeRepresentation::CXXMethod".
    2. C++ methods are imported with their members *last*. Then the arguments are switched when emitting the IR for an application of the function.
    3. Clang decls are now marked as foreign witnesses.

These are all steps towards being able to have C++ protocol conformance.
2022-01-06 14:26:47 -08:00
Butta
5eb29d99dd [android] Switch to new single-header modulemap for Bionic too 2021-12-13 23:23:45 +05:30
Michael Gottesman
5d5b0daf9c [silgen] Add the lexical flag on more alloc_stack that are used to represent variables.
And update all of the tests.
2021-12-03 14:33:00 -08:00
Egor Zhdan
9010d89c5e Merge pull request #39999 from egorzhdan/cxx-mutating-attr
C++ Interop: support mutating attribute for C++ methods
2021-11-30 10:58:16 +03:00