Skip to content

Commit dd82489

Browse files
authored
Merge pull request #193 from scribd/vijays/make-entities-optionally-sendable
Allows for parameterizing entities to be marked as sendable
2 parents 2d1f778 + f00e183 commit dd82489

File tree

9 files changed

+24
-2
lines changed

9 files changed

+24
-2
lines changed

CodeGen/Sources/LucidCodeGen/Meta/MetaEntity.swift

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ struct MetaEntity {
6868

6969
return Type(identifier: entity.typeID())
7070
.adding(inheritedType: .codable)
71+
.adding(inheritedType: entity.senable ? .sendable : nil)
7172
.with(kind: .class(final: true))
7273
.with(accessLevel: .public)
7374
.with(body: [

CodeGen/Sources/LucidCodeGen/Meta/MetaEntityIdentifier.swift

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ struct MetaEntityIdentifier {
4444

4545
return Type(identifier: entity.identifierTypeID())
4646
.adding(inheritedType: .codable)
47+
.adding(inheritedType: entity.senable ? .sendable : nil)
4748
.with(kind: .class(final: true))
4849
.with(accessLevel: .public)
4950
.adding(inheritedType: .coreDataIdentifier)

CodeGen/Sources/LucidCodeGen/Meta/MetaSubtype.swift

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ struct MetaSubtype {
5050
let type = Type(identifier: subtype.typeID())
5151
.with(accessLevel: .public)
5252
.adding(inheritedType: .codable)
53+
.adding(inheritedType: subtype.sendable ? .sendable : nil)
5354
.adding(inheritedType: .hashable)
5455

5556
switch subtype.items {

CodeGen/Sources/LucidCodeGenCore/Codable.swift

+5
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public enum DescriptionDefaults {
4040
public static let ignorePropertyMigrationChecksOn = [String]()
4141
public static let httpMethod: EndpointPayloadTest.HTTPMethod = .get
4242
public static let cacheSize: EntityCacheSize = .group(.medium)
43+
public static let sendable = false
4344
}
4445

4546
public extension Entity {
@@ -322,6 +323,7 @@ extension Entity: Codable {
322323
case queryContext
323324
case clientQueueName
324325
case cacheSize
326+
case sendable
325327
}
326328

327329
public init(from decoder: Decoder) throws {
@@ -348,6 +350,7 @@ extension Entity: Codable {
348350
queryContext = try container.decodeIfPresent(Bool.self, forKey: .queryContext) ?? DescriptionDefaults.queryContext
349351
clientQueueName = try container.decodeIfPresent(String.self, forKey: .clientQueueName) ?? DescriptionDefaults.clientQueueName
350352
cacheSize = try container.decodeIfPresent(EntityCacheSize.self, forKey: .cacheSize) ?? DescriptionDefaults.cacheSize
353+
senable = try container.decodeIfPresent(Bool.self, forKey: .sendable) ?? DescriptionDefaults.sendable
351354

352355
let systemPropertiesSet = Set(SystemPropertyName.allCases.map { $0.rawValue })
353356
for property in properties where systemPropertiesSet.contains(property.name) {
@@ -754,6 +757,7 @@ extension Subtype: Codable {
754757
case objc
755758
case objcNoneCase
756759
case platforms
760+
case sendable
757761
}
758762

759763
public init(from decoder: Decoder) throws {
@@ -762,6 +766,7 @@ extension Subtype: Codable {
762766
name = try container.decode(String.self, forKey: .name)
763767
manualImplementations = Set(try container.decodeIfPresent([`Protocol`].self, forKey: .manualImplementations) ?? [])
764768
platforms = try container.decodeIfPresent(Set<Platform>.self, forKey: .platforms) ?? DescriptionDefaults.platforms
769+
sendable = try container.decodeIfPresent(Bool.self, forKey: .sendable) ?? DescriptionDefaults.sendable
765770

766771
if let usedCases = try container.decodeIfPresent([String].self, forKey: .cases) {
767772
let unusedCases = try container.decodeIfPresent([String].self, forKey: .unusedCases) ?? []

CodeGen/Sources/LucidCodeGenCore/Descriptions.swift

+7-1
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,8 @@ public struct Entity: Equatable {
368368
public let clientQueueName: String
369369

370370
public let cacheSize: EntityCacheSize
371+
372+
public let senable: Bool
371373

372374
public init(name: String,
373375
persistedName: String? = nil,
@@ -382,7 +384,8 @@ public struct Entity: Equatable {
382384
versionHistory: [VersionHistoryItem] = [],
383385
queryContext: Bool = DescriptionDefaults.queryContext,
384386
clientQueueName: String = DescriptionDefaults.clientQueueName,
385-
cacheSize: EntityCacheSize = DescriptionDefaults.cacheSize) {
387+
cacheSize: EntityCacheSize = DescriptionDefaults.cacheSize,
388+
sendable: Bool = DescriptionDefaults.sendable) {
386389

387390
self.name = name
388391
self.persistedName = persistedName
@@ -400,6 +403,7 @@ public struct Entity: Equatable {
400403
self.queryContext = queryContext
401404
self.clientQueueName = clientQueueName
402405
self.cacheSize = cacheSize
406+
self.senable = sendable
403407
}
404408
}
405409

@@ -641,6 +645,8 @@ public struct Subtype: Equatable {
641645
public let objc: Bool
642646

643647
public let platforms: Set<Platform>
648+
649+
public let sendable: Bool
644650
}
645651

646652
// MARK: - Conversions

CodeGen/Sources/LucidCodeGenCore/MetaUtils.swift

+4
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,10 @@ public extension TypeIdentifier {
206206
return TypeIdentifier(name: "CoreDataConversionError")
207207
}
208208

209+
static var sendable: TypeIdentifier {
210+
return TypeIdentifier(name: "Sendable")
211+
}
212+
209213
static var equatable: TypeIdentifier {
210214
return TypeIdentifier(name: "Equatable")
211215
}

Lucid/Core/Payload.swift

+2
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ public enum Lazy<T> {
8585
case unrequested
8686
}
8787

88+
extension Lazy: Sendable where T: Sendable {}
89+
8890
public extension Lazy where T: PayloadIdentifiable {
8991

9092
func identifier() -> Lazy<T.Identifier> {

Lucid/Utils/AnySequence.swift

+2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ extension AnySequence: Equatable where Element: Equatable {
6161
}
6262
}
6363

64+
extension AnySequence: @unchecked Sendable where Element: Sendable {}
65+
6466
public extension Result where Success: Sequence {
6567

6668
@inlinable var any: Result<AnySequence<Success.Element>, Failure> {

Lucid/Utils/PropertyBox.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import Foundation
1010

1111
/// A mutable property which can either ensure atomicity or not.
12-
public final class PropertyBox<T> {
12+
public final class PropertyBox<T>: @unchecked Sendable {
1313

1414
private let valueQueue: DispatchQueue?
1515

0 commit comments

Comments
 (0)