Skip to content

[cxx-interop] Import NonCopyable* as OpaquePointer if noncopyable generics are disabled #73055

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 2 commits into from
Apr 23, 2024

Conversation

egorzhdan
Copy link
Contributor

C++ pointer type T* is generally imported as Unsafe(Mutable)Pointer<T>. However, if T is non-copyable in Swift (e.g. it has a deleted C++ copy constructor), using UnsafePointer<T> type requires noncopyable generics to be enabled.

This was causing assertion failures when building SwiftCompilerSources in #72912.

@egorzhdan egorzhdan added the c++ interop Feature: Interoperability with C++ label Apr 16, 2024
@egorzhdan egorzhdan requested review from zoecarver and hyp as code owners April 16, 2024 15:52
@egorzhdan
Copy link
Contributor Author

@swift-ci please test

// If non-copyable generics are disabled, we cannot specify
// UnsafePointer<T> with a non-copyable type T.
if (pointeeType && pointeeType->isNoncopyable() &&
!Impl.SwiftContext.LangOpts.hasFeature(Feature::NoncopyableGenerics))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lorentey do you know if this is the right way to check whether we can use UnsafePointer<NonCopyable>?

@egorzhdan egorzhdan force-pushed the egorzhdan/ncg-unsafepointer branch from a18ed20 to ec5162a Compare April 16, 2024 17:29
@egorzhdan egorzhdan changed the title [cxx-interop] Import NonCopyable* as UnsafeRawPointer if noncopyable generics are disabled [cxx-interop] Import NonCopyable* as OpaquePointer if noncopyable generics are disabled Apr 16, 2024
@egorzhdan
Copy link
Contributor Author

@swift-ci please test

1 similar comment
@egorzhdan
Copy link
Contributor Author

@swift-ci please test

@egorzhdan egorzhdan requested a review from ahatanaka April 17, 2024 15:58
@egorzhdan egorzhdan force-pushed the egorzhdan/ncg-unsafepointer branch from 9c21f9b to b0d845b Compare April 17, 2024 17:45
@egorzhdan
Copy link
Contributor Author

@swift-ci please test

@egorzhdan
Copy link
Contributor Author

@swift-ci please test Windows

@egorzhdan egorzhdan force-pushed the egorzhdan/ncg-unsafepointer branch from b0d845b to fa25a5e Compare April 18, 2024 12:44
@egorzhdan
Copy link
Contributor Author

@swift-ci please test

@egorzhdan
Copy link
Contributor Author

@swift-ci please test Windows

@egorzhdan egorzhdan force-pushed the egorzhdan/ncg-unsafepointer branch from 8493c7d to d3ef25d Compare April 23, 2024 14:57
@egorzhdan
Copy link
Contributor Author

@swift-ci please test

… generics are disabled

C++ pointer type `T*` is generally imported as `Unsafe(Mutable)Pointer<T>`. However, if `T` is non-copyable in Swift (e.g. it has a deleted C++ copy constructor), using `UnsafePointer<T>` type requires noncopyable generics to be enabled.

This was causing assertion failures when building SwiftCompilerSources in #72912.
@egorzhdan egorzhdan force-pushed the egorzhdan/ncg-unsafepointer branch from d3ef25d to 6140ba1 Compare April 23, 2024 17:48
@egorzhdan
Copy link
Contributor Author

@swift-ci please test

@egorzhdan egorzhdan enabled auto-merge April 23, 2024 22:10
@egorzhdan egorzhdan merged commit 70c3e43 into main Apr 23, 2024
@egorzhdan egorzhdan deleted the egorzhdan/ncg-unsafepointer branch April 23, 2024 23:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ interop Feature: Interoperability with C++
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant