Commit Graph

617 Commits

Author SHA1 Message Date
Zoe Carver
b6574b5745 Merge pull request #60215 from zoecarver/diags-record-in-namesapce
[cxx-interop][diags] Fix diagnostics for records inside namespaces.
2022-07-25 08:14:37 -07:00
swift-ci
8029bda985 Merge remote-tracking branch 'origin/main' into rebranch 2022-07-25 06:14:18 -07:00
Egor Zhdan
6fa2daf496 [cxx-interop] Do not crash when importing anonymous classes
This was discovered during interop adoption in SwiftCompilerSources.
```
/Volumes/Projects/swift/swift/include/swift/SIL/SILNode.h:180:5 <Spelling=/Volumes/Projects/swift/swift/include/swift/SIL/SILNode.h:171:3>: while adding SwiftName lookup table entries for clang declaration 'swift::SILNode::SharedUInt8Fields::(anonymous)'
```
2022-07-25 11:43:31 +01:00
zoecarver
d59d32f712 [cxx-interop][diags] Fix diagnostics for records inside namespaces. 2022-07-24 18:21:08 -07:00
swift-ci
9de631f94f Merge remote-tracking branch 'origin/main' into rebranch 2022-07-19 17:35:57 -07:00
zoecarver
79c68f8d53 [cxx-interop] Don't add incomplete records to lookup table. 2022-07-19 09:24:15 -04:00
zoecarver
3498ff9765 [cxx-interop] Remove UnsafeLifetimeOperation record semantic kind.
This makes "owned" the default kind for records that have custom copy constructors and no pointer-members.
2022-07-18 17:15:15 -04:00
zoecarver
9d1d03124b [nfc][cxx-interop] Add diagnostics when something cannot be imported. 2022-07-18 17:15:15 -04:00
zoecarver
6acffbbee6 [cxx-interop] Flip the switch: only import safe APIs. 2022-07-18 17:15:15 -04:00
swift-ci
5c84024363 Merge remote-tracking branch 'origin/main' into rebranch 2022-07-15 13:15:04 -07:00
Egor Zhdan
44c35a2971 [cxx-interop] Fix lookup of member operators
Calling `StructDecl::lookupDirect` with an operator identifier (e.g. `==`) previously returned no results. This happened because the underlying C++ operator function was added to the lookup table with an underscored name (e.g. `__operatorEqualEqual`), and the synthesized function was not added to the lookup table at all. Lookup should find the synthesized decl, since that is what Swift code will call.

This fixes a typechecker error when trying to conform a C++ struct that defines an operator to a Swift protocol with an operator requirement (e.g. `Equatable`).
2022-07-15 16:53:39 +01:00
swift-ci
d4005d615f Merge remote-tracking branch 'origin/main' into rebranch 2022-07-06 09:55:20 -07:00
Zoe Carver
524637288e Merge pull request #59754 from zoecarver/fix-static-down-cast-shim 2022-07-06 09:36:22 -07:00
swift-ci
8b7ba703eb Merge remote-tracking branch 'origin/main' into rebranch 2022-07-05 20:14:02 -07:00
zoecarver
8cf4d3b983 [cxx-interop] Disable cxxshim on windows until we can figure out cmakeconfig. 2022-07-05 20:03:45 -07:00
zoecarver
3805828ad0 [cxx-interop] Add CxxShim library; move __swift_interopStaticCast into it. 2022-07-05 15:52:51 -07:00
zoecarver
a353d6f272 [cxx-interop] Fix lazy member lookup for forward-declared structs inside of a namespace. 2022-07-05 11:54:02 -07:00
swift-ci
5c8f1fcb12 Merge remote-tracking branch 'origin/main' into rebranch 2022-07-02 17:03:37 -07:00
Egor Zhdan
0e31acb18c [IRGen] Emit missing sret for function arguments
If the IR representation of a C++ function takes an `SRet` parameter instead of a return value, Swift needs to wrap the corresponding argument with `sret(...)` on call site.

This fixes SILOptimizer crashes on arm64.

rdar://92963081
2022-07-01 17:49:33 +01:00
swift-ci
2828990bfd Merge remote-tracking branch 'origin/main' into rebranch 2022-06-27 12:53:23 -07:00
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