Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift 6.0 #27

Merged
merged 8 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
pull_request:
branches: ["master"]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
lint:
Expand Down Expand Up @@ -33,9 +36,9 @@ jobs:
restore-keys: |
${{ runner.os }}-spm-
- name: Setup Swift
uses: swift-actions/setup-swift@v2
uses: SwiftyLab/setup-swift@latest
with:
swift-version: "5.10"
swift-version: '6.0'
- name: Build
run: make build
- name: Test
Expand Down
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.10
6.0
5 changes: 3 additions & 2 deletions Blockchain/Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version: 5.10
// swift-tools-version: 6.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
Expand Down Expand Up @@ -37,5 +37,6 @@ let package = Package(
name: "BlockchainTests",
dependencies: ["Blockchain"]
),
]
],
swiftLanguageVersions: [.version("6")]
)
2 changes: 1 addition & 1 deletion Blockchain/Sources/Blockchain/Config/ProtocolConfig.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Utils

// constants defined in the graypaper
public struct ProtocolConfig {
public struct ProtocolConfig: Sendable {
// A = 8: The period, in seconds, between audit tranches.
public var auditTranchePeriod: Int

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ScaleCodec
import Utils

public struct AvailabilitySpecifications {
public struct AvailabilitySpecifications: Sendable {
// h
public var workPackageHash: H256

Expand Down
2 changes: 1 addition & 1 deletion Blockchain/Sources/Blockchain/Types/Block.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ScaleCodec
import Utils

public struct Block {
public struct Block: Sendable {
public var header: Header
public var extrinsic: Extrinsic

Expand Down
2 changes: 1 addition & 1 deletion Blockchain/Sources/Blockchain/Types/Extrinsic.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ScaleCodec
import Utils

public struct Extrinsic {
public struct Extrinsic: Sendable {
// ET: Tickets, used for the mechanism which manages the selection of validators for the
// permissioning of block authoring
public var tickets: ExtrinsicTickets
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import Foundation
import ScaleCodec
import Utils

public struct ExtrinsicAvailability {
public struct AssuranceItem {
public struct ExtrinsicAvailability: Sendable {
public struct AssuranceItem: Sendable {
// a
public var parentHash: H256
// f
Expand Down
4 changes: 2 additions & 2 deletions Blockchain/Sources/Blockchain/Types/ExtrinsicGuarantees.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import ScaleCodec
import Utils

public struct ExtrinsicGuarantees {
public struct GuaranteeItem {
public struct ExtrinsicGuarantees: Sendable {
public struct GuaranteeItem: Sendable {
public var coreIndex: CoreIndex
public var workReport: WorkReport
public var timeslot: TimeslotIndex
Expand Down
6 changes: 3 additions & 3 deletions Blockchain/Sources/Blockchain/Types/ExtrinsicJudgement.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import ScaleCodec
import Utils

public struct ExtrinsicJudgement {
public struct JudgementItem {
public struct SignatureItem {
public struct ExtrinsicJudgement: Sendable {
public struct JudgementItem: Sendable {
public struct SignatureItem: Sendable {
public var isValid: Bool
public var validatorIndex: ValidatorIndex
public var signature: BandersnatchSignature
Expand Down
24 changes: 12 additions & 12 deletions Blockchain/Sources/Blockchain/Types/ExtrinsicPreimages.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,17 @@ import Foundation
import ScaleCodec
import Utils

public struct ExtrinsicPreimages {
public struct ExtrinsicPreimages: Sendable {
public struct SizeAndData: Sendable {
public var size: DataLength
public var data: Data

public init(size: DataLength, data: Data) {
self.size = size
self.data = data
}
}

public var preimages: [SizeAndData]

public init(
Expand Down Expand Up @@ -31,17 +41,7 @@ extension ExtrinsicPreimages: ScaleCodec.Codable {
}
}

public struct SizeAndData {
public var size: DataLength
public var data: Data

public init(size: DataLength, data: Data) {
self.size = size
self.data = data
}
}

extension SizeAndData: ScaleCodec.Codable {
extension ExtrinsicPreimages.SizeAndData: ScaleCodec.Codable {
public init(from decoder: inout some ScaleCodec.Decoder) throws {
try self.init(
size: decoder.decode(),
Expand Down
4 changes: 2 additions & 2 deletions Blockchain/Sources/Blockchain/Types/ExtrinsicTickets.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import ScaleCodec
import Utils

public struct ExtrinsicTickets {
public struct TicketItem {
public struct ExtrinsicTickets: Sendable {
public struct TicketItem: Sendable {
public var ticketIndex: TicketIndex
public var proof: BandersnatchRintVRFProof

Expand Down
4 changes: 2 additions & 2 deletions Blockchain/Sources/Blockchain/Types/Header.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import ScaleCodec
import Utils

public struct Header {
public struct EpochMarker {
public struct Header: Sendable {
public struct EpochMarker: Sendable {
public var randomness: H256
public var keys: ConfigFixedSizeArray<
BandersnatchPublicKey,
Expand Down
2 changes: 1 addition & 1 deletion Blockchain/Sources/Blockchain/Types/JudgementsState.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ScaleCodec
import Utils

public struct JudgementsState {
public struct JudgementsState: Sendable {
// ψa: The allow-set contains the hashes of all work-reports which were disputed and judged to be accurate.
public var allowSet: Set<H256>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Utils

// A refinement context, denoted by the set X, describes the context of the chain
// at the point that the report’s corresponding work-package was evaluated.
public struct RefinementContext {
public struct RefinementContext: Sendable {
public var anchor: (
headerHash: H256,
stateRoot: H256,
Expand Down
2 changes: 1 addition & 1 deletion Blockchain/Sources/Blockchain/Types/SafroleState.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ScaleCodec
import Utils

public struct SafroleState {
public struct SafroleState: Sendable {
// γk
public var pendingValidators: ConfigFixedSizeArray<
ValidatorKey, ProtocolConfig.TotalNumberOfValidators
Expand Down
4 changes: 2 additions & 2 deletions Blockchain/Sources/Blockchain/Types/ServiceAccount.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import Foundation
import ScaleCodec
import Utils

public struct ServiceAccount {
public struct HashAndLength: Hashable {
public struct ServiceAccount: Sendable {
public struct HashAndLength: Sendable, Hashable {
public var hash: H256
public var length: DataLength

Expand Down
4 changes: 2 additions & 2 deletions Blockchain/Sources/Blockchain/Types/State.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import ScaleCodec
import Utils

public struct State {
public struct ReportItem {
public struct State: Sendable {
public struct ReportItem: Sendable {
public var workReport: WorkReport
public var guarantors: LimitedSizeArray<Ed25519PublicKey, ConstInt2, ConstInt3>
public var timestamp: TimeslotIndex
Expand Down
2 changes: 1 addition & 1 deletion Blockchain/Sources/Blockchain/Types/Ticket.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ScaleCodec
import Utils

public struct Ticket {
public struct Ticket: Sendable {
public var identifier: H256
public var entryIndex: TicketIndex
}
Expand Down
2 changes: 1 addition & 1 deletion Blockchain/Sources/Blockchain/Types/ValidatorKey.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ScaleCodec
import Utils

public struct ValidatorKey {
public struct ValidatorKey: Sendable {
public var bandersnatchKey: BandersnatchPublicKey
public var ed25519Key: Ed25519PublicKey
public var blsKey: BLSKey
Expand Down
2 changes: 1 addition & 1 deletion Blockchain/Sources/Blockchain/Types/WorkReport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Foundation
import ScaleCodec
import Utils

public struct WorkReport {
public struct WorkReport: Sendable {
// a: authorizer hash
public var authorizerHash: H256

Expand Down
2 changes: 1 addition & 1 deletion Blockchain/Sources/Blockchain/Types/WorkResult.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Foundation
import ScaleCodec
import Utils

public struct WorkResult {
public struct WorkResult: Sendable {
// s: the index of the service whose state is to be altered and thus whose refine code was already executed
public var serviceIdentifier: ServiceIdentifier

Expand Down
5 changes: 3 additions & 2 deletions Boka/Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version: 5.10
// swift-tools-version: 6.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
Expand Down Expand Up @@ -26,5 +26,6 @@ let package = Package(
name: "BokaTests",
dependencies: ["Boka"]
),
]
],
swiftLanguageVersions: [.version("6")]
)
5 changes: 3 additions & 2 deletions Database/Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version: 5.10
// swift-tools-version: 6.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
Expand All @@ -22,5 +22,6 @@ let package = Package(
name: "DatabaseTests",
dependencies: ["Database"]
),
]
],
swiftLanguageVersions: [.version("6")]
)
5 changes: 3 additions & 2 deletions Node/Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version: 5.10
// swift-tools-version: 6.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
Expand Down Expand Up @@ -32,5 +32,6 @@ let package = Package(
name: "NodeTests",
dependencies: ["Node"]
),
]
],
swiftLanguageVersions: [.version("6")]
)
5 changes: 3 additions & 2 deletions Utils/Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version: 5.10
// swift-tools-version: 6.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
Expand Down Expand Up @@ -31,5 +31,6 @@ let package = Package(
name: "UtilsTests",
dependencies: ["Utils"]
),
]
],
swiftLanguageVersions: [.version("6")]
)
2 changes: 2 additions & 0 deletions Utils/Sources/Utils/ConfigLimitedSizeArray.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public struct ConfigLimitedSizeArray<T, TMinLength: ReadInt, TMaxLength: ReadInt
}
}

extension ConfigLimitedSizeArray: Sendable where T: Sendable {}

extension ConfigLimitedSizeArray: RandomAccessCollection {
public typealias Element = T
public typealias Index = Int
Expand Down
2 changes: 2 additions & 0 deletions Utils/Sources/Utils/Either.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ public enum Either<A, B> {

extension Either: Equatable where A: Equatable, B: Equatable {}

extension Either: Sendable where A: Sendable, B: Sendable {}

extension Either: CustomStringConvertible where A: CustomStringConvertible, B: CustomStringConvertible {
public var description: String {
switch self {
Expand Down
2 changes: 1 addition & 1 deletion Utils/Sources/Utils/FixedSizeData.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation
import ScaleCodec

public struct FixedSizeData<T: ConstInt> {
public struct FixedSizeData<T: ConstInt>: Sendable {
public private(set) var data: Data

public init?(_ value: Data) {
Expand Down
2 changes: 2 additions & 0 deletions Utils/Sources/Utils/LimitedSizeArray.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public struct LimitedSizeArray<T, TMinLength: ConstInt, TMaxLength: ConstInt> {
}
}

extension LimitedSizeArray: Sendable where T: Sendable {}

extension LimitedSizeArray: ExpressibleByArrayLiteral {
public init(arrayLiteral elements: T...) {
self.init(elements)
Expand Down
17 changes: 7 additions & 10 deletions Utils/Sources/Utils/Ref.swift
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
import ScaleCodec

public class Ref<T> {
public internal(set) var value: T
public final class Ref<T: Sendable>: Sendable {
public let value: T

public required init(_ value: T) {
self.value = value
}
}

public class RefMut<T>: Ref<T> {
override public var value: T {
get {
super.value
}
set {
super.value = newValue
}
public final class RefMut<T> {
public var value: T

public required init(_ value: T) {
self.value = value
}
}

Expand Down
Loading