Skip to content

Commit 14b1ab3

Browse files
Merge pull request #18 from SomeRandomiOSDev/strict-concurrency
Added strict concurrency checking and Sendable conformances
2 parents bb32fc7 + 40a57ef commit 14b1ab3

File tree

5 files changed

+40
-34
lines changed

5 files changed

+40
-34
lines changed

Half.podspec

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |s|
22

33
s.name = "Half"
4-
s.version = "1.4.1"
4+
s.version = "1.4.2"
55
s.summary = "Swift Half-Precision Floating Point"
66
s.description = <<-DESC
77
A lightweight framework containing a Swift implementation for a half-precision floating point type for iOS, macOS, tvOS, and watchOS.
@@ -17,8 +17,9 @@ Pod::Spec.new do |s|
1717
s.tvos.deployment_target = '12.0'
1818
s.watchos.deployment_target = '4.0'
1919

20-
s.source_files = 'Sources/**/*.{swift,h,c}'
21-
s.swift_versions = ['5.0']
22-
s.cocoapods_version = '>= 1.7.3'
20+
s.source_files = 'Sources/**/*.{swift,h,c}'
21+
s.pod_target_xcconfig = { 'SWIFT_STRICT_CONCURRENCY' => 'complete' }
22+
s.swift_versions = ['5.0']
23+
s.cocoapods_version = '>= 1.7.3'
2324

2425
end

Half.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,6 +1030,7 @@
10301030
SDKROOT = iphoneos;
10311031
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
10321032
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
1033+
SWIFT_STRICT_CONCURRENCY = complete;
10331034
SWIFT_VERSION = 5.0;
10341035
TVOS_DEPLOYMENT_TARGET = 12.0;
10351036
VERSIONING_SYSTEM = "apple-generic";
@@ -1094,6 +1095,7 @@
10941095
SDKROOT = iphoneos;
10951096
SWIFT_COMPILATION_MODE = wholemodule;
10961097
SWIFT_OPTIMIZATION_LEVEL = "-O";
1098+
SWIFT_STRICT_CONCURRENCY = complete;
10971099
SWIFT_VERSION = 5.0;
10981100
TVOS_DEPLOYMENT_TARGET = 12.0;
10991101
VALIDATE_PRODUCT = YES;

Package.swift

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.7
1+
// swift-tools-version:5.8
22
import PackageDescription
33

44
let package = Package(
@@ -17,9 +17,27 @@ let package = Package(
1717

1818
targets: [
1919
.target(name: "CHalf"),
20-
.testTarget(name: "CHalfTests", dependencies: ["CHalf", "Half"]),
20+
.testTarget(
21+
name: "CHalfTests",
22+
dependencies: ["CHalf", "Half"],
23+
swiftSettings: [
24+
.enableExperimentalFeature("StrictConcurrency")
25+
]
26+
),
2127

22-
.target(name: "Half", dependencies: ["CHalf"]),
23-
.testTarget(name: "HalfTests", dependencies: ["Half"])
28+
.target(
29+
name: "Half",
30+
dependencies: ["CHalf"],
31+
swiftSettings: [
32+
.enableExperimentalFeature("StrictConcurrency")
33+
]
34+
),
35+
.testTarget(
36+
name: "HalfTests",
37+
dependencies: ["Half"],
38+
swiftSettings: [
39+
.enableExperimentalFeature("StrictConcurrency")
40+
]
41+
)
2442
]
2543
)

Sources/CHalf/include/half.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,19 @@
2828
#define HALF_FUNC HALF_CONST
2929
#define HALF_OFUNC HALF_FUNC __attribute__((__overloadable__))
3030

31+
// Copied from <Foundation/NSObjCRuntime.h> since that header cannot be imported
32+
#if !defined(NS_SWIFT_SENDABLE)
33+
# if defined(__SWIFT_ATTR_SUPPORTS_SENDABLE_DECLS) && __SWIFT_ATTR_SUPPORTS_SENDABLE_DECLS
34+
# define NS_SWIFT_SENDABLE __attribute__((swift_attr("@Sendable")))
35+
# else
36+
# define NS_SWIFT_SENDABLE
37+
# endif
38+
#endif // #if !defined(NS_SWIFT_SENDABLE)
39+
3140
typedef union {
3241
uint16_t _bits;
3342
__fp16 _fp;
34-
} __attribute__((packed)) half_t;
43+
} __attribute__((packed)) NS_SWIFT_SENDABLE half_t;
3544

3645
EXTERN_C HALF_FUNC half_t _half_zero(void);
3746
EXTERN_C HALF_FUNC half_t _half_epsilon(void);

Sources/Half/Half.swift

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,10 @@ import CHalf
1313
import CoreGraphics.CGBase
1414
#endif // #if os(iOS) || os(macOS) || os(tvOS) || os(watchOS)
1515

16-
#if swift(>=5.0)
1716
// MARK: - Half Definition
1817

19-
#if swift(>=5.1)
2018
/// A half-precision, floating-point value type.
21-
@frozen public struct Half {
19+
@frozen public struct Half: Sendable {
2220

2321
// MARK: Public Properties
2422

@@ -36,27 +34,6 @@ import CoreGraphics.CGBase
3634
self._value = _value
3735
}
3836
}
39-
#else
40-
/// A half-precision, floating-point value type.
41-
public struct Half {
42-
43-
// MARK: Public Properties
44-
45-
public var _value: half_t
46-
47-
// MARK: Initialization
48-
49-
@_transparent
50-
public init() {
51-
self._value = _half_zero()
52-
}
53-
54-
@_transparent
55-
public init(_ _value: half_t) {
56-
self._value = _value
57-
}
58-
}
59-
#endif
6037

6138
// MARK: - Half Extension
6239

@@ -1984,4 +1961,3 @@ extension Half: CustomPlaygroundDisplayConvertible {
19841961
return Float(self)
19851962
}
19861963
}
1987-
#endif // #if swift(>=5.0)

0 commit comments

Comments
 (0)