Skip to content

Commit d9b56a7

Browse files
authored
Enable Swift 6 mode, fix concurrency build errors (#202)
This mostly amounted to adding `Sendable` on existing value types, or avoiding use of reference types where not needed.
1 parent 89d6932 commit d9b56a7

File tree

18 files changed

+61
-71
lines changed

18 files changed

+61
-71
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ jobs:
142142
run: |
143143
toolchain_path="/opt/swiftwasm"
144144
./build-exec mkdir -p "$toolchain_path"
145-
curl -v -L ${{ matrix.development-toolchain-download }} | ./build-exec tar xz --strip-component 1 -C "$toolchain_path"
145+
curl -L ${{ matrix.development-toolchain-download }} | ./build-exec tar xz --strip-component 1 -C "$toolchain_path"
146146
echo "toolchain-path=$toolchain_path" >> $GITHUB_OUTPUT
147147
./build-exec "$toolchain_path/usr/bin/swift" sdk install "${{ matrix.wasi-swift-sdk-download }}" --checksum "${{ matrix.wasi-swift-sdk-checksum }}"
148148
wasi_sdk_path=$(./build-exec "$toolchain_path/usr/bin/swift" sdk configure --show-configuration "${{ matrix.wasi-swift-sdk-id }}" wasm32-unknown-wasi | grep sdkRootPath: | cut -d: -f2)

Package.swift

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,7 @@ import PackageDescription
44

55
import class Foundation.ProcessInfo
66

7-
let DarwinPlatforms: [Platform]
8-
#if swift(<5.9)
9-
DarwinPlatforms = [.macOS, .iOS, .watchOS, .tvOS]
10-
#else
11-
DarwinPlatforms = [.macOS, .iOS, .watchOS, .tvOS, .visionOS]
12-
#endif
7+
let DarwinPlatforms: [Platform] = [.macOS, .iOS, .watchOS, .tvOS, .visionOS]
138

149
let package = Package(
1510
name: "WasmKit",
@@ -120,8 +115,7 @@ let package = Package(
120115

121116
.target(name: "WITExtractor"),
122117
.testTarget(name: "WITExtractorTests", dependencies: ["WITExtractor", "WIT"]),
123-
],
124-
swiftLanguageVersions: [.v5]
118+
]
125119
)
126120

127121
if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {

Sources/WAT/Location.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/// A location in a WAT source file.
2-
public struct Location: Equatable, CustomDebugStringConvertible {
2+
public struct Location: Equatable, CustomDebugStringConvertible, Sendable {
33
let index: Lexer.Index
44
let source: String.UnicodeScalarView
55

Sources/WAT/WAT.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import WasmParser
22

33
/// Options for encoding a WebAssembly module into a binary format.
4-
public struct EncodeOptions {
4+
public struct EncodeOptions: Sendable {
55
/// Whether to include the name section.
66
public var nameSection: Bool
77

Sources/WIT/AST.swift

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ struct Version: Equatable, Hashable, CustomStringConvertible {
3333
}
3434
}
3535

36-
public enum ASTItemSyntax: Equatable, Hashable {
36+
public enum ASTItemSyntax: Equatable, Hashable, Sendable {
3737
case interface(SyntaxNode<InterfaceSyntax>)
3838
case world(SyntaxNode<WorldSyntax>)
3939
case use(SyntaxNode<TopLevelUseSyntax>)
4040
}
4141

42-
public struct PackageNameSyntax: Equatable, Hashable, CustomStringConvertible {
42+
public struct PackageNameSyntax: Equatable, Hashable, CustomStringConvertible, Sendable {
4343
public var namespace: Identifier
4444
public var name: Identifier
4545
var version: Version?
@@ -81,27 +81,27 @@ public struct WorldSyntax: Equatable, Hashable, SyntaxNodeProtocol {
8181
public var items: [WorldItemSyntax]
8282
}
8383

84-
public enum WorldItemSyntax: Equatable, Hashable {
84+
public enum WorldItemSyntax: Equatable, Hashable, Sendable {
8585
case `import`(ImportSyntax)
8686
case export(ExportSyntax)
8787
case use(SyntaxNode<UseSyntax>)
8888
case type(SyntaxNode<TypeDefSyntax>)
8989
case include(IncludeSyntax)
9090
}
9191

92-
public struct ImportSyntax: Equatable, Hashable {
92+
public struct ImportSyntax: Equatable, Hashable, Sendable {
9393
public var documents: DocumentsSyntax
9494
public var attributes: [AttributeSyntax]
9595
public var kind: ExternKindSyntax
9696
}
9797

98-
public struct ExportSyntax: Equatable, Hashable {
98+
public struct ExportSyntax: Equatable, Hashable, Sendable {
9999
public var documents: DocumentsSyntax
100100
public var attributes: [AttributeSyntax]
101101
public var kind: ExternKindSyntax
102102
}
103103

104-
public enum ExternKindSyntax: Equatable, Hashable {
104+
public enum ExternKindSyntax: Equatable, Hashable, Sendable {
105105
case interface(Identifier, [InterfaceItemSyntax])
106106
case path(UsePathSyntax)
107107
case function(Identifier, FunctionSyntax)
@@ -131,7 +131,7 @@ public struct TypeDefSyntax: Equatable, Hashable, SyntaxNodeProtocol {
131131
public var body: TypeDefBodySyntax
132132
}
133133

134-
public enum TypeDefBodySyntax: Equatable, Hashable {
134+
public enum TypeDefBodySyntax: Equatable, Hashable, Sendable {
135135
case flags(FlagsSyntax)
136136
case resource(ResourceSyntax)
137137
case record(RecordSyntax)
@@ -141,11 +141,11 @@ public enum TypeDefBodySyntax: Equatable, Hashable {
141141
case alias(TypeAliasSyntax)
142142
}
143143

144-
public struct TypeAliasSyntax: Equatable, Hashable {
144+
public struct TypeAliasSyntax: Equatable, Hashable, Sendable {
145145
public let typeRepr: TypeReprSyntax
146146
}
147147

148-
public indirect enum TypeReprSyntax: Equatable, Hashable {
148+
public indirect enum TypeReprSyntax: Equatable, Hashable, Sendable {
149149
case bool
150150
case u8
151151
case u16
@@ -169,7 +169,7 @@ public indirect enum TypeReprSyntax: Equatable, Hashable {
169169
case stream(StreamSyntax)
170170
}
171171

172-
public enum HandleSyntax: Equatable, Hashable {
172+
public enum HandleSyntax: Equatable, Hashable, Sendable {
173173
case own(resource: Identifier)
174174
case borrow(resource: Identifier)
175175

@@ -181,65 +181,65 @@ public enum HandleSyntax: Equatable, Hashable {
181181
}
182182
}
183183

184-
public struct ResourceSyntax: Equatable, Hashable {
184+
public struct ResourceSyntax: Equatable, Hashable, Sendable {
185185
var functions: [ResourceFunctionSyntax]
186186
}
187187

188-
public enum ResourceFunctionSyntax: Equatable, Hashable {
188+
public enum ResourceFunctionSyntax: Equatable, Hashable, Sendable {
189189
case method(SyntaxNode<NamedFunctionSyntax>)
190190
case `static`(SyntaxNode<NamedFunctionSyntax>)
191191
case constructor(SyntaxNode<NamedFunctionSyntax>)
192192
}
193193

194-
public struct RecordSyntax: Equatable, Hashable {
194+
public struct RecordSyntax: Equatable, Hashable, Sendable {
195195
public var fields: [FieldSyntax]
196196
}
197197

198-
public struct FieldSyntax: Equatable, Hashable {
198+
public struct FieldSyntax: Equatable, Hashable, Sendable {
199199
public var documents: DocumentsSyntax
200200
public var name: Identifier
201201
public var type: TypeReprSyntax
202202
var textRange: TextRange
203203
}
204204

205-
public struct FlagsSyntax: Equatable, Hashable {
205+
public struct FlagsSyntax: Equatable, Hashable, Sendable {
206206
public var flags: [FlagSyntax]
207207
}
208208

209-
public struct FlagSyntax: Equatable, Hashable {
209+
public struct FlagSyntax: Equatable, Hashable, Sendable {
210210
public var documents: DocumentsSyntax
211211
public var name: Identifier
212212
}
213213

214-
public struct VariantSyntax: Equatable, Hashable {
214+
public struct VariantSyntax: Equatable, Hashable, Sendable {
215215
public var cases: [CaseSyntax]
216216
var textRange: TextRange
217217
}
218218

219-
public struct CaseSyntax: Equatable, Hashable {
219+
public struct CaseSyntax: Equatable, Hashable, Sendable {
220220
public var documents: DocumentsSyntax
221221
public var name: Identifier
222222
public var type: TypeReprSyntax?
223223
var textRange: TextRange
224224
}
225225

226-
public struct EnumSyntax: Equatable, Hashable {
226+
public struct EnumSyntax: Equatable, Hashable, Sendable {
227227
public var cases: [EnumCaseSyntax]
228228
var textRange: TextRange
229229
}
230230

231-
public struct EnumCaseSyntax: Equatable, Hashable {
231+
public struct EnumCaseSyntax: Equatable, Hashable, Sendable {
232232
public var documents: DocumentsSyntax
233233
public var name: Identifier
234234
var textRange: TextRange
235235
}
236236

237-
public struct ResultSyntax: Equatable, Hashable {
237+
public struct ResultSyntax: Equatable, Hashable, Sendable {
238238
public let ok: TypeReprSyntax?
239239
public let error: TypeReprSyntax?
240240
}
241241

242-
public struct StreamSyntax: Equatable, Hashable {
242+
public struct StreamSyntax: Equatable, Hashable, Sendable {
243243
var element: TypeReprSyntax?
244244
var end: TypeReprSyntax?
245245
}
@@ -256,20 +256,20 @@ public struct UnionSyntax: Equatable, Hashable, SyntaxNodeProtocol {
256256
var textRange: TextRange
257257
}
258258

259-
public struct UnionCaseSyntax: Equatable, Hashable {
259+
public struct UnionCaseSyntax: Equatable, Hashable, Sendable {
260260
public var documents: DocumentsSyntax
261261
public var type: TypeReprSyntax
262262
var textRange: TextRange
263263
}
264264

265-
public struct ParameterSyntax: Equatable, Hashable {
265+
public struct ParameterSyntax: Equatable, Hashable, Sendable {
266266
public var name: Identifier
267267
public var type: TypeReprSyntax
268268
var textRange: TextRange
269269
}
270270
public typealias ParameterList = [ParameterSyntax]
271271

272-
public enum ResultListSyntax: Equatable, Hashable {
272+
public enum ResultListSyntax: Equatable, Hashable, Sendable {
273273
case named(ParameterList)
274274
case anon(TypeReprSyntax)
275275

@@ -281,7 +281,7 @@ public enum ResultListSyntax: Equatable, Hashable {
281281
}
282282
}
283283

284-
public struct FunctionSyntax: Equatable, Hashable {
284+
public struct FunctionSyntax: Equatable, Hashable, Sendable {
285285
public var parameters: ParameterList
286286
public var results: ResultListSyntax
287287
var textRange: TextRange
@@ -293,7 +293,7 @@ public struct UseSyntax: Equatable, Hashable, SyntaxNodeProtocol {
293293
public var names: [UseNameSyntax]
294294
}
295295

296-
public enum UsePathSyntax: Equatable, Hashable {
296+
public enum UsePathSyntax: Equatable, Hashable, Sendable {
297297
case id(Identifier)
298298
case package(id: PackageNameSyntax, name: Identifier)
299299

@@ -305,23 +305,23 @@ public enum UsePathSyntax: Equatable, Hashable {
305305
}
306306
}
307307

308-
public struct UseNameSyntax: Equatable, Hashable {
308+
public struct UseNameSyntax: Equatable, Hashable, Sendable {
309309
public var name: Identifier
310310
public var asName: Identifier?
311311
}
312312

313-
public struct IncludeSyntax: Equatable, Hashable {
313+
public struct IncludeSyntax: Equatable, Hashable, Sendable {
314314
var attributes: [AttributeSyntax]
315315
var from: UsePathSyntax
316316
var names: [IncludeNameSyntax]
317317
}
318318

319-
public struct IncludeNameSyntax: Equatable, Hashable {
319+
public struct IncludeNameSyntax: Equatable, Hashable, Sendable {
320320
var name: Identifier
321321
var asName: Identifier
322322
}
323323

324-
public struct Identifier: Equatable, Hashable, CustomStringConvertible {
324+
public struct Identifier: Equatable, Hashable, CustomStringConvertible, Sendable {
325325
public var text: String
326326
var textRange: TextRange
327327

@@ -330,28 +330,28 @@ public struct Identifier: Equatable, Hashable, CustomStringConvertible {
330330
}
331331
}
332332

333-
public struct DocumentsSyntax: Equatable, Hashable {
333+
public struct DocumentsSyntax: Equatable, Hashable, Sendable {
334334
var comments: [String]
335335
}
336336

337-
public enum AttributeSyntax: Equatable, Hashable {
337+
public enum AttributeSyntax: Equatable, Hashable, Sendable {
338338
case since(SinceAttributeSyntax)
339339
case unstable(UnstableAttributeSyntax)
340340
case deprecated(DeprecatedAttributeSyntax)
341341
}
342342

343-
public struct SinceAttributeSyntax: Equatable, Hashable {
343+
public struct SinceAttributeSyntax: Equatable, Hashable, Sendable {
344344
let version: Version
345345
let feature: Identifier?
346346
let textRange: TextRange
347347
}
348348

349-
public struct UnstableAttributeSyntax: Equatable, Hashable {
349+
public struct UnstableAttributeSyntax: Equatable, Hashable, Sendable {
350350
let textRange: TextRange
351351
let feature: Identifier
352352
}
353353

354-
public struct DeprecatedAttributeSyntax: Equatable, Hashable {
354+
public struct DeprecatedAttributeSyntax: Equatable, Hashable, Sendable {
355355
let textRange: TextRange
356356
let version: Version
357357
}

Sources/WIT/Diagnostics.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ struct DiagnosticError: Error {
66
let diagnostic: Diagnostic
77
}
88

9-
public struct Diagnostic {
9+
public struct Diagnostic: Sendable {
1010

1111
public let message: String
1212
var textRange: TextRange?

Sources/WIT/PackageResolver.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Foundation
22

33
/// A unit of WIT package managing a collection of WIT source files
4-
public final class PackageUnit: Hashable, CustomStringConvertible {
4+
public final class PackageUnit: Hashable, CustomStringConvertible, Sendable {
55
public let packageName: PackageNameSyntax
66
public let sourceFiles: [SyntaxNode<SourceFileSyntax>]
77

Sources/WIT/Semantics/RequestEvaluator.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ internal class Evaluator {
3535

3636
// Check cyclical request
3737
if activeRequestsSet.contains(requestAsHashable) {
38-
throw CyclicalRequestError(activeRequests: activeRequests + [request])
38+
throw CyclicalRequestError(activeRequestDescriptions: activeRequests.map { "\($0)" } + ["\(request)"])
3939
}
4040

4141
// Push the given request as an active request
@@ -64,11 +64,11 @@ internal class Evaluator {
6464

6565
extension Evaluator {
6666
struct CyclicalRequestError: Error, CustomStringConvertible {
67-
let activeRequests: [any EvaluationRequest]
67+
let activeRequestDescriptions: [String]
6868

6969
var description: String {
7070
var description = "==== Cycle detected! ====\n"
71-
for (index, request) in activeRequests.enumerated() {
71+
for (index, request) in activeRequestDescriptions.enumerated() {
7272
let indent = String(repeating: " ", count: index)
7373
description += "\(indent)\\- \(request)\n"
7474
}

Sources/WIT/SyntaxNode.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/// An AST node that can be wrapped by ``SyntaxNode`` as a reference
2-
public protocol SyntaxNodeProtocol {}
2+
public protocol SyntaxNodeProtocol: Sendable {}
33

44
/// An AST node with reference semantics to provide identity of a node.
55
@dynamicMemberLookup
6-
public struct SyntaxNode<Syntax: SyntaxNodeProtocol>: Equatable, Hashable {
7-
class Ref {
6+
public struct SyntaxNode<Syntax: SyntaxNodeProtocol>: Equatable, Hashable, Sendable {
7+
final class Ref: Sendable {
88
fileprivate let syntax: Syntax
99
init(syntax: Syntax) {
1010
self.syntax = syntax

Sources/WasmKit/Component/ComponentTypes.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/// Error type raised from Component Model operations
2-
public struct ComponentError<Content>: Error {
2+
public struct ComponentError<Content: Sendable>: Error {
33
/// The content of the error
44
public let content: Content
55

0 commit comments

Comments
 (0)