-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[cxx-interop] enable support for move-only types #69790
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
e738bdf
[cxx-interop] Import move only types even when `-enable-experimental-…
zoecarver 4ba62e1
[cxx-interop] Add tests for `std::unique_ptr`.
zoecarver 70a353b
[tests][cxx-interop] Fix straggling test.
zoecarver c79eace
no merge: add some debugging for linux.
zoecarver a78a7ec
[cxx-interop] Cleanup: remove debug printing, enable more tests.
zoecarver 5d8db5c
[cxx-interop] add a testcase for setting the pointee on unique_ptr
hyp 3cdb4b1
[cxx-interop] add some initial move only tests
hyp 86e5556
[cxx-interop] add support for 'address' pointee for non-copyable C++ …
hyp 5d2637a
[cxx-interop] add support for 'mutableAddress' pointee for non-copyab…
hyp a913c4e
[cxx-interop] fix support for value-only non-copyable type dereference
hyp fd6a5a2
[cxx-interop] test accessing fields of a move-only C++ type
hyp 51d0e84
[cxx-interop] add a test to cover accessing non-copyable field
hyp bacc58e
[cxx-interop] provide correct referential access to non-copyable base…
hyp 6a47011
[cxx-interop] add IRGen test for field base accessors for non-copyabl…
hyp 16a8ae4
[cxx-interop] fix the use of '.pointee' with address accessors for de…
hyp 0296448
[cxx-interop] fix the use of '.pointee' with getter accessor for deri…
hyp b7158ea
[cxx-interop] add SWIFT_NONCOPYABLE annotation
hyp 580ecd0
[cxx-interop] fix Egor's review comments for move-only patch
hyp 99e6d33
[cxx-interop] attempt to fix windows unique ptr test
hyp c029ed6
[cxx-interop] try to workaround the linux libstdc++ move-only failure
hyp 633e7f1
fix test
hyp 3a340c7
[cxx-interop] move-only: do not test consume with unsafeAddress acces…
hyp ec931c8
[cxx-interop] non-copyable test windows workaround and no SIL verify …
hyp 623d3d2
[cxx-interop] review fixes for non-copyable patch, ensure we only ena…
hyp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module MoveOnlyCxxValueType { | ||
header "move-only-cxx-value-type.h" | ||
requires cplusplus | ||
} |
56 changes: 56 additions & 0 deletions
56
test/Interop/Cxx/class/move-only/Inputs/move-only-cxx-value-type.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#ifndef TEST_INTEROP_CXX_CLASS_MOVE_ONLY_VT_H | ||
#define TEST_INTEROP_CXX_CLASS_MOVE_ONLY_VT_H | ||
|
||
#include <memory> | ||
|
||
struct Copyable { | ||
int x; | ||
}; | ||
|
||
struct NonCopyable { | ||
inline NonCopyable(int x) : x(x) {} | ||
inline NonCopyable(const NonCopyable &) = delete; | ||
inline NonCopyable(NonCopyable &&other) : x(other.x) { other.x = -123; } | ||
|
||
inline int method(int y) const { return x * y; } | ||
inline int mutMethod(int y) { | ||
x = y; | ||
return y; | ||
} | ||
|
||
int x; | ||
}; | ||
|
||
struct NonCopyableDerived: public NonCopyable { | ||
NonCopyableDerived(int x) : NonCopyable(x) {} | ||
}; | ||
|
||
struct NonCopyableDerivedDerived: public NonCopyableDerived { | ||
NonCopyableDerivedDerived(int x) : NonCopyableDerived(x) {} | ||
}; | ||
|
||
struct NonCopyableHolder { | ||
inline NonCopyableHolder(int x) : x(x) {} | ||
inline NonCopyableHolder(const NonCopyableHolder &) = delete; | ||
inline NonCopyableHolder(NonCopyableHolder &&other) : x(std::move(other.x)) {} | ||
|
||
inline NonCopyable &returnMutNonCopyableRef() { return x; } | ||
|
||
inline const NonCopyable &returnNonCopyableRef() const { return x; } | ||
|
||
NonCopyable x; | ||
}; | ||
|
||
struct NonCopyableHolderDerived: NonCopyableHolder { | ||
inline NonCopyableHolderDerived(int x) : NonCopyableHolder(x) {} | ||
}; | ||
|
||
struct NonCopyableHolderDerivedDerived: NonCopyableHolderDerived { | ||
inline NonCopyableHolderDerivedDerived(int x) : NonCopyableHolderDerived(x) {} | ||
|
||
inline int getActualX() const { | ||
return x.x; | ||
} | ||
}; | ||
|
||
#endif // TEST_INTEROP_CXX_CLASS_MOVE_ONLY_VT_H |
29 changes: 29 additions & 0 deletions
29
test/Interop/Cxx/class/move-only/inherited-field-access-irgen.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// RUN: %target-swift-emit-irgen -I %S/Inputs -cxx-interoperability-mode=upcoming-swift %s -validate-tbd-against-ir=none -Xcc -fignore-exceptions | %FileCheck %s | ||
|
||
import MoveOnlyCxxValueType | ||
|
||
func testGetX() -> CInt { | ||
let derived = NonCopyableHolderDerivedDerived(42) | ||
return derived.x.x | ||
} | ||
|
||
let _ = testGetX() | ||
|
||
func testSetX(_ x: CInt) { | ||
var derived = NonCopyableHolderDerivedDerived(42) | ||
derived.x.x = 2 | ||
} | ||
|
||
testSetX(2) | ||
|
||
// CHECK: define {{.*}}linkonce_odr{{.*}} ptr @{{.*}}__synthesizedBaseCall___synthesizedBaseGetterAccessor{{.*}} | ||
|
||
// CHECK: define {{.*}}linkonce_odr{{.*}} ptr @{{.*}}__synthesizedBaseCall___synthesizedBaseSetterAccessor{{.*}} | ||
|
||
// CHECK: define {{.*}}linkonce_odr{{.*}} ptr @{{.*}}__synthesizedBaseGetterAccessor{{.*}} | ||
// CHECK: %[[VPTR:.*]] = getelementptr inbounds %struct.NonCopyableHolder | ||
// CHECK: ret ptr %[[VPTR]] | ||
|
||
// CHECK: define {{.*}}linkonce_odr{{.*}} ptr @{{.*}}__synthesizedBaseSetterAccessor{{.*}} | ||
// CHECK: %[[VPTRS:.*]] = getelementptr inbounds %struct.NonCopyableHolder | ||
// CHECK: ret ptr %[[VPTRS]] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.