Skip to content

Commit

Permalink
code cleanup, and maybe resolving a build error on SPI w/ Swift 5.7 a…
Browse files Browse the repository at this point in the history
…nd linux
  • Loading branch information
heckj committed Nov 27, 2023
1 parent c867c45 commit 65b0be3
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 23 deletions.
4 changes: 3 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import PackageDescription

var globalSwiftSettings: [PackageDescription.SwiftSetting] = []
#if swift(>=5.7)
#if canImport(Foundation)
if ProcessInfo.processInfo.environment["CI"] != nil {
globalSwiftSettings.append(.unsafeFlags(["-Xfrontend", "-strict-concurrency=complete"]))
/*
Summation from https://www.donnywals.com/enabling-concurrency-warnings-in-xcode-14/
Set `strict-concurrency` to `targeted` to enforce Sendable and actor-isolation checks
in your code. This explicitly verifies that `Sendable` constraints are met when you
mark one of your types as `Sendable`.

This mode is essentially a bit of a hybrid between the behavior that's intended in
Swift 6, and the default in Swift 5.7. Use this mode to have a bit of checking on
your code that uses Swift concurrency without too many warnings and / or errors in
Expand All @@ -21,6 +22,7 @@ var globalSwiftSettings: [PackageDescription.SwiftSetting] = []
constraints, essentially as they will work in Swift 6.
*/
}
#endif
#endif

let package = Package(
Expand Down
2 changes: 1 addition & 1 deletion Sources/CRDT/GenericCRDTs/GCounter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/// by Marc Shapiro, Nuno Preguiça, Carlos Baquero, and Marek Zawirski (2011).
public struct GCounter<ActorID: Hashable & PartiallyOrderable> {
private var _storage: UInt
internal let selfId: ActorID
let selfId: ActorID

/// The counter's value.
public var value: UInt {
Expand Down
2 changes: 1 addition & 1 deletion Sources/CRDT/GenericCRDTs/GSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/// by Marc Shapiro, Nuno Preguiça, Carlos Baquero, and Marek Zawirski (2011).
public struct GSet<ActorID: Hashable & PartiallyOrderable, T: Hashable> {
private var _storage: Set<T>
internal var currentTimestamp: LamportTimestamp<ActorID>
var currentTimestamp: LamportTimestamp<ActorID>

/// The set of values.
public var values: Set<T> {
Expand Down
6 changes: 3 additions & 3 deletions Sources/CRDT/GenericCRDTs/LWWRegister.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import Foundation
public struct LWWRegister<ActorID: Hashable & PartiallyOrderable, T> {
/// A struct that represents the state of an LWWRegister
public struct Metadata {
internal var value: T
internal var clockId: WallclockTimestamp<ActorID>
var value: T
var clockId: WallclockTimestamp<ActorID>

init(value: T, id: ActorID, timestamp: TimeInterval = Date().timeIntervalSinceReferenceDate) {
self.value = value
Expand All @@ -37,7 +37,7 @@ public struct LWWRegister<ActorID: Hashable & PartiallyOrderable, T> {
}

private var _storage: Metadata
internal let selfId: ActorID
let selfId: ActorID

/// The value of the register.
public var value: T {
Expand Down
6 changes: 3 additions & 3 deletions Sources/CRDT/GenericCRDTs/List.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ public struct List<ActorID: Hashable & PartiallyOrderable, T: Hashable & Equatab
}

// A combination of Lamport timestamp & actor ID
internal var currentTimestamp: LamportTimestamp<ActorID>
internal var activeValues: [Metadata] = []
internal var tombstones: [Metadata] = []
var currentTimestamp: LamportTimestamp<ActorID>
var activeValues: [Metadata] = []
var tombstones: [Metadata] = []

/// The values of the list.
public var values: [T] { activeValues.map(\.value) }
Expand Down
6 changes: 3 additions & 3 deletions Sources/CRDT/GenericCRDTs/ORMap.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/// Annette Bieniusa, Marek Zawirski, Nuno Preguiça, Marc Shapiro, Carlos Baquero, Valter Balegas, and Sérgio Duarte (2012).
/// arXiv:[1210.3368](https://arxiv.org/abs/1210.3368).
public struct ORMap<ActorID: Hashable & PartiallyOrderable, KEY: Hashable, VALUE: Equatable> {
internal struct Metadata: CustomStringConvertible {
struct Metadata: CustomStringConvertible {
var isDeleted: Bool
var lamportTimestamp: LamportTimestamp<ActorID>
var value: VALUE
Expand All @@ -25,8 +25,8 @@ public struct ORMap<ActorID: Hashable & PartiallyOrderable, KEY: Hashable, VALUE
}
}

internal var currentTimestamp: LamportTimestamp<ActorID>
internal var metadataByDictKey: [KEY: Metadata]
var currentTimestamp: LamportTimestamp<ActorID>
var metadataByDictKey: [KEY: Metadata]

/// Creates a new grow-only set..
/// - Parameters:
Expand Down
6 changes: 3 additions & 3 deletions Sources/CRDT/GenericCRDTs/ORSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/// Annette Bieniusa, Marek Zawirski, Nuno Preguiça, Marc Shapiro, Carlos Baquero, Valter Balegas, and Sérgio Duarte (2012).
/// arXiv:[1210.3368](https://arxiv.org/abs/1210.3368)
public struct ORSet<ActorID: Hashable & PartiallyOrderable, T: Hashable> {
internal struct Metadata: CustomStringConvertible {
struct Metadata: CustomStringConvertible {
var isDeleted: Bool
var lamportTimestamp: LamportTimestamp<ActorID>
var description: String {
Expand All @@ -24,8 +24,8 @@ public struct ORSet<ActorID: Hashable & PartiallyOrderable, T: Hashable> {
}
}

internal var currentTimestamp: LamportTimestamp<ActorID>
internal var metadataByValue: [T: Metadata]
var currentTimestamp: LamportTimestamp<ActorID>
var metadataByValue: [T: Metadata]

/// Creates a new grow-only set..
/// - Parameters:
Expand Down
6 changes: 3 additions & 3 deletions Sources/CRDT/GenericCRDTs/PNCounter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
/// [A comprehensive study of Convergent and Commutative Replicated Data Types](https://hal.inria.fr/inria-00555588/document)”
/// by Marc Shapiro, Nuno Preguiça, Carlos Baquero, and Marek Zawirski (2011).
public struct PNCounter<ActorID: Hashable & PartiallyOrderable> {
internal var pos_value: UInt
internal var neg_value: UInt
internal let selfId: ActorID
var pos_value: UInt
var neg_value: UInt
let selfId: ActorID

/// The counter's value.
public var value: Int {
Expand Down
4 changes: 2 additions & 2 deletions Sources/CRDT/LamportTimestamp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
/// where the clock value is identical. These scenarios happen when two independent CRDTs update internal values
/// "at the same time".
public struct LamportTimestamp<ActorID: Hashable & PartiallyOrderable>: Identifiable, PartiallyOrderable {
internal var clock: UInt64 = 0
internal var actorId: ActorID
var clock: UInt64 = 0
var actorId: ActorID

/// A stable, unique identity for the Lamport timestamp.
public var id: String {
Expand Down
4 changes: 2 additions & 2 deletions Sources/CRDT/WallclockTimestamp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import Foundation
/// where the clock value is identical. These scenarios happen when two independent CRDTs update internal values
/// "at the same time".
public struct WallclockTimestamp<ActorID: Hashable & PartiallyOrderable>: Identifiable, PartiallyOrderable {
internal var clock: TimeInterval
internal var actorId: ActorID
var clock: TimeInterval
var actorId: ActorID

/// A stable, unique identity for the wallclock timestamp.
public var id: String {
Expand Down
2 changes: 1 addition & 1 deletion Tests/CRDTTests/ORMapTests.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// ORSetTests.swift
// ORMapTests.swift
//

@testable import CRDT
Expand Down

0 comments on commit 65b0be3

Please sign in to comment.