diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml index 28c6ce29..888bd19f 100644 --- a/.github/workflows/format.yml +++ b/.github/workflows/format.yml @@ -9,10 +9,10 @@ jobs: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true container: - image: swift:6.0.1-jammy + image: swift:6.2-noble steps: - uses: actions/checkout@v4 - - run: ./Utilities/format.py + - run: apt-get update && apt-get install -y python3 && ./Utilities/format.py - name: Check for formatting changes run: | git config --global --add safe.directory "$GITHUB_WORKSPACE" diff --git a/Sources/WASI/WASI.swift b/Sources/WASI/WASI.swift index 41035b8b..1e4896e5 100644 --- a/Sources/WASI/WASI.swift +++ b/Sources/WASI/WASI.swift @@ -1494,7 +1494,7 @@ public class WASIBridgeToHost: WASI { } func fd_advise(fd: WASIAbi.Fd, offset: WASIAbi.FileSize, length: WASIAbi.FileSize, advice: WASIAbi.Advice) throws { - guard case let .file(fileEntry) = fdTable[fd] else { + guard case .file(let fileEntry) = fdTable[fd] else { throw WASIAbi.Errno.EBADF } try fileEntry.advise(offset: offset, length: length, advice: advice) @@ -1518,7 +1518,7 @@ public class WASIBridgeToHost: WASI { } func fd_datasync(fd: WASIAbi.Fd) throws { - guard case let .file(fileEntry) = fdTable[fd] else { + guard case .file(let fileEntry) = fdTable[fd] else { throw WASIAbi.Errno.EBADF } return try fileEntry.datasync() @@ -1527,7 +1527,7 @@ public class WASIBridgeToHost: WASI { func fd_fdstat_get(fileDescriptor: UInt32) throws -> WASIAbi.FdStat { let entry = self.fdTable[fileDescriptor] switch entry { - case let .file(entry): + case .file(let entry): return try entry.fdStat() case .directory: return WASIAbi.FdStat( @@ -1542,7 +1542,7 @@ public class WASIBridgeToHost: WASI { } func fd_fdstat_set_flags(fd: WASIAbi.Fd, flags: WASIAbi.Fdflags) throws { - guard case let .file(fileEntry) = fdTable[fd] else { + guard case .file(let fileEntry) = fdTable[fd] else { throw WASIAbi.Errno.EBADF } try fileEntry.setFdStatFlags(flags) @@ -1564,7 +1564,7 @@ public class WASIBridgeToHost: WASI { } func fd_filestat_set_size(fd: WASIAbi.Fd, size: WASIAbi.FileSize) throws { - guard case let .file(entry) = fdTable[fd] else { + guard case .file(let entry) = fdTable[fd] else { throw WASIAbi.Errno.EBADF } return try entry.setFilestatSize(size) @@ -1584,14 +1584,14 @@ public class WASIBridgeToHost: WASI { fd: WASIAbi.Fd, iovs: UnsafeGuestBufferPointer, offset: WASIAbi.FileSize ) throws -> WASIAbi.Size { - guard case let .file(fileEntry) = fdTable[fd] else { + guard case .file(let fileEntry) = fdTable[fd] else { throw WASIAbi.Errno.EBADF } return try fileEntry.pread(into: iovs, offset: offset) } func fd_prestat_get(fd: WASIAbi.Fd) throws -> WASIAbi.Prestat { - guard case let .directory(entry) = fdTable[fd], + guard case .directory(let entry) = fdTable[fd], let preopenPath = entry.preopenPath else { throw WASIAbi.Errno.EBADF @@ -1600,7 +1600,7 @@ public class WASIBridgeToHost: WASI { } func fd_prestat_dir_name(fd: WASIAbi.Fd, path: UnsafeGuestPointer, maxPathLength: WASIAbi.Size) throws { - guard case let .directory(entry) = fdTable[fd], + guard case .directory(let entry) = fdTable[fd], var preopenPath = entry.preopenPath else { throw WASIAbi.Errno.EBADF @@ -1620,7 +1620,7 @@ public class WASIBridgeToHost: WASI { fd: WASIAbi.Fd, iovs: UnsafeGuestBufferPointer, offset: WASIAbi.FileSize ) throws -> WASIAbi.Size { - guard case let .file(fileEntry) = fdTable[fd] else { + guard case .file(let fileEntry) = fdTable[fd] else { throw WASIAbi.Errno.EBADF } return try fileEntry.pwrite(vectored: iovs, offset: offset) @@ -1630,7 +1630,7 @@ public class WASIBridgeToHost: WASI { fd: WASIAbi.Fd, iovs: UnsafeGuestBufferPointer ) throws -> WASIAbi.Size { - guard case let .file(fileEntry) = fdTable[fd] else { + guard case .file(let fileEntry) = fdTable[fd] else { throw WASIAbi.Errno.EBADF } return try fileEntry.read(into: iovs) @@ -1641,7 +1641,7 @@ public class WASIBridgeToHost: WASI { buffer: UnsafeGuestBufferPointer, cookie: WASIAbi.DirCookie ) throws -> WASIAbi.Size { - guard case let .directory(dirEntry) = fdTable[fd] else { + guard case .directory(let dirEntry) = fdTable[fd] else { throw WASIAbi.Errno.EBADF } @@ -1693,21 +1693,21 @@ public class WASIBridgeToHost: WASI { } func fd_seek(fd: WASIAbi.Fd, offset: WASIAbi.FileDelta, whence: WASIAbi.Whence) throws -> WASIAbi.FileSize { - guard case let .file(fileEntry) = fdTable[fd] else { + guard case .file(let fileEntry) = fdTable[fd] else { throw WASIAbi.Errno.EBADF } return try fileEntry.seek(offset: offset, whence: whence) } func fd_sync(fd: WASIAbi.Fd) throws { - guard case let .file(fileEntry) = fdTable[fd] else { + guard case .file(let fileEntry) = fdTable[fd] else { throw WASIAbi.Errno.EBADF } return try fileEntry.sync() } func fd_tell(fd: WASIAbi.Fd) throws -> WASIAbi.FileSize { - guard case let .file(fileEntry) = fdTable[fd] else { + guard case .file(let fileEntry) = fdTable[fd] else { throw WASIAbi.Errno.EBADF } return try fileEntry.tell() @@ -1717,14 +1717,14 @@ public class WASIBridgeToHost: WASI { fileDescriptor: WASIAbi.Fd, ioVectors: UnsafeGuestBufferPointer ) throws -> UInt32 { - guard case let .file(entry) = self.fdTable[fileDescriptor] else { + guard case .file(let entry) = self.fdTable[fileDescriptor] else { throw WASIAbi.Errno.EBADF } return try entry.write(vectored: ioVectors) } func path_create_directory(dirFd: WASIAbi.Fd, path: String) throws { - guard case let .directory(dirEntry) = fdTable[dirFd] else { + guard case .directory(let dirEntry) = fdTable[dirFd] else { throw WASIAbi.Errno.ENOTDIR } try dirEntry.createDirectory(atPath: path) @@ -1733,7 +1733,7 @@ public class WASIBridgeToHost: WASI { func path_filestat_get( dirFd: WASIAbi.Fd, flags: WASIAbi.LookupFlags, path: String ) throws -> WASIAbi.Filestat { - guard case let .directory(dirEntry) = fdTable[dirFd] else { + guard case .directory(let dirEntry) = fdTable[dirFd] else { throw WASIAbi.Errno.ENOTDIR } return try dirEntry.attributes( @@ -1746,7 +1746,7 @@ public class WASIBridgeToHost: WASI { path: String, atim: WASIAbi.Timestamp, mtim: WASIAbi.Timestamp, fstFlags: WASIAbi.FstFlags ) throws { - guard case let .directory(dirEntry) = fdTable[dirFd] else { + guard case .directory(let dirEntry) = fdTable[dirFd] else { throw WASIAbi.Errno.ENOTDIR } try dirEntry.setFilestatTimes( @@ -1775,7 +1775,7 @@ public class WASIBridgeToHost: WASI { #if os(Windows) throw WASIAbi.Errno.ENOTSUP #else - guard case let .directory(dirEntry) = fdTable[dirFd] else { + guard case .directory(let dirEntry) = fdTable[dirFd] else { throw WASIAbi.Errno.ENOTDIR } var accessMode: FileAccessMode = [] @@ -1814,7 +1814,7 @@ public class WASIBridgeToHost: WASI { } func path_remove_directory(dirFd: WASIAbi.Fd, path: String) throws { - guard case let .directory(dirEntry) = fdTable[dirFd] else { + guard case .directory(let dirEntry) = fdTable[dirFd] else { throw WASIAbi.Errno.ENOTDIR } try dirEntry.removeDirectory(atPath: path) @@ -1824,24 +1824,24 @@ public class WASIBridgeToHost: WASI { oldFd: WASIAbi.Fd, oldPath: String, newFd: WASIAbi.Fd, newPath: String ) throws { - guard case let .directory(oldDirEntry) = fdTable[oldFd] else { + guard case .directory(let oldDirEntry) = fdTable[oldFd] else { throw WASIAbi.Errno.ENOTDIR } - guard case let .directory(newDirEntry) = fdTable[newFd] else { + guard case .directory(let newDirEntry) = fdTable[newFd] else { throw WASIAbi.Errno.ENOTDIR } try oldDirEntry.rename(from: oldPath, toDir: newDirEntry, to: newPath) } func path_symlink(oldPath: String, dirFd: WASIAbi.Fd, newPath: String) throws { - guard case let .directory(dirEntry) = fdTable[dirFd] else { + guard case .directory(let dirEntry) = fdTable[dirFd] else { throw WASIAbi.Errno.ENOTDIR } try dirEntry.symlink(from: oldPath, to: newPath) } func path_unlink_file(dirFd: WASIAbi.Fd, path: String) throws { - guard case let .directory(dirEntry) = fdTable[dirFd] else { + guard case .directory(let dirEntry) = fdTable[dirFd] else { throw WASIAbi.Errno.ENOTDIR } try dirEntry.removeFile(atPath: path) diff --git a/Sources/WAT/Encoder.swift b/Sources/WAT/Encoder.swift index 0f0829cc..52b90740 100644 --- a/Sources/WAT/Encoder.swift +++ b/Sources/WAT/Encoder.swift @@ -244,7 +244,7 @@ extension WAT.WatParser.ElementDecl { if let tableIndex = tableIndex { encoder.writeUnsignedLEB128(tableIndex) } - if case let .active(_, offset) = self.mode { + if case .active(_, let offset) = self.mode { switch offset { case .expression(var lexer): try encoder.writeExpression(lexer: &lexer, wat: &wat) @@ -288,7 +288,7 @@ extension WAT.WatParser.ElementDecl { } } else { encoder.encodeVector(collector.instructions) { instruction, encoder in - guard case let .refFunc(funcIndex) = instruction else { fatalError("non-ref.func instruction in non-expression mode") } + guard case .refFunc(let funcIndex) = instruction else { fatalError("non-ref.func instruction in non-expression mode") } encoder.writeUnsignedLEB128(funcIndex) } } @@ -325,7 +325,7 @@ extension Export: WasmEncodable { extension WatParser.GlobalDecl { func encode(to encoder: inout Encoder, wat: inout Wat) throws { encoder.encode(type) - guard case var .definition(expr) = kind else { + guard case .definition(var expr) = kind else { fatalError("imported global declaration should not be encoded here") } try encoder.writeExpression(lexer: &expr, wat: &wat) @@ -539,7 +539,7 @@ func encode(module: inout Wat, options: EncodeOptions) throws -> [UInt8] { var codeEncoder = Encoder() let functions = module.functionsMap.compactMap { (function: WatParser.FunctionDecl) -> ([WatParser.LocalDecl], WatParser.FunctionDecl)? in - guard case let .definition(locals, _) = function.kind else { + guard case .definition(let locals, _) = function.kind else { return nil } return (locals, function) diff --git a/Sources/WAT/NameMapping.swift b/Sources/WAT/NameMapping.swift index ab7f019b..ea553687 100644 --- a/Sources/WAT/NameMapping.swift +++ b/Sources/WAT/NameMapping.swift @@ -169,7 +169,7 @@ struct TypesMap { /// Resolves a block type from a type use mutating func resolveBlockType(use: WatParser.TypeUse) throws -> BlockType { switch (use.index, use.inline) { - case let (indexOrId?, inline): + case (let indexOrId?, let inline): let (type, index) = try resolveAndCheck(use: indexOrId, inline: inline) return try resolveBlockType(signature: type.signature, resolveSignatureIndex: { _ in index }) case (nil, let inline?): @@ -180,7 +180,7 @@ struct TypesMap { mutating func resolveIndex(use: WatParser.TypeUse) throws -> Int { switch (use.index, use.inline) { - case let (indexOrId?, _): + case (let indexOrId?, _): return try nameMapping.resolveIndex(use: indexOrId) case (nil, let inline): let inline = inline?.signature ?? WasmTypes.FunctionType(parameters: [], results: []) @@ -208,7 +208,7 @@ struct TypesMap { /// Resolves a function type from a type use with an optional inline type mutating func resolve(use: WatParser.TypeUse) throws -> (type: WatParser.FunctionType, index: Int) { switch (use.index, use.inline) { - case let (indexOrId?, inline): + case (let indexOrId?, let inline): return try resolveAndCheck(use: indexOrId, inline: inline) case (nil, let inline): // If no index and no inline type, then it's a function type with no parameters or results diff --git a/Sources/WAT/Parser.swift b/Sources/WAT/Parser.swift index a016413d..6e45fe0c 100644 --- a/Sources/WAT/Parser.swift +++ b/Sources/WAT/Parser.swift @@ -53,7 +53,7 @@ internal struct Parser { mutating func takeUnsignedInt(_: IntegerType.Type = IntegerType.self) throws -> IntegerType? { guard let token = try peek() else { return nil } - guard case let .integer(nil, pattern) = token.kind else { + guard case .integer(nil, let pattern) = token.kind else { return nil } try consume() @@ -75,7 +75,7 @@ internal struct Parser { fromBitPattern: (UnsignedType) -> IntegerType ) throws -> IntegerType? { guard let token = try peek() else { return nil } - guard case let .integer(sign, pattern) = token.kind else { + guard case .integer(let sign, let pattern) = token.kind else { return nil } try consume() @@ -213,7 +213,7 @@ internal struct Parser { return value } switch token.kind { - case let .float(sign, pattern): + case .float(let sign, let pattern): let float: F switch pattern { case .decimalPattern(let pattern): @@ -232,7 +232,7 @@ internal struct Parser { return bitPattern } return toBitPattern(sign == .minus ? -float : float) - case let .integer(sign, pattern): + case .integer(let sign, let pattern): let float: F switch pattern { case .hexPattern(let pattern): diff --git a/Sources/WAT/Parser/WatParser.swift b/Sources/WAT/Parser/WatParser.swift index 530494a4..5efaa36e 100644 --- a/Sources/WAT/Parser/WatParser.swift +++ b/Sources/WAT/Parser/WatParser.swift @@ -81,7 +81,7 @@ struct WatParser { /// /// - Returns: Type index of this function func parse(visitor: inout V, wat: inout Wat, features: WasmFeatureSet) throws -> Int { - guard case let .definition(locals, body) = kind else { + guard case .definition(let locals, let body) = kind else { fatalError("Imported functions cannot be parsed") } let (type, typeIndex) = try wat.types.resolve(use: typeUse) diff --git a/Sources/WAT/WAT.swift b/Sources/WAT/WAT.swift index 707f7161..9d7c1650 100644 --- a/Sources/WAT/WAT.swift +++ b/Sources/WAT/WAT.swift @@ -219,9 +219,9 @@ func parseWAT(_ parser: inout Parser, features: WasmFeatureSet) throws -> Wat { } switch decl.kind { - case let .type(decl): + case .type(let decl): try typesMap.add(decl) - case let .function(decl): + case .function(let decl): try checkImportOrder(decl.importNames) let index = try functionsMap.add(decl) addExports(decl.exports, index: index, kind: .function) @@ -233,7 +233,7 @@ func parseWAT(_ parser: inout Parser, features: WasmFeatureSet) throws -> Wat { return .function(TypeIndex(typeIndex)) } } - case let .table(decl): + case .table(let decl): try checkImportOrder(decl.importNames) let index = try tablesMap.add(decl) addExports(decl.exports, index: index, kind: .table) @@ -246,7 +246,7 @@ func parseWAT(_ parser: inout Parser, features: WasmFeatureSet) throws -> Wat { if let importNames = decl.importNames { addImport(importNames) { .table(decl.type) } } - case let .memory(decl): + case .memory(let decl): try checkImportOrder(decl.importNames) let index = try memoriesMap.add(decl) if var inlineData = decl.inlineData { @@ -259,7 +259,7 @@ func parseWAT(_ parser: inout Parser, features: WasmFeatureSet) throws -> Wat { if let importNames = decl.importNames { addImport(importNames) { .memory(decl.type) } } - case let .global(decl): + case .global(let decl): try checkImportOrder(decl.importNames) let index = try globalsMap.add(decl) addExports(decl.exports, index: index, kind: .global) @@ -268,13 +268,13 @@ func parseWAT(_ parser: inout Parser, features: WasmFeatureSet) throws -> Wat { case .imported(let importNames): addImport(importNames) { .global(decl.type) } } - case let .element(decl): + case .element(let decl): try elementSegmentsMap.add(decl) - case let .export(decl): + case .export(let decl): exportDecls.append(decl) - case let .data(decl): + case .data(let decl): try dataSegmentsMap.add(decl) - case let .start(startIndex): + case .start(let startIndex): guard start == nil else { throw WatParserError("Multiple start sections", location: location) } diff --git a/Sources/WIT/Semantics/NameLookup.swift b/Sources/WIT/Semantics/NameLookup.swift index b48a1a2e..ab7d4bfa 100644 --- a/Sources/WIT/Semantics/NameLookup.swift +++ b/Sources/WIT/Semantics/NameLookup.swift @@ -150,7 +150,7 @@ struct LookupInterfaceInPackageRequest: EvaluationRequest { sourceFile: SyntaxNode ) { for sourceFile in packageUnit.sourceFiles { - for case let .interface(iface) in sourceFile.items { + for case .interface(let iface) in sourceFile.items { if iface.name.text == name { return (iface, sourceFile) } } } @@ -210,7 +210,7 @@ struct LookupLocalInterfaceRequest: EvaluationRequest { sourceFile: SyntaxNode ) { if let sourceFile { - for case let .use(use) in sourceFile.items { + for case .use(let use) in sourceFile.items { let found: Bool if let asName = use.asName { found = name == asName.text @@ -231,7 +231,7 @@ struct LookupLocalInterfaceRequest: EvaluationRequest { } } for sourceFile in packageUnit.sourceFiles { - for case let .interface(iface) in sourceFile.items { + for case .interface(let iface) in sourceFile.items { if iface.name.text == name { return (iface, sourceFile) } } } diff --git a/Sources/WITExtractor/SourceSummary.swift b/Sources/WITExtractor/SourceSummary.swift index fa866c96..cde90a47 100644 --- a/Sources/WITExtractor/SourceSummary.swift +++ b/Sources/WITExtractor/SourceSummary.swift @@ -100,7 +100,7 @@ struct SourceSummaryBuilder { // Ignore static fields if let isStatic = declChild.body.static, isStatic { continue } - guard case let .typeNominal(fieldTypeNode) = child.body.children?.first else { + guard case .typeNominal(let fieldTypeNode) = child.body.children?.first else { diagnostics.add( .warning("Skipping \(node.parent.printedName)/\(child.body.printedName) field due to missing nominal type child node") ) @@ -141,7 +141,7 @@ struct SourceSummaryBuilder { // If the result is not TypeFunc, it has no payload return nil } - guard case let .typeNominal(payloadTupleType) = resultType.children?.last else { + guard case .typeNominal(let payloadTupleType) = resultType.children?.last else { return nil } return payloadTupleType @@ -178,13 +178,13 @@ struct SourceSummaryBuilder { let witName = ConvertCase.witIdentifier(identifier: node.parent.name) var results: [SwiftFunctionSource.Parameter] = [] - if case let .typeNominal(resultNode) = node.parent.children?.first { + if case .typeNominal(let resultNode) = node.parent.children?.first { // If returns a tuple, it's a function that returns multiple values. if resultNode.parent.parent.name == "Tuple" { let tupleElements = resultNode.parent.parent.children ?? [] for elementNode in tupleElements { - guard case let .typeNominal(resultNominalNode) = elementNode else { + guard case .typeNominal(let resultNominalNode) = elementNode else { diagnostics.add( .warning("Skipping \(node.parent.printedName)'s result due to missing nominal type child node") ) diff --git a/Sources/WITExtractor/TypeMapping.swift b/Sources/WITExtractor/TypeMapping.swift index 41a031bc..1b4c9beb 100644 --- a/Sources/WITExtractor/TypeMapping.swift +++ b/Sources/WITExtractor/TypeMapping.swift @@ -81,7 +81,7 @@ struct TypeMapping { func genericParameters() -> some Collection { let children = node.parent.parent.children ?? [] return children.lazy.compactMap { child in - guard case let .typeNominal(typeNode) = child else { + guard case .typeNominal(let typeNode) = child else { diagnostics.add(.warning("Missing generic parameter type node for \(node.parent.parent.printedName)")) return nil } @@ -139,7 +139,7 @@ struct TypeMapping { var cleanup: (inout TypeMapping) -> Void = { _ in } defer { cleanup(&self) } - if case let .typeDecl(typeDecl) = node { + if case .typeDecl(let typeDecl) = node { collect(node: typeDecl.parent) declScope.append(typeDecl.parent) cleanup = { diff --git a/Sources/WITOverlayGenerator/DefinitionMapping.swift b/Sources/WITOverlayGenerator/DefinitionMapping.swift index 7c9701bd..3c6aad59 100644 --- a/Sources/WITOverlayGenerator/DefinitionMapping.swift +++ b/Sources/WITOverlayGenerator/DefinitionMapping.swift @@ -85,7 +85,7 @@ private func deriveQualifiedSwiftName( parent: TypeDefinitionContext, name: String ) throws -> String { switch parent { - case let .interface(id, .package(packageName)): + case .interface(let id, .package(let packageName)): return try typeNamespace(packageName: packageName, interface: id) + "." + ConvertCase.pascalCase(kebab: name) case .interface(let id, parent: .world): return id.text + ConvertCase.pascalCase(kebab: name) diff --git a/Sources/WITTool/WITTool.swift b/Sources/WITTool/WITTool.swift index 91ab69a7..d0c4c7b1 100644 --- a/Sources/WITTool/WITTool.swift +++ b/Sources/WITTool/WITTool.swift @@ -178,7 +178,7 @@ struct SwiftSourceSummaryProvider: SourceSummaryProvider { let typeMapping: (String) -> String? func enumCaseNames(byWITName witName: String) -> [String]? { - guard case let .enumType(enumType) = summary.lookupType(byWITName: witName) else { + guard case .enumType(let enumType) = summary.lookupType(byWITName: witName) else { return nil } return enumType.cases.map(\.name) diff --git a/Sources/WasmKit/Component/CanonicalCall.swift b/Sources/WasmKit/Component/CanonicalCall.swift index 847a44d8..0ec01af7 100644 --- a/Sources/WasmKit/Component/CanonicalCall.swift +++ b/Sources/WasmKit/Component/CanonicalCall.swift @@ -46,7 +46,7 @@ public struct CanonicalCallContext { guard results.count == 1 else { throw CanonicalABIError(description: "\"cabi_realloc\" export should return a single value") } - guard case let .i32(new) = results[0] else { + guard case .i32(let new) = results[0] else { throw CanonicalABIError(description: "\"cabi_realloc\" export should return an i32 value") } return UnsafeGuestRawPointer(memorySpace: guestMemory, offset: new) diff --git a/Sources/WasmKit/Component/CanonicalOptions.swift b/Sources/WasmKit/Component/CanonicalOptions.swift index de9a562f..6aeda40c 100644 --- a/Sources/WasmKit/Component/CanonicalOptions.swift +++ b/Sources/WasmKit/Component/CanonicalOptions.swift @@ -36,7 +36,7 @@ public struct CanonicalOptions { /// in an encoded component at componetizing-time. (e.g. wit-component tool is one of the componetizers) /// Remove this temporary method after we will accept binary form of component file. public static func _derive(from instance: Instance, exportName: String) -> CanonicalOptions { - guard case let .memory(memory) = instance.exports["memory"] else { + guard case .memory(let memory) = instance.exports["memory"] else { fatalError("Missing required \"memory\" export") } return CanonicalOptions( diff --git a/Sources/WasmKit/Execution/ConstEvaluation.swift b/Sources/WasmKit/Execution/ConstEvaluation.swift index 3f155e6b..10a45b89 100644 --- a/Sources/WasmKit/Execution/ConstEvaluation.swift +++ b/Sources/WasmKit/Execution/ConstEvaluation.swift @@ -85,7 +85,7 @@ extension WasmParser.ElementSegment { context: C, expression: ConstExpression ) throws -> Reference { switch expression[0] { - case let .refFunc(index): + case .refFunc(let index): return try context.functionRef(index) case .refNull(.funcRef): return .function(nil) diff --git a/Sources/WasmKit/Execution/Errors.swift b/Sources/WasmKit/Execution/Errors.swift index 884901b7..08bd4273 100644 --- a/Sources/WasmKit/Execution/Errors.swift +++ b/Sources/WasmKit/Execution/Errors.swift @@ -107,7 +107,7 @@ enum TrapReason: Error, CustomStringConvertible { return "integer overflow" case .invalidConversionToInteger: return "invalid conversion to integer" - case let .indirectCallToNull(elementIndex): + case .indirectCallToNull(let elementIndex): return "indirect call to null element (uninitialized element \(elementIndex))" case .typeMismatchCall(let actual, let expected): return "indirect call type mismatch, expected \(expected), got \(actual)" diff --git a/Sources/WasmKit/Execution/Function.swift b/Sources/WasmKit/Execution/Function.swift index 52fc06f2..52676fae 100644 --- a/Sources/WasmKit/Execution/Function.swift +++ b/Sources/WasmKit/Execution/Function.swift @@ -215,7 +215,7 @@ extension InternalFunction { function: EntityHandle ) { let entity = self.wasm - guard case let .compiled(iseq) = entity.code else { + guard case .compiled(let iseq) = entity.code else { preconditionFailure() } return (iseq, entity.numberOfNonParameterLocals, entity) diff --git a/Sources/WasmKit/Execution/Instructions/Control.swift b/Sources/WasmKit/Execution/Instructions/Control.swift index 47dbbb49..2eff6ae4 100644 --- a/Sources/WasmKit/Execution/Instructions/Control.swift +++ b/Sources/WasmKit/Execution/Instructions/Control.swift @@ -121,7 +121,7 @@ extension Execution { guard elementIndex < table.elements.count else { throw Trap(.tableOutOfBounds(elementIndex)) } - guard case let .function(rawBitPattern?) = table.elements[elementIndex] + guard case .function(let rawBitPattern?) = table.elements[elementIndex] else { throw Trap(.indirectCallToNull(elementIndex)) } diff --git a/Sources/WasmKit/Execution/Runtime.swift b/Sources/WasmKit/Execution/Runtime.swift index dcdeda47..75e16ab4 100644 --- a/Sources/WasmKit/Execution/Runtime.swift +++ b/Sources/WasmKit/Execution/Runtime.swift @@ -129,7 +129,7 @@ public final class Runtime { /// ``` @available(*, deprecated, message: "Use `Instance.export` and `Global.value` instead") public func getGlobal(_ instance: Instance, globalName: String) throws -> Value { - guard case let .global(global) = instance.export(globalName) else { + guard case .global(let global) = instance.export(globalName) else { throw Trap(.noGlobalExportWithName(globalName: globalName, instance: instance)) } return global.value @@ -137,7 +137,7 @@ public final class Runtime { /// Invokes a function in a given module instance. public func invoke(_ instance: Instance, function: String, with arguments: [Value] = []) throws -> [Value] { - guard case let .function(function)? = instance.export(function) else { + guard case .function(let function)? = instance.export(function) else { throw Trap(.exportedFunctionNotFound(name: function, instance: instance)) } return try function.invoke(arguments) diff --git a/Sources/WasmKit/Execution/StoreAllocator.swift b/Sources/WasmKit/Execution/StoreAllocator.swift index 812ed5b3..f060dc56 100644 --- a/Sources/WasmKit/Execution/StoreAllocator.swift +++ b/Sources/WasmKit/Execution/StoreAllocator.swift @@ -272,7 +272,7 @@ extension StoreAllocator { } switch (importEntry.descriptor, external) { - case let (.function(typeIndex), .function(externalFunc)): + case (.function(let typeIndex), .function(let externalFunc)): let type = externalFunc.type guard typeIndex < module.types.count else { throw ValidationError(.indexOutOfBounds("type", typeIndex, max: module.types.count)) @@ -284,19 +284,19 @@ extension StoreAllocator { } importedFunctions.append(externalFunc) - case let (.table(tableType), .table(table)): + case (.table(let tableType), .table(let table)): if let max = table.limits.max, max < tableType.limits.min { throw ImportError(.incompatibleTableType(importEntry, actual: tableType, expected: table.tableType)) } importedTables.append(table) - case let (.memory(memoryType), .memory(memory)): + case (.memory(let memoryType), .memory(let memory)): if let max = memory.limit.max, max < memoryType.min { throw ImportError(.incompatibleMemoryType(importEntry, actual: memoryType, expected: memory.limit)) } importedMemories.append(memory) - case let (.global(globalType), .global(global)): + case (.global(let globalType), .global(let global)): guard globalType == global.globalType else { throw ImportError(.incompatibleGlobalType(importEntry, actual: global.globalType, expected: globalType)) } @@ -402,7 +402,7 @@ extension StoreAllocator { for (index, datum) in module.data.enumerated() { let segment: InternalDataSegment switch datum { - case let .passive(bytes): + case .passive(let bytes): segment = allocate(bytes: bytes) case .active: // Active segments are copied into memories while instantiation @@ -416,16 +416,16 @@ extension StoreAllocator { func createExportValue(_ export: WasmParser.Export) throws -> InternalExternalValue { switch export.descriptor { - case let .function(index): + case .function(let index): let handle = try functions[validating: Int(index)] return .function(handle) - case let .table(index): + case .table(let index): let handle = try tables[validating: Int(index)] return .table(handle) - case let .memory(index): + case .memory(let index): let handle = try memories[validating: Int(index)] return .memory(handle) - case let .global(index): + case .global(let index): let handle = try globals[validating: Int(index)] return .global(handle) } diff --git a/Sources/WasmKit/Module.swift b/Sources/WasmKit/Module.swift index 55603fc1..30070d1a 100644 --- a/Sources/WasmKit/Module.swift +++ b/Sources/WasmKit/Module.swift @@ -166,7 +166,7 @@ public struct Module { // Steps 14-15. for element in elements { - guard case let .active(tableIndex, offset) = element.mode else { continue } + guard case .active(let tableIndex, let offset) = element.mode else { continue } let table = try instance.tables[validating: Int(tableIndex)] let offsetValue = try offset.evaluate( context: constEvalContext, @@ -194,7 +194,7 @@ public struct Module { } // Step 16. - for case let .active(data) in data { + for case .active(let data) in data { let memory = try instance.memories[validating: Int(data.index)] let offsetValue = try data.offset.evaluate( context: constEvalContext, diff --git a/Sources/WasmKit/Translator.swift b/Sources/WasmKit/Translator.swift index 7e6ed95a..071eb85c 100644 --- a/Sources/WasmKit/Translator.swift +++ b/Sources/WasmKit/Translator.swift @@ -684,9 +684,9 @@ struct InstructionTranslator: InstructionVisitor { self.unpinnedLabels.remove(ref) for user in users { switch user.action { - case let .emitInstruction(insertAt, source, make): + case .emitInstruction(let insertAt, let source, let make): assign(at: insertAt.offsetFromHead, make(self, source, pc)) - case let .fillBrTableEntry(brTable, index, make): + case .fillBrTableEntry(let brTable, let index, let make): brTable[index] = make(self, pc) } } @@ -705,13 +705,14 @@ struct InstructionTranslator: InstructionVisitor { _ makeInstruction: @escaping (Immediate) -> Instruction, _ ref: LabelRef, line: UInt = #line, - make: @escaping ( - ISeqBuilder, - // The position of the next slot of the creating instruction - _ source: MetaProgramCounter, - // The position of the resolved label - _ target: MetaProgramCounter - ) -> (Immediate) + make: + @escaping ( + ISeqBuilder, + // The position of the next slot of the creating instruction + _ source: MetaProgramCounter, + // The position of the resolved label + _ target: MetaProgramCounter + ) -> (Immediate) ) { let insertAt = insertingPC @@ -1182,7 +1183,7 @@ struct InstructionTranslator: InstructionVisitor { mutating func visitElse() throws -> Output { var frame = try controlStack.currentFrame() - guard case let .if(elseLabel, endLabel, _) = frame.kind else { + guard case .if(let elseLabel, let endLabel, _) = frame.kind else { throw ValidationError(.expectedIfControlFrame) } preserveOnStack(depth: valueStack.height - frame.stackHeight) @@ -1575,7 +1576,7 @@ struct InstructionTranslator: InstructionVisitor { switch (value1Type, value2Type) { case (.some(.ref(_)), _), (_, .some(.ref(_))): throw ValidationError(.cannotSelectOnReferenceTypes) - case let (.some(type1), .some(type2)): + case (.some(let type1), .some(let type2)): guard type1 == type2 else { throw ValidationError(.typeMismatchOnSelect(expected: type1, actual: type2)) } @@ -1731,10 +1732,11 @@ struct InstructionTranslator: InstructionVisitor { private mutating func pop2PushEmit( _ pops: (ValueType, ValueType), _ push: ValueType, - _ instruction: @escaping ( - _ popped: (VReg, VReg), - _ result: VReg - ) -> Instruction + _ instruction: + @escaping ( + _ popped: (VReg, VReg), + _ result: VReg + ) -> Instruction ) throws { guard let pop1 = try popVRegOperand(pops.0), let pop2 = try popVRegOperand(pops.1) @@ -2256,7 +2258,7 @@ extension FunctionType { self.init(parameters: [], results: [valueType]) case .empty: self.init(parameters: [], results: []) - case let .funcType(typeIndex): + case .funcType(let typeIndex): let typeIndex = Int(typeIndex) guard typeIndex < typeSection.count else { throw ValidationError(.indexOutOfBounds("type", typeIndex, max: typeSection.count)) diff --git a/Sources/WasmKitWASI/WASIBridgeToHost+WasmKit.swift b/Sources/WasmKitWASI/WASIBridgeToHost+WasmKit.swift index f5470276..23e364ee 100644 --- a/Sources/WasmKitWASI/WASIBridgeToHost+WasmKit.swift +++ b/Sources/WasmKitWASI/WASIBridgeToHost+WasmKit.swift @@ -34,7 +34,7 @@ extension WASIBridgeToHost { private func makeHostFunction(_ function: WASIHostFunction) -> ((Caller, [Value]) throws -> [Value]) { { caller, values -> [Value] in - guard case let .memory(memory) = caller.instance?.export("memory") else { + guard case .memory(let memory) = caller.instance?.export("memory") else { throw WASIError(description: "Missing required \"memory\" export") } return try function.implementation(memory, values) diff --git a/Sources/WasmParser/WasmParser.swift b/Sources/WasmParser/WasmParser.swift index 2f8374b2..501aaad4 100644 --- a/Sources/WasmParser/WasmParser.swift +++ b/Sources/WasmParser/WasmParser.swift @@ -373,7 +373,7 @@ extension ByteStream { var decoder = UTF8() Decode: while true { switch decoder.decode(&iterator) { - case let .scalarValue(scalar): name.append(Character(scalar)) + case .scalarValue(let scalar): name.append(Character(scalar)) case .emptyInput: break Decode case .error: throw WasmParserError(.invalidUTF8(bytes), offset: currentIndex) } @@ -681,7 +681,7 @@ extension Parser: BinaryInstructionDecoder { } @inlinable mutating func visitRefNull() throws -> WasmTypes.ReferenceType { let type = try parseValueType() - guard case let .ref(refType) = type else { + guard case .ref(let refType) = type else { throw makeError(.expectedRefType(actual: type)) } return refType @@ -924,7 +924,7 @@ extension Parser { if flag.segmentHasRefType { let valueType = try parseValueType() - guard case let .ref(refType) = valueType else { + guard case .ref(let refType) = valueType else { throw makeError(.expectedRefType(actual: valueType)) } diff --git a/Sources/WasmTypes/WasmTypes.swift b/Sources/WasmTypes/WasmTypes.swift index e3e1e589..054e901c 100644 --- a/Sources/WasmTypes/WasmTypes.swift +++ b/Sources/WasmTypes/WasmTypes.swift @@ -98,28 +98,28 @@ extension Value { /// Returns the value as a 32-bit signed integer. /// - Precondition: The value is of type `i32`. public var i32: UInt32 { - guard case let .i32(result) = self else { fatalError() } + guard case .i32(let result) = self else { fatalError() } return result } /// Returns the value as a 64-bit signed integer. /// - Precondition: The value is of type `i64`. public var i64: UInt64 { - guard case let .i64(result) = self else { fatalError() } + guard case .i64(let result) = self else { fatalError() } return result } /// Returns the value as a 32-bit floating-point number. /// - Precondition: The value is of type `f32`. public var f32: UInt32 { - guard case let .f32(result) = self else { fatalError() } + guard case .f32(let result) = self else { fatalError() } return result } /// Returns the value as a 64-bit floating-point number. /// - Precondition: The value is of type `f64`. public var f64: UInt64 { - guard case let .f64(result) = self else { fatalError() } + guard case .f64(let result) = self else { fatalError() } return result } } diff --git a/Tests/WASITests/Platform/SandboxPrimitives/OpenParentTests.swift b/Tests/WASITests/Platform/SandboxPrimitives/OpenParentTests.swift index 220dc609..2b68cc01 100644 --- a/Tests/WASITests/Platform/SandboxPrimitives/OpenParentTests.swift +++ b/Tests/WASITests/Platform/SandboxPrimitives/OpenParentTests.swift @@ -15,7 +15,7 @@ ) { switch (lhs, rhs) { case (.none, .none): return - case let (.some(lhs), .some(rhs)): + case (.some(let lhs), .some(let rhs)): #expect(lhs.0 == rhs.0, sourceLocation: sourceLocation) #expect(lhs.1 == rhs.1, sourceLocation: sourceLocation) default: diff --git a/Tests/WATTests/ParserTests.swift b/Tests/WATTests/ParserTests.swift index a6498bb2..cd60676d 100644 --- a/Tests/WATTests/ParserTests.swift +++ b/Tests/WATTests/ParserTests.swift @@ -18,7 +18,7 @@ func parseModule(_ source: String) throws -> ModuleDirective? { let directives = try parseWast(source) - guard case let .module(moduleDirective) = directives.first else { + guard case .module(let moduleDirective) = directives.first else { #expect((false), "Expected module directive") return nil } @@ -27,7 +27,7 @@ func parseBinaryModule(_ source: String) throws -> (source: [UInt8], id: String?)? { guard let module = try parseModule(source) else { return nil } - guard case let .binary(content) = module.source else { return nil } + guard case .binary(let content) = module.source else { return nil } return (content, module.id) } @@ -101,8 +101,8 @@ """#) #expect(directives.count == 2) - guard case let .module(directive) = try #require(directives.last), - case let .binary(content) = directive.source + guard case .module(let directive) = try #require(directives.last), + case .binary(let content) = directive.source else { return } @@ -135,7 +135,7 @@ """ let wast = try parseWast(source) #expect(wast.count == 5) - guard case let .module(module) = wast.first, case var .text(wat) = module.source else { + guard case .module(let module) = wast.first, case .text(var wat) = module.source else { #expect((false), "expect a module directive") return } diff --git a/Tests/WITOverlayGeneratorTests/Runtime/RuntimeTypesTests.swift b/Tests/WITOverlayGeneratorTests/Runtime/RuntimeTypesTests.swift index 5f6fe490..b927bc7e 100644 --- a/Tests/WITOverlayGeneratorTests/Runtime/RuntimeTypesTests.swift +++ b/Tests/WITOverlayGeneratorTests/Runtime/RuntimeTypesTests.swift @@ -162,7 +162,7 @@ class RuntimeTypesTests: XCTestCase { XCTAssertEqual(try component.returnSingle(), .a(33_550_336)) let value1 = try component.returnLarge() - guard case let .c256(value1) = value1 else { + guard case .c256(let value1) = value1 else { XCTFail("unexpected variant case \(value1)") return } @@ -175,7 +175,7 @@ class RuntimeTypesTests: XCTestCase { } let value3 = try component.roundtripLarge(v: .c256(24)) - guard case let .c256(value3) = value3 else { + guard case .c256(let value3) = value3 else { XCTFail("unexpected variant case \(value3)") return } @@ -291,7 +291,7 @@ class RuntimeTypesTests: XCTestCase { extension VariantTestWorld.Single: Equatable { static func == (lhs: VariantTestWorld.Single, rhs: VariantTestWorld.Single) -> Bool { switch (lhs, rhs) { - case let (.a(lhs), .a(rhs)): return lhs == rhs + case (.a(let lhs), .a(let rhs)): return lhs == rhs } } } diff --git a/Tests/WITTests/Semantics/NameLookupTests.swift b/Tests/WITTests/Semantics/NameLookupTests.swift index fa2ba223..15ce598c 100644 --- a/Tests/WITTests/Semantics/NameLookupTests.swift +++ b/Tests/WITTests/Semantics/NameLookupTests.swift @@ -91,7 +91,7 @@ class NameLookupTests: XCTestCase { interfaceName: "x", typeName: "my-type" ) - guard case let .record(record) = type else { + guard case .record(let record) = type else { XCTFail("expected record but got \(type)") return } @@ -115,7 +115,7 @@ class NameLookupTests: XCTestCase { interfaceName: "x", typeName: "my-type" ) - guard case let .record(record) = type else { + guard case .record(let record) = type else { XCTFail("expected record but got \(type)") return } @@ -147,7 +147,7 @@ class NameLookupTests: XCTestCase { ], namespace: "foo", package: "root", interfaceName: "x", typeName: "my-type" ) - guard case let .record(record) = type else { + guard case .record(let record) = type else { XCTFail("expected record but got \(type)") return } @@ -180,7 +180,7 @@ class NameLookupTests: XCTestCase { ], namespace: "foo", package: "root", interfaceName: "x", typeName: "my-type" ) - guard case let .record(record) = type else { + guard case .record(let record) = type else { XCTFail("expected record but got \(type)") return } @@ -273,11 +273,11 @@ class NameLookupTests: XCTestCase { default: return nil } }.first) - guard case let .import(importItem) = try XCTUnwrap(world.items.first) else { + guard case .import(let importItem) = try XCTUnwrap(world.items.first) else { XCTFail("expected import item but got \(String(describing: world.items.first))") return } - guard case let .interface(name, items) = importItem.kind else { + guard case .interface(let name, let items) = importItem.kind else { XCTFail("expected inline interface but got \(importItem.kind)") return } diff --git a/Tests/WITTests/TextParser/ParseInterfaceTests.swift b/Tests/WITTests/TextParser/ParseInterfaceTests.swift index 9dcb7ceb..700e2527 100644 --- a/Tests/WITTests/TextParser/ParseInterfaceTests.swift +++ b/Tests/WITTests/TextParser/ParseInterfaceTests.swift @@ -43,7 +43,7 @@ class ParseInterfaceTests: XCTestCase { XCTAssertEqual(iface.name.text, "x") XCTAssertEqual(iface.items.count, 1) let item = iface.items[0] - guard case let .function(function) = item else { + guard case .function(let function) = item else { XCTFail("unexpected item type: \(item)") return } @@ -64,7 +64,7 @@ class ParseInterfaceTests: XCTestCase { ) XCTAssertEqual(iface.items.count, 1) let item = iface.items[0] - guard case let .typeDef(typeDef) = item else { + guard case .typeDef(let typeDef) = item else { XCTFail("unexpected item type: \(item)") return } @@ -83,7 +83,7 @@ class ParseInterfaceTests: XCTestCase { ) XCTAssertEqual(iface.items.count, 1) let item = iface.items[0] - guard case let .typeDef(typeDef) = item else { + guard case .typeDef(let typeDef) = item else { XCTFail("unexpected item type: \(item)") return } @@ -102,7 +102,7 @@ class ParseInterfaceTests: XCTestCase { ) XCTAssertEqual(iface.items.count, 1) let item = iface.items[0] - guard case let .typeDef(typeDef) = item else { + guard case .typeDef(let typeDef) = item else { XCTFail("unexpected item type: \(item)") return } @@ -121,7 +121,7 @@ class ParseInterfaceTests: XCTestCase { ) XCTAssertEqual(iface.items.count, 1) let item = iface.items[0] - guard case let .typeDef(typeDef) = item else { + guard case .typeDef(let typeDef) = item else { XCTFail("unexpected item type: \(item)") return } @@ -138,7 +138,7 @@ class ParseInterfaceTests: XCTestCase { ) XCTAssertEqual(iface.items.count, 1) let item = iface.items[0] - guard case let .typeDef(typeDef) = item else { + guard case .typeDef(let typeDef) = item else { XCTFail("unexpected item type: \(item)") return } @@ -157,7 +157,7 @@ class ParseInterfaceTests: XCTestCase { ) XCTAssertEqual(iface.items.count, 1) let item = iface.items[0] - guard case let .typeDef(typeDef) = item else { + guard case .typeDef(let typeDef) = item else { XCTFail("unexpected item type: \(item)") return } @@ -177,7 +177,7 @@ class ParseInterfaceTests: XCTestCase { ) XCTAssertEqual(iface.items.count, 1) let item = iface.items[0] - guard case let .typeDef(typeDef) = item else { + guard case .typeDef(let typeDef) = item else { XCTFail("unexpected item type: \(item)") return } @@ -194,7 +194,7 @@ class ParseInterfaceTests: XCTestCase { ) XCTAssertEqual(iface.items.count, 1) let item = iface.items[0] - guard case let .function(function) = item else { + guard case .function(let function) = item else { XCTFail("unexpected item type: \(item)") return } @@ -211,7 +211,7 @@ class ParseInterfaceTests: XCTestCase { ) XCTAssertEqual(iface.items.count, 1) let item = iface.items[0] - guard case let .use(use) = item else { + guard case .use(let use) = item else { XCTFail("unexpected item type: \(item)") return } diff --git a/Tests/WITTests/TextParser/ParseTopTests.swift b/Tests/WITTests/TextParser/ParseTopTests.swift index b6642e4f..12a76afb 100644 --- a/Tests/WITTests/TextParser/ParseTopTests.swift +++ b/Tests/WITTests/TextParser/ParseTopTests.swift @@ -134,7 +134,7 @@ class ParseTopTests: XCTestCase { var lexer = Lexer(cursor: .init(input: "use ns1:pkg1/item1@1.0.0")) let use = try TopLevelUseSyntax.parse(lexer: &lexer, documents: .init(comments: []), attributes: []) XCTAssertEqual(use.item.name.text, "item1") - guard case let .package(id, _) = use.item else { + guard case .package(let id, _) = use.item else { XCTFail("expected package but got \(use.item)") return } @@ -156,7 +156,7 @@ class ParseTopTests: XCTestCase { return } do { - guard case let .since(attribute) = attributes[0] else { + guard case .since(let attribute) = attributes[0] else { XCTFail("expected since but got \(attributes[0])") return } @@ -164,7 +164,7 @@ class ParseTopTests: XCTestCase { XCTAssertEqual(attribute.feature?.text, nil) } do { - guard case let .since(attribute) = attributes[1] else { + guard case .since(let attribute) = attributes[1] else { XCTFail("expected since but got \(attributes[1])") return } @@ -177,7 +177,7 @@ class ParseTopTests: XCTestCase { var lexer = Lexer(cursor: .init(input: "@unstable(feature = foo)")) let attributes = try AttributeSyntax.parseItems(lexer: &lexer) XCTAssertEqual(attributes.count, 1) - guard case let .unstable(attribute) = attributes.first else { + guard case .unstable(let attribute) = attributes.first else { XCTFail("expected since but got \(attributes)") return } @@ -188,7 +188,7 @@ class ParseTopTests: XCTestCase { var lexer = Lexer(cursor: .init(input: "@deprecated(version = 1.0.3)")) let attributes = try AttributeSyntax.parseItems(lexer: &lexer) XCTAssertEqual(attributes.count, 1) - guard case let .deprecated(attribute) = attributes.first else { + guard case .deprecated(let attribute) = attributes.first else { XCTFail("expected since but got \(attributes)") return } diff --git a/Tests/WITTests/TextParser/ParseTypesTests.swift b/Tests/WITTests/TextParser/ParseTypesTests.swift index e8b2272a..4dbd8de7 100644 --- a/Tests/WITTests/TextParser/ParseTypesTests.swift +++ b/Tests/WITTests/TextParser/ParseTypesTests.swift @@ -74,7 +74,7 @@ class ParseTestsTests: XCTestCase { ) let typeDef = try TypeDefSyntax.parseResource(lexer: &lexer, documents: .init(comments: []), attributes: []) XCTAssertEqual(typeDef.name.text, "r1") - guard case let .resource(resource) = typeDef.body else { + guard case .resource(let resource) = typeDef.body else { XCTFail("unexpected type kind: \(typeDef.body)") return } @@ -95,7 +95,7 @@ class ParseTestsTests: XCTestCase { ) let typeDef = try TypeDefSyntax.parseVariant(lexer: &lexer, documents: .init(comments: []), attributes: []) XCTAssertEqual(typeDef.name.text, "r1") - guard case let .variant(variant) = typeDef.body else { + guard case .variant(let variant) = typeDef.body else { XCTFail("unexpected type kind: \(typeDef.body)") return } diff --git a/Tests/WITTests/TextParser/ParseWorldTests.swift b/Tests/WITTests/TextParser/ParseWorldTests.swift index 689345c8..10ab0654 100644 --- a/Tests/WITTests/TextParser/ParseWorldTests.swift +++ b/Tests/WITTests/TextParser/ParseWorldTests.swift @@ -44,7 +44,7 @@ final class ParseWorldTests: XCTestCase { XCTAssertEqual(world.name.text, "x") XCTAssertEqual(world.items.count, 1) let item = world.items[0] - guard case let .type(typeDef) = item else { + guard case .type(let typeDef) = item else { XCTFail("unexpected item type: \(item)") return } @@ -68,11 +68,11 @@ final class ParseWorldTests: XCTestCase { XCTAssertEqual(world.items.count, 3) do { let item = world.items[0] - guard case let .import(importItem) = item else { + guard case .import(let importItem) = item else { XCTFail("unexpected item type: \(item)") return } - guard case let .function(name, _) = importItem.kind else { + guard case .function(let name, _) = importItem.kind else { XCTFail("unexpected import type: \(importItem.kind)") return } @@ -81,11 +81,11 @@ final class ParseWorldTests: XCTestCase { do { let item = world.items[1] - guard case let .import(importItem) = item else { + guard case .import(let importItem) = item else { XCTFail("unexpected item type: \(item)") return } - guard case let .interface(name, iface) = importItem.kind else { + guard case .interface(let name, let iface) = importItem.kind else { XCTFail("unexpected import type: \(importItem.kind)") return } @@ -95,11 +95,11 @@ final class ParseWorldTests: XCTestCase { do { let item = world.items[2] - guard case let .import(importItem) = item else { + guard case .import(let importItem) = item else { XCTFail("unexpected item type: \(item)") return } - guard case let .path(path) = importItem.kind else { + guard case .path(let path) = importItem.kind else { XCTFail("unexpected import type: \(importItem.kind)") return } @@ -117,11 +117,11 @@ final class ParseWorldTests: XCTestCase { ) XCTAssertEqual(world.items.count, 1) let item = world.items[0] - guard case let .export(export) = item else { + guard case .export(let export) = item else { XCTFail("unexpected item type: \(item)") return } - guard case let .function(name, _) = export.kind else { + guard case .function(let name, _) = export.kind else { XCTFail("unexpected export type: \(export.kind)") return } @@ -141,7 +141,7 @@ final class ParseWorldTests: XCTestCase { XCTAssertEqual(world.items.count, 3) do { let item = world.items[0] - guard case let .include(include) = item else { + guard case .include(let include) = item else { XCTFail("unexpected item type: \(item)") return } @@ -151,7 +151,7 @@ final class ParseWorldTests: XCTestCase { do { let item = world.items[1] - guard case let .include(include) = item else { + guard case .include(let include) = item else { XCTFail("unexpected item type: \(item)") return } @@ -164,7 +164,7 @@ final class ParseWorldTests: XCTestCase { do { let item = world.items[2] - guard case let .include(include) = item else { + guard case .include(let include) = item else { XCTFail("unexpected item type: \(item)") return } @@ -188,7 +188,7 @@ final class ParseWorldTests: XCTestCase { ) XCTAssertEqual(world.items.count, 1) let item = world.items[0] - guard case let .type(typeDef) = item else { + guard case .type(let typeDef) = item else { XCTFail("unexpected item type: \(item)") return } @@ -207,7 +207,7 @@ final class ParseWorldTests: XCTestCase { ) XCTAssertEqual(world.items.count, 1) let item = world.items[0] - guard case let .type(typeDef) = item else { + guard case .type(let typeDef) = item else { XCTFail("unexpected item type: \(item)") return } @@ -226,7 +226,7 @@ final class ParseWorldTests: XCTestCase { ) XCTAssertEqual(world.items.count, 1) let item = world.items[0] - guard case let .type(typeDef) = item else { + guard case .type(let typeDef) = item else { XCTFail("unexpected item type: \(item)") return } @@ -245,7 +245,7 @@ final class ParseWorldTests: XCTestCase { ) XCTAssertEqual(world.items.count, 1) let item = world.items[0] - guard case let .type(typeDef) = item else { + guard case .type(let typeDef) = item else { XCTFail("unexpected item type: \(item)") return } @@ -262,7 +262,7 @@ final class ParseWorldTests: XCTestCase { ) XCTAssertEqual(world.items.count, 1) let item = world.items[0] - guard case let .type(typeDef) = item else { + guard case .type(let typeDef) = item else { XCTFail("unexpected item type: \(item)") return } @@ -281,7 +281,7 @@ final class ParseWorldTests: XCTestCase { ) XCTAssertEqual(world.items.count, 1) let item = world.items[0] - guard case let .type(typeDef) = item else { + guard case .type(let typeDef) = item else { XCTFail("unexpected item type: \(item)") return } @@ -301,7 +301,7 @@ final class ParseWorldTests: XCTestCase { ) XCTAssertEqual(world.items.count, 1) let item = world.items[0] - guard case let .type(typeDef) = item else { + guard case .type(let typeDef) = item else { XCTFail("unexpected item type: \(item)") return } @@ -318,7 +318,7 @@ final class ParseWorldTests: XCTestCase { ) XCTAssertEqual(world.items.count, 1) let item = world.items[0] - guard case let .use(use) = item else { + guard case .use(let use) = item else { XCTFail("unexpected item type: \(item)") return } diff --git a/Tests/WasmKitTests/Spectest/TestCase.swift b/Tests/WasmKitTests/Spectest/TestCase.swift index 37c35578..195c1a23 100644 --- a/Tests/WasmKitTests/Spectest/TestCase.swift +++ b/Tests/WasmKitTests/Spectest/TestCase.swift @@ -331,7 +331,7 @@ extension WastRunContext { return try wastInvoke(call: invoke) case .get(let module, let globalName): let instance = try deriveInstance(by: module) - guard case let .global(global) = instance.export(globalName) else { + guard case .global(let global) = instance.export(globalName) else { throw SpectestError("no global export with name \(globalName) in a module instance \(instance)") } return [global.value] @@ -396,21 +396,21 @@ extension WastRunContext { extension Value { func isTestEquivalent(to value: Self) -> Bool { switch (self, value) { - case let (.i32(lhs), .i32(rhs)): + case (.i32(let lhs), .i32(let rhs)): return lhs == rhs - case let (.i64(lhs), .i64(rhs)): + case (.i64(let lhs), .i64(let rhs)): return lhs == rhs - case let (.f32(lhs), .f32(rhs)): + case (.f32(let lhs), .f32(let rhs)): let lhs = Float32(bitPattern: lhs) let rhs = Float32(bitPattern: rhs) return lhs.isNaN && rhs.isNaN || lhs == rhs - case let (.f64(lhs), .f64(rhs)): + case (.f64(let lhs), .f64(let rhs)): let lhs = Float64(bitPattern: lhs) let rhs = Float64(bitPattern: rhs) return lhs.isNaN && rhs.isNaN || lhs == rhs - case let (.ref(.extern(lhs)), .ref(.extern(rhs))): + case (.ref(.extern(let lhs)), .ref(.extern(let rhs))): return lhs == rhs - case let (.ref(.function(lhs)), .ref(.function(rhs))): + case (.ref(.function(let lhs)), .ref(.function(let rhs))): return lhs == rhs default: return false diff --git a/Utilities/format.py b/Utilities/format.py index 8add96cb..eb5b9c4e 100755 --- a/Utilities/format.py +++ b/Utilities/format.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 +import argparse import subprocess import os @@ -11,22 +12,28 @@ def run(arguments): subprocess.run(arguments, check=True) -def build_swift_format(): +def build_swift_format() -> list[str]: # Build swift-format package_path = os.path.join(SOURCE_ROOT, "Vendor", "swift-format") bin_path = os.path.join(package_path, ".build", "release", "swift-format") if os.path.exists(bin_path): - return bin_path + return [bin_path] run(["./Vendor/checkout-dependency", "swift-format"]) run([ "swift", "build", "-c", "release", "--package-path", package_path]) - return bin_path + return [bin_path] def main(): + parser = argparse.ArgumentParser( + prog='WasmKit codebase formatter', + description='Ensures that codebase formatting is consistent') + parser.add_argument('-b', '--build-swift-format', action='store_true') + args = parser.parse_args() + targets = [] for targets_dir in ["Sources", "Tests"]: targets_path = os.path.join(SOURCE_ROOT, targets_dir) @@ -40,10 +47,13 @@ def main(): # swift-format. targets.remove(os.path.join("Sources", "SystemExtras")) - swift_format = build_swift_format() + if args.build_swift_format: + swift_format = build_swift_format() + else: + swift_format = ["swift", "format"] - arguments = [ - swift_format, "format", "--in-place", "--recursive", "--parallel" + arguments = swift_format + [ + "format", "--in-place", "--recursive", "--parallel" ] for target in targets: arguments.append(os.path.join(SOURCE_ROOT, target)) diff --git a/Vendor/dependencies.json b/Vendor/dependencies.json index 5c20310b..c5047053 100644 --- a/Vendor/dependencies.json +++ b/Vendor/dependencies.json @@ -16,7 +16,7 @@ }, "swift-format": { "repository": "https://github.com/swiftlang/swift-format.git", - "revision": "c7a8b752e35d96577d1e9191d27cd9ea57dce2f2", + "revision": "62eaad2822b865407b8cde56c36386c00800f7ec", "categories": ["default"] }, "wish-you-were-fast": {