-
Notifications
You must be signed in to change notification settings - Fork 10.6k
[cxx-interop] Add flag to assume C++ types are resilient #76907
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
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
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
87 changes: 87 additions & 0 deletions
87
test/Interop/Cxx/library-evolution/allow-cxx-api-in-evolving-libraries.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,87 @@ | ||
| // RUN: %empty-directory(%t) | ||
| // RUN: split-file %s %t | ||
| // RUN: %target-swift-frontend %t/test.swift -I %t/Inputs -typecheck -enable-library-evolution -enable-experimental-cxx-interop -disable-availability-checking -disable-implicit-cxx-module-import -enable-experimental-feature AssumeResilientCxxTypes -verify | ||
|
|
||
| //--- Inputs/module.modulemap | ||
| module CxxModule { | ||
| header "header.h" | ||
| requires cplusplus | ||
| } | ||
|
|
||
| //--- Inputs/header.h | ||
|
|
||
| class CxxStruct { | ||
| public: | ||
| int x; int y; | ||
|
|
||
| void method() const; | ||
| }; | ||
|
|
||
| enum class CxxEnum { | ||
| A, B | ||
| }; | ||
|
|
||
| template<class T> | ||
| class CxxTemplate { | ||
| T v; | ||
| }; | ||
|
|
||
| using CxxTemplateInt = CxxTemplate<int>; | ||
|
|
||
| class | ||
| __attribute__((swift_attr("import_reference"))) | ||
| __attribute__((swift_attr("retain:immortal"))) | ||
| __attribute__((swift_attr("release:immortal"))) | ||
| SingletonReference { | ||
| public: | ||
| SingletonReference(const SingletonReference &) = delete; | ||
|
|
||
| static SingletonReference * _Nonnull create(); | ||
|
|
||
| void method(); | ||
| }; | ||
|
|
||
| CxxStruct createStruct(); | ||
|
|
||
| void freeCxxFunction(); | ||
|
|
||
| using BuiltinIntTypealis = int; | ||
|
|
||
| //--- test.swift | ||
|
|
||
| import CxxModule | ||
|
|
||
| public func usesBuiltinIntTypealis() -> BuiltinIntTypealis { | ||
| return 21 | ||
| } | ||
|
|
||
| public func usesCxxSingletonReference() -> SingletonReference { | ||
| return SingletonReference.create() | ||
| } | ||
|
|
||
| public func usesCxxStruct(_ x: CxxStruct) { | ||
| } | ||
|
|
||
| public typealias EnumT = CxxEnum | ||
|
|
||
| extension CxxTemplateInt { | ||
| func testInternal() { | ||
|
|
||
| } | ||
| } | ||
|
|
||
| extension CxxTemplateInt { | ||
| public func testPublicExt() { | ||
| } | ||
| } | ||
|
|
||
| public func publicFuncInternalBody() { | ||
| let s = createStruct() | ||
| s.method() | ||
| } | ||
|
|
||
| @inlinable | ||
| public func publicFuncPublicBody() { | ||
| let value = SingletonReference.create() | ||
| value.method() | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is better not to use experimental feature since this is a flag to opt out of the error and not really a feature. Think it would better to have a flag that reads like
allow-cxx-types-in-swift-interfaceThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally, I prefer the experimental feature approach because they are easier to add and remove. If you add flags, you have to update the drivers and frontend, and possibly leave them in forever. Experimental features are more self-contained.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good to me.