Skip to content

Commit 98a7c54

Browse files
refactor: Update swift format rules to use 4 space tabs instead of 2 - Pull request #13
2 parents cc18bbf + 6a4cbff commit 98a7c54

16 files changed

Lines changed: 4787 additions & 4695 deletions

.swift-format

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
{
2+
"fileScopedDeclarationPrivacy" : {
3+
"accessLevel" : "private"
4+
},
5+
"indentConditionalCompilationBlocks" : false,
6+
"indentSwitchCaseLabels" : false,
7+
"indentation" : {
8+
"spaces" : 4
9+
},
10+
"lineBreakAroundMultilineExpressionChainComponents" : false,
11+
"lineBreakBeforeControlFlowKeywords" : false,
12+
"lineBreakBeforeEachArgument" : false,
13+
"lineBreakBeforeEachGenericRequirement" : false,
14+
"lineBreakBetweenDeclarationAttributes" : false,
15+
"lineLength" : 140,
16+
"maximumBlankLines" : 1,
17+
"multiElementCollectionTrailingCommas" : true,
18+
"noAssignmentInExpressions" : {
19+
"allowedFunctions" : [
20+
"XCTAssertNoThrow"
21+
]
22+
},
23+
"prioritizeKeepingFunctionOutputTogether" : false,
24+
"reflowMultilineStringLiterals" : {
25+
"never" : {
26+
27+
}
28+
},
29+
"respectsExistingLineBreaks" : true,
30+
"rules" : {
31+
"AllPublicDeclarationsHaveDocumentation" : false,
32+
"AlwaysUseLiteralForEmptyCollectionInit" : false,
33+
"AlwaysUseLowerCamelCase" : true,
34+
"AmbiguousTrailingClosureOverload" : true,
35+
"AvoidRetroactiveConformances" : true,
36+
"BeginDocumentationCommentWithOneLineSummary" : false,
37+
"DoNotUseSemicolons" : true,
38+
"DontRepeatTypeInStaticProperties" : true,
39+
"FileScopedDeclarationPrivacy" : true,
40+
"FullyIndirectEnum" : true,
41+
"GroupNumericLiterals" : true,
42+
"IdentifiersMustBeASCII" : true,
43+
"NeverForceUnwrap" : false,
44+
"NeverUseForceTry" : false,
45+
"NeverUseImplicitlyUnwrappedOptionals" : false,
46+
"NoAccessLevelOnExtensionDeclaration" : true,
47+
"NoAssignmentInExpressions" : true,
48+
"NoBlockComments" : true,
49+
"NoCasesWithOnlyFallthrough" : true,
50+
"NoEmptyLinesOpeningClosingBraces" : false,
51+
"NoEmptyTrailingClosureParentheses" : true,
52+
"NoLabelsInCasePatterns" : true,
53+
"NoLeadingUnderscores" : false,
54+
"NoParensAroundConditions" : true,
55+
"NoPlaygroundLiterals" : true,
56+
"NoVoidReturnOnFunctionSignature" : true,
57+
"OmitExplicitReturns" : false,
58+
"OneCasePerLine" : true,
59+
"OneVariableDeclarationPerLine" : true,
60+
"OnlyOneTrailingClosureArgument" : true,
61+
"OrderedImports" : true,
62+
"ReplaceForEachWithForLoop" : true,
63+
"ReturnVoidInsteadOfEmptyTuple" : true,
64+
"TypeNamesShouldBeCapitalized" : true,
65+
"UseEarlyExits" : false,
66+
"UseExplicitNilCheckInConditions" : true,
67+
"UseLetInEveryBoundCaseVariable" : true,
68+
"UseShorthandTypeNames" : true,
69+
"UseSingleLinePropertyGetter" : true,
70+
"UseSynthesizedInitializer" : true,
71+
"UseTripleSlashForDocumentationComments" : true,
72+
"UseWhereClausesInForLoops" : false,
73+
"ValidateDocumentationComments" : false
74+
},
75+
"spacesAroundRangeFormationOperators" : true,
76+
"spacesBeforeEndOfLineComments" : 1,
77+
"tabWidth" : 8,
78+
"version" : 1
79+
}

Benchmarks/Benchmarks/NIOAsyncRuntimeBenchmarks/Benchmarks.swift

Lines changed: 79 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -21,99 +21,99 @@ import NIOCore
2121
private let eventLoop = MultiThreadedEventLoopGroup.singleton.next()
2222

2323
let benchmarks = {
24-
let defaultMetrics: [BenchmarkMetric] = [
25-
.mallocCountTotal,
26-
.contextSwitches,
27-
.wallClock,
28-
]
24+
let defaultMetrics: [BenchmarkMetric] = [
25+
.mallocCountTotal,
26+
.contextSwitches,
27+
.wallClock,
28+
]
2929

30-
Benchmark(
31-
"MTELG.immediateTasksThroughput",
32-
configuration: Benchmark.Configuration(
33-
metrics: defaultMetrics,
34-
scalingFactor: .mega,
35-
maxDuration: .seconds(10_000_000),
36-
maxIterations: 5
37-
)
38-
) { benchmark in
39-
func noOp() {}
40-
for _ in benchmark.scaledIterations {
41-
eventLoop.execute { noOp() }
30+
Benchmark(
31+
"MTELG.immediateTasksThroughput",
32+
configuration: Benchmark.Configuration(
33+
metrics: defaultMetrics,
34+
scalingFactor: .mega,
35+
maxDuration: .seconds(10_000_000),
36+
maxIterations: 5
37+
)
38+
) { benchmark in
39+
func noOp() {}
40+
for _ in benchmark.scaledIterations {
41+
eventLoop.execute { noOp() }
42+
}
4243
}
43-
}
4444

45-
Benchmark(
46-
"MTELG.scheduleTask(in:_:)",
47-
configuration: Benchmark.Configuration(
48-
metrics: defaultMetrics,
49-
scalingFactor: .mega,
50-
maxDuration: .seconds(10_000_000),
51-
maxIterations: 5
52-
)
53-
) { benchmark in
54-
for _ in benchmark.scaledIterations {
55-
eventLoop.scheduleTask(in: .hours(1), {})
45+
Benchmark(
46+
"MTELG.scheduleTask(in:_:)",
47+
configuration: Benchmark.Configuration(
48+
metrics: defaultMetrics,
49+
scalingFactor: .mega,
50+
maxDuration: .seconds(10_000_000),
51+
maxIterations: 5
52+
)
53+
) { benchmark in
54+
for _ in benchmark.scaledIterations {
55+
eventLoop.scheduleTask(in: .hours(1), {})
56+
}
5657
}
57-
}
5858

59-
Benchmark(
60-
"MTELG.scheduleCallback(in:_:)",
61-
configuration: Benchmark.Configuration(
62-
metrics: defaultMetrics,
63-
scalingFactor: .mega,
64-
maxDuration: .seconds(10_000_000),
65-
maxIterations: 5
66-
)
67-
) { benchmark in
68-
final class Timer: NIOScheduledCallbackHandler {
69-
func handleScheduledCallback(eventLoop: some EventLoop) {}
70-
}
71-
let timer = Timer()
59+
Benchmark(
60+
"MTELG.scheduleCallback(in:_:)",
61+
configuration: Benchmark.Configuration(
62+
metrics: defaultMetrics,
63+
scalingFactor: .mega,
64+
maxDuration: .seconds(10_000_000),
65+
maxIterations: 5
66+
)
67+
) { benchmark in
68+
final class Timer: NIOScheduledCallbackHandler {
69+
func handleScheduledCallback(eventLoop: some EventLoop) {}
70+
}
71+
let timer = Timer()
7272

73-
benchmark.startMeasurement()
74-
for _ in benchmark.scaledIterations {
75-
let handle = try! eventLoop.scheduleCallback(in: .hours(1), handler: timer)
73+
benchmark.startMeasurement()
74+
for _ in benchmark.scaledIterations {
75+
let handle = try! eventLoop.scheduleCallback(in: .hours(1), handler: timer)
76+
}
7677
}
77-
}
7878

79-
Benchmark(
80-
"Jump to EL and back using execute and unsafecontinuation",
81-
configuration: .init(
82-
metrics: defaultMetrics,
83-
scalingFactor: .kilo
84-
)
85-
) { benchmark in
86-
for _ in benchmark.scaledIterations {
87-
await withUnsafeContinuation { (continuation: UnsafeContinuation<Void, Never>) in
88-
eventLoop.execute {
89-
continuation.resume()
79+
Benchmark(
80+
"Jump to EL and back using execute and unsafecontinuation",
81+
configuration: .init(
82+
metrics: defaultMetrics,
83+
scalingFactor: .kilo
84+
)
85+
) { benchmark in
86+
for _ in benchmark.scaledIterations {
87+
await withUnsafeContinuation { (continuation: UnsafeContinuation<Void, Never>) in
88+
eventLoop.execute {
89+
continuation.resume()
90+
}
91+
}
9092
}
91-
}
9293
}
93-
}
9494

95-
final actor Foo {
96-
nonisolated public let unownedExecutor: UnownedSerialExecutor
95+
final actor Foo {
96+
nonisolated public let unownedExecutor: UnownedSerialExecutor
9797

98-
init(eventLoop: any EventLoop) {
99-
self.unownedExecutor = eventLoop.executor.asUnownedSerialExecutor()
100-
}
98+
init(eventLoop: any EventLoop) {
99+
self.unownedExecutor = eventLoop.executor.asUnownedSerialExecutor()
100+
}
101101

102-
func foo() {
103-
blackHole(Void())
102+
func foo() {
103+
blackHole(Void())
104+
}
104105
}
105-
}
106106

107-
Benchmark(
108-
"Jump to EL and back using actor with EL executor",
109-
configuration: .init(
110-
metrics: defaultMetrics,
111-
scalingFactor: .kilo
112-
)
113-
) { benchmark in
114-
let actor = Foo(eventLoop: eventLoop)
115-
for _ in benchmark.scaledIterations {
116-
await actor.foo()
107+
Benchmark(
108+
"Jump to EL and back using actor with EL executor",
109+
configuration: .init(
110+
metrics: defaultMetrics,
111+
scalingFactor: .kilo
112+
)
113+
) { benchmark in
114+
let actor = Foo(eventLoop: eventLoop)
115+
for _ in benchmark.scaledIterations {
116+
await actor.foo()
117+
}
117118
}
118-
}
119119
}

Benchmarks/Benchmarks/NIOAsyncRuntimeBenchmarks/Util/GlobalExecutor.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,23 @@
1515
// See https://github.com/apple/swift-nio/blob/main/Benchmarks/Benchmarks/NIOPosixBenchmarks/Benchmarks.swift
1616

1717
#if canImport(Darwin)
18-
import Darwin.C
18+
import Darwin.C
1919
#elseif canImport(Glibc)
20-
import Glibc
20+
import Glibc
2121
#else
22-
#error("Unsupported platform.")
22+
#error("Unsupported platform.")
2323
#endif
2424

2525
// This file allows us to hook the global executor which
2626
// we can use to mimic task executors for now.
2727
typealias EnqueueGlobalHook =
28-
@convention(thin) (UnownedJob, @convention(thin) (UnownedJob) -> Void) -> Void
28+
@convention(thin) (UnownedJob, @convention(thin) (UnownedJob) -> Void) -> Void
2929

3030
var swiftTaskEnqueueGlobalHook: EnqueueGlobalHook? {
31-
get { _swiftTaskEnqueueGlobalHook.pointee }
32-
set { _swiftTaskEnqueueGlobalHook.pointee = newValue }
31+
get { _swiftTaskEnqueueGlobalHook.pointee }
32+
set { _swiftTaskEnqueueGlobalHook.pointee = newValue }
3333
}
3434

3535
private let _swiftTaskEnqueueGlobalHook: UnsafeMutablePointer<EnqueueGlobalHook?> =
36-
dlsym(dlopen(nil, RTLD_LAZY), "swift_task_enqueueGlobal_hook").assumingMemoryBound(
37-
to: EnqueueGlobalHook?.self)
36+
dlsym(dlopen(nil, RTLD_LAZY), "swift_task_enqueueGlobal_hook").assumingMemoryBound(
37+
to: EnqueueGlobalHook?.self)

0 commit comments

Comments
 (0)