Skip to content

Commit

Permalink
Allows for parameterizing entities to be marked as sendable
Browse files Browse the repository at this point in the history
  • Loading branch information
vijaysharm committed Nov 13, 2024
1 parent 43aa8e5 commit ebe003a
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions CodeGen/Sources/LucidCodeGen/Meta/MetaEntity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ struct MetaEntity {

return Type(identifier: entity.typeID())
.adding(inheritedType: .codable)
.adding(inheritedType: entity.senable ? .sendable : nil)
.with(kind: .class(final: true))
.with(accessLevel: .public)
.with(body: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ struct MetaEntityIdentifier {

return Type(identifier: entity.identifierTypeID())
.adding(inheritedType: .codable)
.adding(inheritedType: entity.senable ? .sendable : nil)
.with(kind: .class(final: true))
.with(accessLevel: .public)
.adding(inheritedType: .coreDataIdentifier)
Expand Down
3 changes: 3 additions & 0 deletions CodeGen/Sources/LucidCodeGenCore/Codable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public enum DescriptionDefaults {
public static let ignorePropertyMigrationChecksOn = [String]()
public static let httpMethod: EndpointPayloadTest.HTTPMethod = .get
public static let cacheSize: EntityCacheSize = .group(.medium)
public static let sendable = false
}

public extension Entity {
Expand Down Expand Up @@ -322,6 +323,7 @@ extension Entity: Codable {
case queryContext
case clientQueueName
case cacheSize
case sendable
}

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

let systemPropertiesSet = Set(SystemPropertyName.allCases.map { $0.rawValue })
for property in properties where systemPropertiesSet.contains(property.name) {
Expand Down
6 changes: 5 additions & 1 deletion CodeGen/Sources/LucidCodeGenCore/Descriptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,8 @@ public struct Entity: Equatable {
public let clientQueueName: String

public let cacheSize: EntityCacheSize

public let senable: Bool

public init(name: String,
persistedName: String? = nil,
Expand All @@ -382,7 +384,8 @@ public struct Entity: Equatable {
versionHistory: [VersionHistoryItem] = [],
queryContext: Bool = DescriptionDefaults.queryContext,
clientQueueName: String = DescriptionDefaults.clientQueueName,
cacheSize: EntityCacheSize = DescriptionDefaults.cacheSize) {
cacheSize: EntityCacheSize = DescriptionDefaults.cacheSize,
sendable: Bool = DescriptionDefaults.sendable) {

self.name = name
self.persistedName = persistedName
Expand All @@ -400,6 +403,7 @@ public struct Entity: Equatable {
self.queryContext = queryContext
self.clientQueueName = clientQueueName
self.cacheSize = cacheSize
self.senable = sendable
}
}

Expand Down
4 changes: 4 additions & 0 deletions CodeGen/Sources/LucidCodeGenCore/MetaUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ public extension TypeIdentifier {
return TypeIdentifier(name: "CoreDataConversionError")
}

static var sendable: TypeIdentifier {
return TypeIdentifier(name: "Sendable")
}

static var equatable: TypeIdentifier {
return TypeIdentifier(name: "Equatable")
}
Expand Down
2 changes: 2 additions & 0 deletions Lucid/Core/Payload.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ public enum Lazy<T> {
case unrequested
}

extension Lazy: Sendable where T: Sendable {}

public extension Lazy where T: PayloadIdentifiable {

func identifier() -> Lazy<T.Identifier> {
Expand Down
2 changes: 2 additions & 0 deletions Lucid/Utils/AnySequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ extension AnySequence: Equatable where Element: Equatable {
}
}

extension AnySequence: Sendable where Element: Sendable {}

Check warning on line 64 in Lucid/Utils/AnySequence.swift

View workflow job for this annotation

GitHub Actions / Lucid-iOS Tests

conformance to 'Sendable' must occur in the same source file as generic struct 'AnySequence'; use '@unchecked Sendable' for retroactive conformance

public extension Result where Success: Sequence {

@inlinable var any: Result<AnySequence<Success.Element>, Failure> {
Expand Down
2 changes: 1 addition & 1 deletion Lucid/Utils/PropertyBox.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation

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

private let valueQueue: DispatchQueue?

Expand Down

0 comments on commit ebe003a

Please sign in to comment.