From 8d52279b9809ef27eabe7d5420f03734528f19da Mon Sep 17 00:00:00 2001 From: Stephen Celis Date: Wed, 27 Nov 2024 10:01:59 -0600 Subject: [PATCH] Fix Swift 5.9 (#111) * Fix Swift 5.9 * Fix --- Sources/PerceptionCore/Internal/ThreadLocal.swift | 7 ++++++- .../Internal/{UncheckedSendable.swift => Unchecked.swift} | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) rename Sources/PerceptionCore/Internal/{UncheckedSendable.swift => Unchecked.swift} (50%) diff --git a/Sources/PerceptionCore/Internal/ThreadLocal.swift b/Sources/PerceptionCore/Internal/ThreadLocal.swift index 02a3845..c1af3ca 100644 --- a/Sources/PerceptionCore/Internal/ThreadLocal.swift +++ b/Sources/PerceptionCore/Internal/ThreadLocal.swift @@ -13,7 +13,12 @@ import Foundation struct _ThreadLocal { #if os(WASI) - static nonisolated(unsafe) var value: UnsafeMutableRawPointer? + // NB: This can simply be 'nonisolated(unsafe)' when we drop support for Swift 5.9 + static var value: UnsafeMutableRawPointer? { + get { _value.value } + set { _value.value = newValue } + } + private static let _value = UncheckedBox(nil) #else static var value: UnsafeMutableRawPointer? { get { Thread.current.threadDictionary[Key()] as! UnsafeMutableRawPointer? } diff --git a/Sources/PerceptionCore/Internal/UncheckedSendable.swift b/Sources/PerceptionCore/Internal/Unchecked.swift similarity index 50% rename from Sources/PerceptionCore/Internal/UncheckedSendable.swift rename to Sources/PerceptionCore/Internal/Unchecked.swift index 712c62f..ea7e8e9 100644 --- a/Sources/PerceptionCore/Internal/UncheckedSendable.swift +++ b/Sources/PerceptionCore/Internal/Unchecked.swift @@ -1,3 +1,9 @@ +@usableFromInline final class UncheckedBox: @unchecked Sendable { + @usableFromInline var value: Value + @usableFromInline init(_ value: Value) { + self.value = value + } +} @usableFromInline struct UncheckedSendable: @unchecked Sendable { @usableFromInline let value: Value @usableFromInline init(_ value: Value) {