Skip to content
Draft
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
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ jobs:
name: Test Swift Linux
strategy:
matrix:
swift: ["5.10", "6.1", "6.2"]
swift: ["6.0", "6.1", "6.2"]
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v6
Expand Down
20 changes: 15 additions & 5 deletions 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
/*
* Copyright 2020 Google Inc. All rights reserved.
*
Expand Down Expand Up @@ -36,14 +36,17 @@ let package = Package(
.target(
name: "FlatBuffers",
dependencies: ["Common"],
path: "swift/Sources/FlatBuffers"),
path: "swift/Sources/FlatBuffers",
swiftSettings: .settings),
.target(
name: "FlexBuffers",
dependencies: ["Common"],
path: "swift/Sources/FlexBuffers"),
path: "swift/Sources/FlexBuffers",
swiftSettings: .settings),
.target(
name: "Common",
path: "swift/Sources/Common"),
path: "swift/Sources/Common",
swiftSettings: .settings),
.testTarget(
name: "FlatbuffersTests",
dependencies: .dependencies,
Expand All @@ -52,7 +55,14 @@ let package = Package(
name: "FlexbuffersTests",
dependencies: ["FlexBuffers"],
path: "tests/swift/Tests/Flexbuffers"),
])
],
swiftLanguageModes: [.v6])

extension Array where Element == SwiftSetting {
static var settings: [SwiftSetting] {
[.enableUpcomingFeature("ExistentialAny")]
}
}

extension Array where Element == Package.Dependency {
static var dependencies: [Package.Dependency] {
Expand Down
2 changes: 1 addition & 1 deletion swift/Sources/FlatBuffers/ByteBuffer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public struct ByteBuffer {
enum Blob {
#if !os(WASI)
case data(Data)
case bytes(ContiguousBytes)
case bytes(any ContiguousBytes)
#endif

case byteBuffer(_InternalByteBuffer)
Expand Down
2 changes: 1 addition & 1 deletion swift/Sources/FlatBuffers/FlatBufferBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ public struct FlatBufferBuilder {
///
/// - Parameter bytes: bytes to be written into the buffer
/// - Returns: ``Offset`` of the vector
mutating public func createVector(bytes: ContiguousBytes) -> Offset {
mutating public func createVector(bytes: any ContiguousBytes) -> Offset {
bytes.withUnsafeBytes {
startVector($0.count, elementSize: MemoryLayout<UInt8>.size)
_bb.push(bytes: $0)
Expand Down
2 changes: 1 addition & 1 deletion swift/Sources/FlatBuffers/TableVerifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public struct TableVerifier {
unionKeyName: String,
fieldName: String,
required: Bool,
completion: @escaping (inout Verifier, T, Int) throws -> Void) throws
completion: (inout Verifier, T, Int) throws -> Void) throws
where T: UnionEnum
{
let keyPos = try dereference(key)
Expand Down
2 changes: 1 addition & 1 deletion swift/Sources/FlatBuffers/Vectors/FlatbufferVector.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public struct FlatbufferVector<
}

extension FlatbufferVector: Encodable where Element: Encodable {
public func encode(to encoder: Encoder) throws {
public func encode(to encoder: any Encoder) throws {
var container = encoder.unkeyedContainer()
for element in self {
try container.encode(element)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ public struct UnionFlatbufferVector {

public subscript(
position: Int,
Type: FlatbuffersVectorInitializable
.Type) -> FlatbuffersVectorInitializable
Type: any FlatbuffersVectorInitializable
.Type) -> any FlatbuffersVectorInitializable
{
guard position < count else {
fatalError(
Expand Down
2 changes: 1 addition & 1 deletion swift/Sources/FlatBuffers/_InternalByteBuffer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ struct _InternalByteBuffer {
#if !os(WASI)
@inline(__always)
@usableFromInline
mutating func push(bytes: ContiguousBytes) {
mutating func push(bytes: any ContiguousBytes) {
bytes.withUnsafeBytes { ptr in
ensureSpace(size: ptr.count)
memcpy(
Expand Down
2 changes: 1 addition & 1 deletion swift/Sources/FlexBuffers/ByteBuffer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public struct ByteBuffer {
enum Blob {
#if !os(WASI)
case data(Data)
case bytes(ContiguousBytes)
case bytes(any ContiguousBytes)
#endif

case byteBuffer(_InternalByteBuffer)
Expand Down
2 changes: 1 addition & 1 deletion swift/Sources/FlexBuffers/FlexBufferType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import Foundation

public enum FlexBufferType: UInt64 {
public enum FlexBufferType: UInt64, Sendable {
case null = 0
/// Variable width signed integer: `Int8, Int16, Int32, Int64`
case int = 1
Expand Down
2 changes: 1 addition & 1 deletion swift/Sources/FlexBuffers/Utils/BitWidth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import Foundation

@usableFromInline
enum BitWidth: UInt64, CaseIterable {
enum BitWidth: UInt64, CaseIterable, Sendable {
case w8 = 0
case w16 = 1
case w32 = 2
Expand Down
4 changes: 2 additions & 2 deletions swift/Sources/FlexBuffers/Utils/Value.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ import Foundation
import Common
#endif

public struct Value: Equatable {
public struct Value: Equatable, Sendable {

@usableFromInline
enum Union: Equatable {
enum Union: Equatable, Sendable {
case i(Int64)
case u(UInt64)
case f(Double)
Expand Down
9 changes: 6 additions & 3 deletions swift/Sources/FlexBuffers/Writer/FlexBuffersWriter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -479,12 +479,12 @@ public struct FlexBuffersWriter {
@inline(__always)
public mutating func add(string: borrowing String, key: borrowing String) {
add(key: key)
write(str: string, len: string.count)
write(str: string, len: string.utf8.count)
}

@inline(__always)
public mutating func add(string: borrowing String) {
write(str: string, len: string.count)
write(str: string, len: string.utf8.count)
}

// MARK: - Writing Blobs
Expand Down Expand Up @@ -591,7 +591,7 @@ public struct FlexBuffersWriter {
@discardableResult
@inline(__always)
private mutating func add(key: borrowing String) -> UInt {
add(key: key, len: key.count)
add(key: key, len: key.utf8.count)
}

@discardableResult
Expand Down Expand Up @@ -977,6 +977,9 @@ fileprivate struct Stack: RandomAccessCollection {
mutating func removeAll(keepingCapacity keepCapacity: Bool = false) {
count = 0
if !keepCapacity {
let ptr = storage.memory
defer { ptr.deallocate() }

capacity = Self.initialCapacity
storage.memory = UnsafeMutableRawPointer.allocate(
byteCount: capacity,
Expand Down
Loading