Skip to content

[6.0] Adopt Swift 6 and audit for Sendable #5026

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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ list(APPEND _Foundation_common_build_flags
"-Wno-unused-function"
"-Wno-microsoft-enum-forward-reference"
"-Wno-int-conversion"
"-Wno-switch"
"-fblocks")

if(NOT "${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC")
Expand Down Expand Up @@ -139,8 +140,11 @@ endif()
# Swift build flags (Foundation, FoundationNetworking, FoundationXML)
set(_Foundation_swift_build_flags)
list(APPEND _Foundation_swift_build_flags
"-swift-version 6"
"-DDEPLOYMENT_RUNTIME_SWIFT"
"-DSWIFT_CORELIBS_FOUNDATION_HAS_THREADS")
"-DSWIFT_CORELIBS_FOUNDATION_HAS_THREADS"
"-Xfrontend"
"-require-explicit-sendable")

if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Android")
list(APPEND _Foundation_common_build_flags
Expand Down
44 changes: 39 additions & 5 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version: 5.9
// swift-tools-version: 6.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
Expand All @@ -21,6 +21,7 @@ let coreFoundationBuildSettings: [CSetting] = [
"-Wno-unused-function",
"-Wno-microsoft-enum-forward-reference",
"-Wno-int-conversion",
"-Wno-switch",
"-fconstant-cfstrings",
"-fexceptions", // TODO: not on OpenBSD
"-fdollars-in-identifiers",
Expand Down Expand Up @@ -66,6 +67,11 @@ let interfaceBuildSettings: [CSetting] = [
let swiftBuildSettings: [SwiftSetting] = [
.define("DEPLOYMENT_RUNTIME_SWIFT"),
.define("SWIFT_CORELIBS_FOUNDATION_HAS_THREADS"),
.swiftLanguageVersion(.v6),
.unsafeFlags([
"-Xfrontend",
"-require-explicit-sendable",
])
]

var dependencies: [Package.Dependency] {
Expand All @@ -85,7 +91,7 @@ var dependencies: [Package.Dependency] {
from: "0.0.9"),
.package(
url: "https://github.com/apple/swift-foundation",
revision: "35d896ab47ab5e487cfce822fbe40d2b278c51d6")
revision: "d59046871c6b69a13595f18d334afa1553e0ba50")
]
}
}
Expand All @@ -110,6 +116,9 @@ let package = Package(
"CoreFoundation"
],
path: "Sources/Foundation",
exclude: [
"CMakeLists.txt"
],
swiftSettings: swiftBuildSettings
),
.target(
Expand All @@ -121,6 +130,9 @@ let package = Package(
"_CFXMLInterface"
],
path: "Sources/FoundationXML",
exclude: [
"CMakeLists.txt"
],
swiftSettings: swiftBuildSettings
),
.target(
Expand All @@ -132,15 +144,21 @@ let package = Package(
"_CFURLSessionInterface"
],
path: "Sources/FoundationNetworking",
swiftSettings:swiftBuildSettings
exclude: [
"CMakeLists.txt"
],
swiftSettings: swiftBuildSettings
),
.target(
name: "CoreFoundation",
dependencies: [
.product(name: "_FoundationICU", package: "swift-foundation-icu"),
],
path: "Sources/CoreFoundation",
exclude: ["BlockRuntime"],
exclude: [
"BlockRuntime",
"CMakeLists.txt"
],
cSettings: coreFoundationBuildSettings
),
.target(
Expand All @@ -150,6 +168,9 @@ let package = Package(
"Clibxml2",
],
path: "Sources/_CFXMLInterface",
exclude: [
"CMakeLists.txt"
],
cSettings: interfaceBuildSettings
),
.target(
Expand All @@ -159,6 +180,9 @@ let package = Package(
"Clibcurl",
],
path: "Sources/_CFURLSessionInterface",
exclude: [
"CMakeLists.txt"
],
cSettings: interfaceBuildSettings
),
.systemLibrary(
Expand All @@ -181,6 +205,12 @@ let package = Package(
name: "plutil",
dependencies: [
"Foundation"
],
exclude: [
"CMakeLists.txt"
],
swiftSettings: [
.swiftLanguageVersion(.v6)
]
),
.executableTarget(
Expand All @@ -189,6 +219,9 @@ let package = Package(
"Foundation",
"FoundationXML",
"FoundationNetworking"
],
swiftSettings: [
.swiftLanguageVersion(.v6)
]
),
.target(
Expand All @@ -215,7 +248,8 @@ let package = Package(
.copy("Foundation/Resources")
],
swiftSettings: [
.define("NS_FOUNDATION_ALLOWS_TESTABLE_IMPORT")
.define("NS_FOUNDATION_ALLOWS_TESTABLE_IMPORT"),
.swiftLanguageVersion(.v6)
]
),
]
Expand Down
4 changes: 2 additions & 2 deletions Sources/CoreFoundation/CFBundle_Resources.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,9 @@ CF_PRIVATE _CFBundleVersion _CFBundleGetBundleVersionForURL(CFURLRef url) {
foundSupportFiles2 = true;
} else if (fileNameLen == supportFilesDirectoryLength && CFStringCompareWithOptions(fileName, _CFBundleSupportFilesDirectoryName1, CFRangeMake(0, supportFilesDirectoryLength), kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
foundSupportFiles1 = true;
} else if (fileNameLen == wrapperDirLength && CFStringCompareWithOptions(fileName, _CFBundleWrapperDirectoryName, CFRangeMake(0, wrapperDirLength), kCFCompareEqualTo) == kCFCompareEqualTo) {
} else if (fileNameLen == wrapperDirLength && CFStringCompareWithOptions(fileName, _CFBundleWrapperDirectoryName, CFRangeMake(0, wrapperDirLength), 0) == kCFCompareEqualTo) {
foundAppWrapperDirectory = true;
} else if (fileType == DT_LNK && fileNameLen == wrapperLinkLength && CFStringCompareWithOptions(fileName, _CFBundleWrapperLinkName, CFRangeMake(0, wrapperLinkLength), kCFCompareEqualTo) == kCFCompareEqualTo) {
} else if (fileType == DT_LNK && fileNameLen == wrapperLinkLength && CFStringCompareWithOptions(fileName, _CFBundleWrapperLinkName, CFRangeMake(0, wrapperLinkLength), 0) == kCFCompareEqualTo) {
foundAppWrapperLink = true;
}
} else if (fileType == DT_UNKNOWN) {
Expand Down
3 changes: 3 additions & 0 deletions Sources/CoreFoundation/CFDate.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,11 @@ double __CFTSRRate = 0.0;
static double __CF1_TSRRate = 0.0;

CF_PRIVATE uint64_t __CFTimeIntervalToTSR(CFTimeInterval ti) {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wimplicit-const-int-float-conversion"
if ((ti * __CFTSRRate) > INT64_MAX / 2) return (INT64_MAX / 2);
return (uint64_t)(ti * __CFTSRRate);
#pragma GCC diagnostic pop
}

CF_PRIVATE CFTimeInterval __CFTSRToTimeInterval(uint64_t tsr) {
Expand Down
3 changes: 3 additions & 0 deletions Sources/CoreFoundation/CFNumber.c
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,8 @@ static Boolean __CFNumberGetValue(CFNumberRef number, CFNumberType type, void *v
}
}
return true;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wimplicit-const-int-float-conversion"
case kCFNumberSInt32Type:
if (floatBit) {
if (!storageBit) {
Expand Down Expand Up @@ -564,6 +566,7 @@ static Boolean __CFNumberGetValue(CFNumberRef number, CFNumberType type, void *v
}
}
return true;
#pragma GCC diagnostic pop
case kCFNumberSInt128Type:
if (floatBit) {
if (!storageBit) {
Expand Down
1 change: 1 addition & 0 deletions Sources/CoreFoundation/CFPlatform.c
Original file line number Diff line number Diff line change
Expand Up @@ -1814,6 +1814,7 @@ CF_CROSS_PLATFORM_EXPORT int _CFThreadSetName(_CFThreadRef thread, const char *_
#endif
}

// `buf` must be null-terminated
CF_CROSS_PLATFORM_EXPORT int _CFThreadGetName(char *buf, int length) {
#if SWIFT_CORELIBS_FOUNDATION_HAS_THREADS
#if TARGET_OS_MAC
Expand Down
6 changes: 6 additions & 0 deletions Sources/CoreFoundation/CFPreferences.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,14 +234,20 @@ CFDictionaryRef CFPreferencesCopyMultiple(CFArrayRef keysToFetch, CFStringRef ap
__CFGenericValidateType(host, CFStringGetTypeID());

domain = _CFPreferencesStandardDomain(appName, user, host);
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wnonnull"
if (!domain) return NULL;
#pragma GCC diagnostic pop
if (!keysToFetch) {
return _CFPreferencesDomainDeepCopyDictionary(domain);
} else {
__CFGenericValidateType(keysToFetch, CFArrayGetTypeID());
count = CFArrayGetCount(keysToFetch);
result = CFDictionaryCreateMutable(CFGetAllocator(domain), count, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wnonnull"
if (!result) return NULL;
#pragma GCC diagnostic pop
for (idx = 0; idx < count; idx ++) {
CFStringRef key = (CFStringRef)CFArrayGetValueAtIndex(keysToFetch, idx);
CFPropertyListRef value;
Expand Down
4 changes: 3 additions & 1 deletion Sources/CoreFoundation/CFPropertyList.c
Original file line number Diff line number Diff line change
Expand Up @@ -1587,6 +1587,8 @@ static Boolean parseDictTag(_CFXMLPlistParseInfo * _Nonnull pInfo, CFTypeRef * _

static Boolean parseDataTag(_CFXMLPlistParseInfo *pInfo, CFTypeRef *out) {
const char *base = pInfo->curr;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wgnu-folding-constant"
static const unsigned char dataDecodeTableSize = 128;
static const signed char dataDecodeTable[dataDecodeTableSize] = {
/* 000 */ -1, -1, -1, -1, -1, -1, -1, -1,
Expand All @@ -1606,7 +1608,7 @@ static Boolean parseDataTag(_CFXMLPlistParseInfo *pInfo, CFTypeRef *out) {
/* 'p' */ 41, 42, 43, 44, 45, 46, 47, 48,
/* 'x' */ 49, 50, 51, -1, -1, -1, -1, -1
};
#pragma GCC diagnostic pop
int tmpbufpos = 0;
int tmpbuflen = 256;
uint8_t *tmpbuf = pInfo->skip ? NULL : (uint8_t *)CFAllocatorAllocate(pInfo->allocator, tmpbuflen, 0);
Expand Down
2 changes: 1 addition & 1 deletion Sources/CoreFoundation/CFRelativeDateTimeFormatter.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct __CFRelativeDateTimeFormatter {
CFRelativeDateTimeFormattingContext _formattingContext;
};

static UDateRelativeDateTimeFormatterStyle icuRelativeDateTimeStyleFromUnitsStyle(CFRelativeDateTimeFormatterStyle style) {
static UDateRelativeDateTimeFormatterStyle icuRelativeDateTimeStyleFromUnitsStyle(CFRelativeDateTimeFormatterUnitsStyle style) {
switch (style) {
case CFRelativeDateTimeFormatterUnitsStyleSpellOut:
case CFRelativeDateTimeFormatterUnitsStyleFull:
Expand Down
4 changes: 4 additions & 0 deletions Sources/CoreFoundation/CFRuntime.c
Original file line number Diff line number Diff line change
Expand Up @@ -1774,11 +1774,15 @@ struct _NSCFXMLBridgeUntyped __NSCFXMLBridgeUntyped = {
CFDataGetBytePtr,
CFDictionaryCreateMutable,
CFDictionarySetValue,
// We cannot use the real types here because eventually it winds up exposed as API using CF types in Swift, which we do not want
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wincompatible-pointer-types-discards-qualifiers"
&kCFAllocatorSystemDefault,
&kCFAllocatorNull,
&kCFCopyStringDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks,
&kCFErrorLocalizedDescriptionKey,
#pragma GCC diagnostic pop
};

// Call out to the CF-level finalizer, because the object is going to go away.
Expand Down
11 changes: 7 additions & 4 deletions Sources/CoreFoundation/include/ForSwiftFoundationOnly.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#define NOMINMAX
#define VC_EXTRALEAN
#define WIN32_LEAN_AND_MEAN
#define _CRT_NONSTDC_NO_DEPRECATE
#include <Windows.h>
#elif !TARGET_OS_WASI
#include <fts.h>
Expand All @@ -59,6 +60,8 @@

#if TARGET_OS_LINUX
#include <sys/sysmacros.h>
#include <fcntl.h>
#include <sys/stat.h>
#endif

#if TARGET_OS_ANDROID
Expand Down Expand Up @@ -335,10 +338,10 @@ struct _NSCFXMLBridgeUntyped {
void *kCFErrorLocalizedDescriptionKey;
};

CF_EXPORT struct _NSCFXMLBridgeStrong __NSCFXMLBridgeStrong;
CF_EXPORT struct _NSCFXMLBridgeUntyped __NSCFXMLBridgeUntyped;
CF_EXPORT struct _NSCFXMLBridgeStrong __NSCFXMLBridgeStrong __attribute__((swift_attr("nonisolated(unsafe)")));
CF_EXPORT struct _NSCFXMLBridgeUntyped __NSCFXMLBridgeUntyped __attribute__((swift_attr("nonisolated(unsafe)")));

CF_EXPORT struct _CFSwiftBridge __CFSwiftBridge;
CF_EXPORT struct _CFSwiftBridge __CFSwiftBridge __attribute__((swift_attr("nonisolated(unsafe)")));

CF_EXPORT void *_Nullable _CFSwiftRetain(void *_Nullable t);
CF_EXPORT void _CFSwiftRelease(void *_Nullable t);
Expand Down Expand Up @@ -407,7 +410,7 @@ typedef void *_CFThreadSpecificKey;
#endif

CF_CROSS_PLATFORM_EXPORT Boolean _CFIsMainThread(void);
CF_EXPORT _CFThreadRef _CFMainPThread;
CF_EXPORT _CFThreadRef _CFMainPThread __attribute__((swift_attr("nonisolated(unsafe)")));

CF_EXPORT CFHashCode __CFHashDouble(double d);

Expand Down
Loading