Skip to content

Commit

Permalink
Soundness formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterAdams-A committed Jun 10, 2024
1 parent b6b18af commit 059542f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
15 changes: 8 additions & 7 deletions Sources/Logging/Logging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ public enum LoggingSystem {
/// - parameters:
/// - factory: A closure that given a `Logger` identifier, produces an instance of the `LogHandler`.
@preconcurrency
public static func bootstrap(_ factory: @escaping @Sendable (String) -> any LogHandler) {
public static func bootstrap(_ factory: @escaping @Sendable(String) -> any LogHandler) {
self._factory.replace({ label, _ in
factory(label)
}, validate: true)
Expand All @@ -534,22 +534,22 @@ public enum LoggingSystem {
/// - metadataProvider: The `MetadataProvider` used to inject runtime-generated metadata from the execution context.
/// - factory: A closure that given a `Logger` identifier, produces an instance of the `LogHandler`.
@preconcurrency
public static func bootstrap(_ factory: @escaping @Sendable (String, Logger.MetadataProvider?) -> any LogHandler,
public static func bootstrap(_ factory: @escaping @Sendable(String, Logger.MetadataProvider?) -> any LogHandler,
metadataProvider: Logger.MetadataProvider?) {
self._metadataProviderFactory.replace(metadataProvider, validate: true)
self._factory.replace(factory, validate: true)
}

// for our testing we want to allow multiple bootstrapping
internal static func bootstrapInternal(_ factory: @escaping @Sendable (String) -> any LogHandler) {
internal static func bootstrapInternal(_ factory: @escaping @Sendable(String) -> any LogHandler) {
self._metadataProviderFactory.replace(nil, validate: false)
self._factory.replace({ label, _ in
factory(label)
}, validate: false)
}

// for our testing we want to allow multiple bootstrapping
internal static func bootstrapInternal(_ factory: @escaping @Sendable (String, Logger.MetadataProvider?) -> any LogHandler,
internal static func bootstrapInternal(_ factory: @escaping @Sendable(String, Logger.MetadataProvider?) -> any LogHandler,
metadataProvider: Logger.MetadataProvider?) {
self._metadataProviderFactory.replace(metadataProvider, validate: false)
self._factory.replace(factory, validate: false)
Expand Down Expand Up @@ -594,13 +594,13 @@ public enum LoggingSystem {

func withReadLock<Result>(_ operation: (Value) -> Result) -> Result {
self.lock.withReaderLock {
return operation(self.storage)
operation(self.storage)
}
}

func withWriteLock<Result>(_ operation: (inout Value) -> Result) -> Result {
self.lock.withWriterLock {
return operation(&self.storage)
operation(&self.storage)
}
}
}
Expand Down Expand Up @@ -645,7 +645,7 @@ public enum LoggingSystem {
}
}

private typealias FactoryBox = ReplaceOnceBox<@Sendable (_ label: String, _ provider: Logger.MetadataProvider?) -> any LogHandler>
private typealias FactoryBox = ReplaceOnceBox< @Sendable(_ label: String, _ provider: Logger.MetadataProvider?) -> any LogHandler>

private typealias MetadataProviderBox = ReplaceOnceBox<Logger.MetadataProvider?>
}
Expand Down Expand Up @@ -1103,6 +1103,7 @@ internal struct StdioOutputStream: TextOutputStream, @unchecked Sendable {
#endif
return StdioOutputStream(file: systemStderr, flushMode: .always)
}()

internal static let stdout = {
// Prevent name clashes
#if canImport(Darwin)
Expand Down
10 changes: 5 additions & 5 deletions Tests/LoggingTests/LoggingTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import WinSDK
import Glibc
#endif

fileprivate extension LogHandler {
private extension LogHandler {
func with(logLevel: Logger.Level) -> any LogHandler {
var result = self
result.logLevel = logLevel
Expand Down Expand Up @@ -711,7 +711,7 @@ class LoggingTest: XCTestCase {
private let lock = Lock()
private var storage: Value

init(initialValue: Value) {
init(initialValue: Value) {
self.storage = initialValue
}

Expand All @@ -721,15 +721,15 @@ class LoggingTest: XCTestCase {
}
}

func withLockMutating(_ operation: (inout Value) -> Void) -> Void {
func withLockMutating(_ operation: (inout Value) -> Void) {
self.lock.withLockVoid {
operation(&self.storage)
}
}

var underlying: Value {
get { self.withLock { return $0 } }
set { self.withLockMutating { $0 = newValue }}
get { self.withLock { $0 } }
set { self.withLockMutating { $0 = newValue } }
}
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/LoggingTests/TestLogger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ internal struct TestLibrary {
self.logger.info("TestLibrary::doSomething")
}

public func doSomethingAsync(completion: @escaping @Sendable () -> Void) {
public func doSomethingAsync(completion: @escaping @Sendable() -> Void) {
// libraries that use global loggers and async, need to make sure they propagate the
// logging metadata when creating a new thread
let metadata = MDC.global.metadata
Expand Down

0 comments on commit 059542f

Please sign in to comment.