Skip to content
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
4 changes: 2 additions & 2 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
48 changes: 24 additions & 24 deletions Sources/WASI/WASI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Expand All @@ -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(
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -1584,14 +1584,14 @@ public class WASIBridgeToHost: WASI {
fd: WASIAbi.Fd, iovs: UnsafeGuestBufferPointer<WASIAbi.IOVec>,
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
Expand All @@ -1600,7 +1600,7 @@ public class WASIBridgeToHost: WASI {
}

func fd_prestat_dir_name(fd: WASIAbi.Fd, path: UnsafeGuestPointer<UInt8>, 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
Expand All @@ -1620,7 +1620,7 @@ public class WASIBridgeToHost: WASI {
fd: WASIAbi.Fd, iovs: UnsafeGuestBufferPointer<WASIAbi.IOVec>,
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)
Expand All @@ -1630,7 +1630,7 @@ public class WASIBridgeToHost: WASI {
fd: WASIAbi.Fd,
iovs: UnsafeGuestBufferPointer<WASIAbi.IOVec>
) 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)
Expand All @@ -1641,7 +1641,7 @@ public class WASIBridgeToHost: WASI {
buffer: UnsafeGuestBufferPointer<UInt8>,
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
}

Expand Down Expand Up @@ -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()
Expand All @@ -1717,14 +1717,14 @@ public class WASIBridgeToHost: WASI {
fileDescriptor: WASIAbi.Fd,
ioVectors: UnsafeGuestBufferPointer<WASIAbi.IOVec>
) 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)
Expand All @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -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 = []
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions Sources/WAT/Encoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions Sources/WAT/NameMapping.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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?):
Expand All @@ -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: [])
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions Sources/WAT/Parser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ internal struct Parser {

mutating func takeUnsignedInt<IntegerType: UnsignedInteger & FixedWidthInteger>(_: 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()
Expand All @@ -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()
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion Sources/WAT/Parser/WatParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ struct WatParser {
///
/// - Returns: Type index of this function
func parse<V: InstructionVisitor>(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)
Expand Down
18 changes: 9 additions & 9 deletions Sources/WAT/WAT.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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 {
Expand All @@ -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)
Expand All @@ -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)
}
Expand Down
Loading