Skip to content

Commit 7590bea

Browse files
authored
Ran swiftformat . on main. No other changes. (#117)
Motivation: Have main pass the soundness checks. Modifications: `CONTRIBUTING.md` recommends running the `./Utilities/soundness.sh` script before making changes to the project. This script runs the `swiftformat .` command which currently modifies 34 of the files on main with no other changes to the project. Result: Bring main up to formatting requirements specified by `CONTRIBUTING.md`.
1 parent 7d1798e commit 7590bea

34 files changed

+899
-863
lines changed

Sources/AsyncProcess/FileContentStream.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,11 @@ private final class ReadIntoAsyncChannelHandler: ChannelDuplexHandler {
183183
private var shouldRead: Bool {
184184
switch self.state {
185185
case .idle:
186-
return true
186+
true
187187
case .error:
188-
return false
188+
false
189189
case .sending:
190-
return false
190+
false
191191
}
192192
}
193193

Sources/AsyncProcess/ProcessExecutor+Convenience.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,18 @@ public struct OutputLoggingSettings: Sendable {
3737
func logMessage(line: String) -> Logger.Message {
3838
switch self.to {
3939
case .logMessage:
40-
return "\(line)"
40+
"\(line)"
4141
case .metadata(logMessage: let message, key: _):
42-
return message
42+
message
4343
}
4444
}
4545

4646
func metadata(stream: ProcessOutputStream, line: String) -> Logger.Metadata {
4747
switch self.to {
4848
case .logMessage:
49-
return ["stream": "\(stream.description)"]
49+
["stream": "\(stream.description)"]
5050
case .metadata(logMessage: _, let key):
51-
return [key: "\(line)"]
51+
[key: "\(line)"]
5252
}
5353
}
5454
}

Sources/AsyncProcess/ProcessExecutor.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ public struct ProcessOutputStream: Sendable & Hashable & CustomStringConvertible
3333
public var description: String {
3434
switch self.backing {
3535
case .standardOutput:
36-
return "stdout"
36+
"stdout"
3737
case .standardError:
38-
return "stderr"
38+
"stderr"
3939
}
4040
}
4141
}

Sources/GeneratorCLI/GeneratorCLI.swift

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ extension GeneratorCLI {
138138
if let host {
139139
return host
140140
}
141-
let current = try SwiftSDKGenerator.getCurrentTriple(isVerbose: verbose)
141+
let current = try SwiftSDKGenerator.getCurrentTriple(isVerbose: self.verbose)
142142
if let arch = hostArch {
143143
let target = Triple(arch: arch, vendor: current.vendor!, os: current.os!)
144144
print("deprecated: Please use `--host \(target.triple)` instead of `--host-arch \(arch)`")
@@ -198,15 +198,16 @@ extension GeneratorCLI {
198198
}
199199

200200
func run() async throws {
201-
if isInvokedAsDefaultSubcommand() {
202-
print("deprecated: Please explicity specify the subcommand to run. For example: $ swift-sdk-generator make-linux-sdk")
201+
if self.isInvokedAsDefaultSubcommand() {
202+
print(
203+
"deprecated: Please explicity specify the subcommand to run. For example: $ swift-sdk-generator make-linux-sdk"
204+
)
203205
}
204-
let linuxDistributionDefaultVersion: String
205-
switch self.linuxDistributionName {
206+
let linuxDistributionDefaultVersion = switch self.linuxDistributionName {
206207
case .rhel:
207-
linuxDistributionDefaultVersion = "ubi9"
208+
"ubi9"
208209
case .ubuntu:
209-
linuxDistributionDefaultVersion = "22.04"
210+
"22.04"
210211
}
211212
let linuxDistributionVersion = self.linuxDistributionVersion ?? linuxDistributionDefaultVersion
212213
let linuxDistribution = try LinuxDistribution(name: linuxDistributionName, version: linuxDistributionVersion)
@@ -218,14 +219,14 @@ extension GeneratorCLI {
218219
hostTriple: hostTriple,
219220
linuxDistribution: linuxDistribution,
220221
swiftVersion: generatorOptions.swiftVersion,
221-
swiftBranch: generatorOptions.swiftBranch,
222-
lldVersion: lldVersion,
223-
withDocker: withDocker,
224-
fromContainerImage: fromContainerImage,
225-
hostSwiftPackagePath: generatorOptions.hostSwiftPackagePath,
226-
targetSwiftPackagePath: generatorOptions.targetSwiftPackagePath
222+
swiftBranch: self.generatorOptions.swiftBranch,
223+
lldVersion: self.lldVersion,
224+
withDocker: self.withDocker,
225+
fromContainerImage: self.fromContainerImage,
226+
hostSwiftPackagePath: self.generatorOptions.hostSwiftPackagePath,
227+
targetSwiftPackagePath: self.generatorOptions.targetSwiftPackagePath
227228
)
228-
try await GeneratorCLI.run(recipe: recipe, targetTriple: targetTriple, options: generatorOptions)
229+
try await GeneratorCLI.run(recipe: recipe, targetTriple: targetTriple, options: self.generatorOptions)
229230
}
230231

231232
func isInvokedAsDefaultSubcommand() -> Bool {
@@ -270,17 +271,17 @@ extension GeneratorCLI {
270271
guard let targetSwiftPackagePath = generatorOptions.targetSwiftPackagePath else {
271272
throw StringError("Missing expected argument '--target-swift-package-path'")
272273
}
273-
let recipe = WebAssemblyRecipe(
274-
hostSwiftPackage: try generatorOptions.hostSwiftPackagePath.map {
274+
let recipe = try WebAssemblyRecipe(
275+
hostSwiftPackage: generatorOptions.hostSwiftPackagePath.map {
275276
let hostTriple = try self.generatorOptions.deriveHostTriple()
276277
return WebAssemblyRecipe.HostToolchainPackage(path: FilePath($0), triple: hostTriple)
277278
},
278279
targetSwiftPackagePath: FilePath(targetSwiftPackagePath),
279-
wasiSysroot: FilePath(wasiSysroot),
280-
swiftVersion: generatorOptions.swiftVersion
280+
wasiSysroot: FilePath(self.wasiSysroot),
281+
swiftVersion: self.generatorOptions.swiftVersion
281282
)
282283
let targetTriple = self.deriveTargetTriple()
283-
try await GeneratorCLI.run(recipe: recipe, targetTriple: targetTriple, options: generatorOptions)
284+
try await GeneratorCLI.run(recipe: recipe, targetTriple: targetTriple, options: self.generatorOptions)
284285
}
285286
}
286287
}

Sources/GeneratorEngine/Cache/CacheKeyProtocol.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ import struct SystemPackage.FilePath
1616

1717
/// Indicates that values of a conforming type can be hashed with an arbitrary hashing function. Unlike `Hashable`,
1818
/// this protocol doesn't utilize random seed values and produces consistent hash values across process launches.
19-
public protocol CacheKey: Encodable {
20-
}
19+
public protocol CacheKey: Encodable {}
2120

2221
/// Types that cannot be decomposed more to be hashed
2322
protocol LeafCacheKey: CacheKey {

Sources/GeneratorEngine/Cache/SQLite.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,11 @@ public final class SQLite {
135135
var pathString: String {
136136
switch self {
137137
case let .path(path):
138-
return path.string
138+
path.string
139139
case .memory:
140-
return ":memory:"
140+
":memory:"
141141
case .temporary:
142-
return ""
142+
""
143143
}
144144
}
145145
}

Sources/GeneratorEngine/Engine.swift

Lines changed: 88 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -11,108 +11,107 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
@_exported import Crypto
14+
import Helpers
1415
import struct Logging.Logger
1516
@_exported import struct SystemPackage.FilePath
16-
import Helpers
1717

1818
public func withEngine(
19-
_ fileSystem: any FileSystem,
20-
_ logger: Logger,
21-
cacheLocation: SQLite.Location,
22-
_ body: @Sendable (Engine) async throws -> Void
19+
_ fileSystem: any FileSystem,
20+
_ logger: Logger,
21+
cacheLocation: SQLite.Location,
22+
_ body: @Sendable (Engine) async throws -> ()
2323
) async throws {
24-
let engine = Engine(
25-
fileSystem,
26-
logger,
27-
cacheLocation: cacheLocation
28-
)
29-
30-
try await withAsyncThrowing {
31-
try await body(engine)
32-
} defer: {
33-
try await engine.shutDown()
34-
}
24+
let engine = Engine(
25+
fileSystem,
26+
logger,
27+
cacheLocation: cacheLocation
28+
)
29+
30+
try await withAsyncThrowing {
31+
try await body(engine)
32+
} defer: {
33+
try await engine.shutDown()
34+
}
3535
}
3636

3737
/// Cacheable computations engine. Currently the engine makes an assumption that computations produce same results for
3838
/// the same query values and write results to a single file path.
3939
public actor Engine {
40-
private(set) var cacheHits = 0
41-
private(set) var cacheMisses = 0
42-
43-
public let fileSystem: any FileSystem
44-
public let logger: Logger
45-
private let resultsCache: SQLiteBackedCache
46-
private var isShutDown = false
47-
48-
/// Creates a new instance of the ``QueryEngine`` actor. Requires an explicit call
49-
/// to ``QueryEngine//shutdown`` before the instance is deinitialized. The recommended approach to resource
50-
/// management is to place `engine.shutDown()` when the engine is no longer used, but is not deinitialized yet.
51-
/// - Parameter fileSystem: Implementation of a file system this engine should use.
52-
/// - Parameter cacheLocation: Location of cache storage used by the engine.
53-
/// - Parameter logger: Logger to use during queries execution.
54-
init(
55-
_ fileSystem: any FileSystem,
56-
_ logger: Logger,
57-
cacheLocation: SQLite.Location
58-
) {
59-
self.fileSystem = fileSystem
60-
self.logger = logger
61-
self.resultsCache = SQLiteBackedCache(tableName: "cache_table", location: cacheLocation, logger)
62-
}
40+
private(set) var cacheHits = 0
41+
private(set) var cacheMisses = 0
42+
43+
public let fileSystem: any FileSystem
44+
public let logger: Logger
45+
private let resultsCache: SQLiteBackedCache
46+
private var isShutDown = false
47+
48+
/// Creates a new instance of the ``QueryEngine`` actor. Requires an explicit call
49+
/// to ``QueryEngine//shutdown`` before the instance is deinitialized. The recommended approach to resource
50+
/// management is to place `engine.shutDown()` when the engine is no longer used, but is not deinitialized yet.
51+
/// - Parameter fileSystem: Implementation of a file system this engine should use.
52+
/// - Parameter cacheLocation: Location of cache storage used by the engine.
53+
/// - Parameter logger: Logger to use during queries execution.
54+
init(
55+
_ fileSystem: any FileSystem,
56+
_ logger: Logger,
57+
cacheLocation: SQLite.Location
58+
) {
59+
self.fileSystem = fileSystem
60+
self.logger = logger
61+
self.resultsCache = SQLiteBackedCache(tableName: "cache_table", location: cacheLocation, logger)
62+
}
63+
64+
public func shutDown() async throws {
65+
precondition(!self.isShutDown, "`QueryEngine/shutDown` should be called only once")
66+
try self.resultsCache.close()
67+
68+
self.isShutDown = true
69+
}
70+
71+
deinit {
72+
let isShutDown = self.isShutDown
73+
precondition(
74+
isShutDown,
75+
"`QueryEngine/shutDown` should be called explicitly on instances of `Engine` before deinitialization"
76+
)
77+
}
78+
79+
/// Executes a given query if no cached result of it is available. Otherwise fetches the result from engine's cache.
80+
/// - Parameter query: A query value to execute.
81+
/// - Returns: A file path to query's result recorded in a file.
82+
public subscript(_ query: some Query) -> FileCacheRecord {
83+
get async throws {
84+
let hashEncoder = HashEncoder<SHA512>()
85+
try hashEncoder.encode(query.cacheKey)
86+
let key = hashEncoder.finalize()
87+
88+
if let fileRecord = try resultsCache.get(key, as: FileCacheRecord.self) {
89+
let fileHash = try await self.fileSystem.withOpenReadableFile(fileRecord.path) {
90+
var hashFunction = SHA512()
91+
try await $0.hash(with: &hashFunction)
92+
return hashFunction.finalize().description
93+
}
94+
95+
if fileHash == fileRecord.hash {
96+
self.cacheHits += 1
97+
return fileRecord
98+
}
99+
}
63100

64-
public func shutDown() async throws {
65-
precondition(!self.isShutDown, "`QueryEngine/shutDown` should be called only once")
66-
try self.resultsCache.close()
101+
self.cacheMisses += 1
102+
let resultPath = try await query.run(engine: self)
67103

68-
self.isShutDown = true
69-
}
104+
let resultHash = try await self.fileSystem.withOpenReadableFile(resultPath) {
105+
var hashFunction = SHA512()
106+
try await $0.hash(with: &hashFunction)
107+
return hashFunction.finalize().description
108+
}
109+
let result = FileCacheRecord(path: resultPath, hash: resultHash)
70110

71-
deinit {
72-
let isShutDown = self.isShutDown
73-
precondition(
74-
isShutDown,
75-
"`QueryEngine/shutDown` should be called explicitly on instances of `Engine` before deinitialization"
76-
)
77-
}
111+
// FIXME: update `SQLiteBackedCache` to store `resultHash` directly instead of relying on string conversions
112+
try self.resultsCache.set(key, to: result)
78113

79-
/// Executes a given query if no cached result of it is available. Otherwise fetches the result from engine's cache.
80-
/// - Parameter query: A query value to execute.
81-
/// - Returns: A file path to query's result recorded in a file.
82-
public subscript(_ query: some Query) -> FileCacheRecord {
83-
get async throws {
84-
let hashEncoder = HashEncoder<SHA512>()
85-
try hashEncoder.encode(query.cacheKey)
86-
let key = hashEncoder.finalize()
87-
88-
if let fileRecord = try resultsCache.get(key, as: FileCacheRecord.self) {
89-
90-
let fileHash = try await self.fileSystem.withOpenReadableFile(fileRecord.path) {
91-
var hashFunction = SHA512()
92-
try await $0.hash(with: &hashFunction)
93-
return hashFunction.finalize().description
94-
}
95-
96-
if fileHash == fileRecord.hash {
97-
self.cacheHits += 1
98-
return fileRecord
99-
}
100-
}
101-
102-
self.cacheMisses += 1
103-
let resultPath = try await query.run(engine: self)
104-
105-
let resultHash = try await self.fileSystem.withOpenReadableFile(resultPath) {
106-
var hashFunction = SHA512()
107-
try await $0.hash(with: &hashFunction)
108-
return hashFunction.finalize().description
109-
}
110-
let result = FileCacheRecord(path: resultPath, hash: resultHash)
111-
112-
// FIXME: update `SQLiteBackedCache` to store `resultHash` directly instead of relying on string conversions
113-
try self.resultsCache.set(key, to: result)
114-
115-
return result
116-
}
114+
return result
117115
}
116+
}
118117
}

Sources/GeneratorEngine/FileSystem/FileSystem.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ enum FileSystemError: Error {
2828
extension Error {
2929
func attach(path: FilePath) -> any Error {
3030
if let error = self as? Errno {
31-
return FileSystemError.systemError(path, error)
31+
FileSystemError.systemError(path, error)
3232
} else {
33-
return self
33+
self
3434
}
3535
}
3636
}

Sources/GeneratorEngine/FileSystem/OpenReadableFile.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ public struct OpenReadableFile {
2525
func read() async throws -> ReadableFileStream {
2626
switch self.fileHandle {
2727
case let .local(fileDescriptor):
28-
return ReadableFileStream.local(.init(fileDescriptor: fileDescriptor, readChunkSize: self.readChunkSize))
28+
ReadableFileStream.local(.init(fileDescriptor: fileDescriptor, readChunkSize: self.readChunkSize))
2929
case let .virtual(array):
30-
return ReadableFileStream.virtual(.init(bytes: array))
30+
ReadableFileStream.virtual(.init(bytes: array))
3131
}
3232
}
3333

Sources/GeneratorEngine/FileSystem/ReadableFileStream.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,19 @@ public enum ReadableFileStream: AsyncSequence {
2525
public func next() async throws -> [UInt8]? {
2626
switch self {
2727
case let .local(local):
28-
return try await local.next()
28+
try await local.next()
2929
case let .virtual(virtual):
30-
return try await virtual.next()
30+
try await virtual.next()
3131
}
3232
}
3333
}
3434

3535
public func makeAsyncIterator() -> Iterator {
3636
switch self {
3737
case let .local(local):
38-
return .local(local.makeAsyncIterator())
38+
.local(local.makeAsyncIterator())
3939
case let .virtual(virtual):
40-
return .virtual(virtual.makeAsyncIterator())
40+
.virtual(virtual.makeAsyncIterator())
4141
}
4242
}
4343
}

0 commit comments

Comments
 (0)