Fix NSLock
/Thread
subclassing issues
#5122
Open
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.
Currently,
NSLock
/Thread
cannot be subclassed due to the following (or related) issues:This is because
NSLock
/Thread
have members whose types come frompthread.h
.CoreFoundation
currently importspthread.h
in its public headers, and this led the compiler to believe thatpthread.h
came from theCoreFoundation
module and not theSwiftGlibc
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 theSwiftGlibc
clang module rather thanCoreFoundation
. To do this, we import theSwiftGlibc.h
header file (from theSwiftGlibc
clang module) before importingpthread.h
. However,SwiftGlibc.h
is not in the default header search paths so we need CMake to lookup the path forSwiftGlibc.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