Skip to content
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

Fix NSLock/Thread subclassing issues #5122

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jmschonfeld
Copy link
Contributor

Currently, NSLock/Thread cannot be subclassed due to the following (or related) issues:

error: cannot inherit from class 'NSLock' (compiled with Swift 6.1) because it has overridable members that could not be loaded in Swift 5.10
Could not deserialize type for 'mutex'
Caused by: module 'CoreFoundation' was not loaded

This is because NSLock/Thread have members whose types come from pthread.h. CoreFoundation currently imports pthread.h in its public headers, and this led the compiler to believe that pthread.h came from the CoreFoundation module and not the SwiftGlibc clang module. This results in a failure because due to the @_implementationOnly import, CoreFoundation is not loaded by clients.

To resolve this, we need to ensure the compiler realizes that pthread.h and the types within come from the SwiftGlibc clang module rather than CoreFoundation. To do this, we import the SwiftGlibc.h header file (from the SwiftGlibc clang module) before importing pthread.h. However, SwiftGlibc.h is not in the default header search paths so we need CMake to lookup the path for SwiftGlibc.h (by asking the compiler) and add the search path when building CoreFoundation. We don't need to do this for the SwiftPM build since it seems that the modules are resolved differently and we do not have this issue (which is also why we can't add a unit test for this).

Resolves #5108, rdar://137716518

@jmschonfeld
Copy link
Contributor Author

@swift-ci test

@jmschonfeld
Copy link
Contributor Author

Using a toolchain built with this change, it seems that this resolves the issue for NSLock and its subclasses, but it did not resolve the issue for Thread:

error: cannot inherit from class 'Thread' (compiled with Swift 6.1) because it has overridable members that could not be loaded in Swift 5.10

Could not deserialize type for '_attr'
Caused by: module 'CoreFoundation' was not loaded

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants