Skip to content

Commit

Permalink
Merge pull request #18 from SomeRandomiOSDev/strict-concurrency
Browse files Browse the repository at this point in the history
Added strict concurrency checking and Sendable conformances
  • Loading branch information
SomeRandomiOSDev committed Nov 15, 2023
2 parents bb32fc7 + 40a57ef commit 14b1ab3
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 34 deletions.
9 changes: 5 additions & 4 deletions Half.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

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

s.source_files = 'Sources/**/*.{swift,h,c}'
s.swift_versions = ['5.0']
s.cocoapods_version = '>= 1.7.3'
s.source_files = 'Sources/**/*.{swift,h,c}'
s.pod_target_xcconfig = { 'SWIFT_STRICT_CONCURRENCY' => 'complete' }
s.swift_versions = ['5.0']
s.cocoapods_version = '>= 1.7.3'

end
2 changes: 2 additions & 0 deletions Half.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1030,6 +1030,7 @@
SDKROOT = iphoneos;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_STRICT_CONCURRENCY = complete;
SWIFT_VERSION = 5.0;
TVOS_DEPLOYMENT_TARGET = 12.0;
VERSIONING_SYSTEM = "apple-generic";
Expand Down Expand Up @@ -1094,6 +1095,7 @@
SDKROOT = iphoneos;
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_OPTIMIZATION_LEVEL = "-O";
SWIFT_STRICT_CONCURRENCY = complete;
SWIFT_VERSION = 5.0;
TVOS_DEPLOYMENT_TARGET = 12.0;
VALIDATE_PRODUCT = YES;
Expand Down
26 changes: 22 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.7
// swift-tools-version:5.8
import PackageDescription

let package = Package(
Expand All @@ -17,9 +17,27 @@ let package = Package(

targets: [
.target(name: "CHalf"),
.testTarget(name: "CHalfTests", dependencies: ["CHalf", "Half"]),
.testTarget(
name: "CHalfTests",
dependencies: ["CHalf", "Half"],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency")
]
),

.target(name: "Half", dependencies: ["CHalf"]),
.testTarget(name: "HalfTests", dependencies: ["Half"])
.target(
name: "Half",
dependencies: ["CHalf"],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency")
]
),
.testTarget(
name: "HalfTests",
dependencies: ["Half"],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency")
]
)
]
)
11 changes: 10 additions & 1 deletion Sources/CHalf/include/half.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,19 @@
#define HALF_FUNC HALF_CONST
#define HALF_OFUNC HALF_FUNC __attribute__((__overloadable__))

// Copied from <Foundation/NSObjCRuntime.h> since that header cannot be imported
#if !defined(NS_SWIFT_SENDABLE)
# if defined(__SWIFT_ATTR_SUPPORTS_SENDABLE_DECLS) && __SWIFT_ATTR_SUPPORTS_SENDABLE_DECLS
# define NS_SWIFT_SENDABLE __attribute__((swift_attr("@Sendable")))
# else
# define NS_SWIFT_SENDABLE
# endif
#endif // #if !defined(NS_SWIFT_SENDABLE)

typedef union {
uint16_t _bits;
__fp16 _fp;
} __attribute__((packed)) half_t;
} __attribute__((packed)) NS_SWIFT_SENDABLE half_t;

EXTERN_C HALF_FUNC half_t _half_zero(void);
EXTERN_C HALF_FUNC half_t _half_epsilon(void);
Expand Down
26 changes: 1 addition & 25 deletions Sources/Half/Half.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@ import CHalf
import CoreGraphics.CGBase
#endif // #if os(iOS) || os(macOS) || os(tvOS) || os(watchOS)

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

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

// MARK: Public Properties

Expand All @@ -36,27 +34,6 @@ import CoreGraphics.CGBase
self._value = _value
}
}
#else
/// A half-precision, floating-point value type.
public struct Half {

// MARK: Public Properties

public var _value: half_t

// MARK: Initialization

@_transparent
public init() {
self._value = _half_zero()
}

@_transparent
public init(_ _value: half_t) {
self._value = _value
}
}
#endif

// MARK: - Half Extension

Expand Down Expand Up @@ -1984,4 +1961,3 @@ extension Half: CustomPlaygroundDisplayConvertible {
return Float(self)
}
}
#endif // #if swift(>=5.0)

0 comments on commit 14b1ab3

Please sign in to comment.