Skip to content

Commit dd1b2b5

Browse files
authored
Merge branch 'swift-server:main' into benchmark
2 parents a15bd27 + 785478c commit dd1b2b5

16 files changed

+637
-404
lines changed

.swift-format

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"fileScopedDeclarationPrivacy": {
3+
"accessLevel": "private"
4+
},
5+
"indentation": {
6+
"spaces": 4
7+
},
8+
"indentConditionalCompilationBlocks": false,
9+
"indentSwitchCaseLabels": false,
10+
"lineBreakAroundMultilineExpressionChainComponents": false,
11+
"lineBreakBeforeControlFlowKeywords": false,
12+
"lineBreakBeforeEachArgument": true,
13+
"lineBreakBeforeEachGenericRequirement": true,
14+
"lineLength": 120,
15+
"maximumBlankLines": 1,
16+
"prioritizeKeepingFunctionOutputTogether": true,
17+
"respectsExistingLineBreaks": true,
18+
"rules": {
19+
"AllPublicDeclarationsHaveDocumentation": false,
20+
"AlwaysUseLowerCamelCase": false,
21+
"AmbiguousTrailingClosureOverload": true,
22+
"BeginDocumentationCommentWithOneLineSummary": false,
23+
"DoNotUseSemicolons": true,
24+
"DontRepeatTypeInStaticProperties": true,
25+
"FileScopedDeclarationPrivacy": true,
26+
"FullyIndirectEnum": true,
27+
"GroupNumericLiterals": true,
28+
"IdentifiersMustBeASCII": true,
29+
"NeverForceUnwrap": false,
30+
"NeverUseForceTry": false,
31+
"NeverUseImplicitlyUnwrappedOptionals": false,
32+
"NoAccessLevelOnExtensionDeclaration": false,
33+
"NoAssignmentInExpressions": true,
34+
"NoBlockComments": true,
35+
"NoCasesWithOnlyFallthrough": true,
36+
"NoEmptyTrailingClosureParentheses": true,
37+
"NoLabelsInCasePatterns": false,
38+
"NoLeadingUnderscores": false,
39+
"NoParensAroundConditions": true,
40+
"NoVoidReturnOnFunctionSignature": true,
41+
"OneCasePerLine": true,
42+
"OneVariableDeclarationPerLine": true,
43+
"OnlyOneTrailingClosureArgument": true,
44+
"OrderedImports": false,
45+
"ReturnVoidInsteadOfEmptyTuple": true,
46+
"UseEarlyExits": true,
47+
"UseLetInEveryBoundCaseVariable": false,
48+
"UseShorthandTypeNames": true,
49+
"UseSingleLinePropertyGetter": false,
50+
"UseSynthesizedInitializer": false,
51+
"UseTripleSlashForDocumentationComments": true,
52+
"UseWhereClausesInForLoops": false,
53+
"ValidateDocumentationComments": false
54+
},
55+
"spacesAroundRangeFormationOperators": false,
56+
"tabWidth": 8,
57+
"version": 1
58+
}

.swiftformat

Lines changed: 0 additions & 24 deletions
This file was deleted.

Sources/Prometheus/Counter.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
import Atomics
1616
import CoreMetrics
1717

18-
/// A counter is a cumulative metric that represents a single monotonically increasing counter whose value
19-
/// can only increase or be ``reset()`` to zero on restart.
18+
/// A counter is a cumulative metric that represents a single monotonically increasing
19+
/// counter whose value can only increase or be ``reset()`` to zero on restart.
2020
///
2121
/// For example, you can use a counter to represent the number of requests served, tasks completed, or errors.
2222
///
@@ -68,7 +68,11 @@ public final class Counter: Sendable {
6868
while true {
6969
let bits = self.floatAtomic.load(ordering: .relaxed)
7070
let value = Double(bitPattern: bits) + amount
71-
let (exchanged, _) = self.floatAtomic.compareExchange(expected: bits, desired: value.bitPattern, ordering: .relaxed)
71+
let (exchanged, _) = self.floatAtomic.compareExchange(
72+
expected: bits,
73+
desired: value.bitPattern,
74+
ordering: .relaxed
75+
)
7276
if exchanged {
7377
break
7478
}

Sources/Prometheus/Docs.docc/swift-metrics.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ import Prometheus
4545

4646
func main() {
4747
let factory = PrometheusMetricsFactory()
48-
MetricSystem.bootstrap(factory)
48+
MetricsSystem.bootstrap(factory)
4949

5050
// the rest of your application code
5151
}
@@ -66,7 +66,7 @@ To use a different collector registry pass your ``PrometheusCollectorRegistry``
6666
```swift
6767
let registry = PrometheusCollectorRegistry()
6868
let factory = PrometheusMetricsFactory(registry: registry)
69-
MetricSystem.bootstrap(factory)
69+
MetricsSystem.bootstrap(factory)
7070
```
7171

7272
You can also overwrite the ``PrometheusMetricsFactory/registry`` by setting it explicitly:
@@ -75,7 +75,7 @@ You can also overwrite the ``PrometheusMetricsFactory/registry`` by setting it e
7575
let registry = PrometheusCollectorRegistry()
7676
var factory = PrometheusMetricsFactory()
7777
factory.registry = registry
78-
MetricSystem.bootstrap(factory)
78+
MetricsSystem.bootstrap(factory)
7979
```
8080

8181
### Modifying Swift metrics names and labels
@@ -93,7 +93,7 @@ factory.nameAndLabelSanitizer = { (name, labels)
9393
return (name, labels)
9494
}
9595
}
96-
MetricSystem.bootstrap(factory)
96+
MetricsSystem.bootstrap(factory)
9797

9898
// somewhere else
9999
Metrics.Counter(label: "my_counter") // will show up in Prometheus exports as `counter`
@@ -134,7 +134,7 @@ factory.defaultValueHistogramBuckets = [
134134
100,
135135
250,
136136
]
137-
MetricSystem.bootstrap(factory)
137+
MetricsSystem.bootstrap(factory)
138138

139139
// somewhere else
140140
Timer(label: "my_timer") // will use the buckets specified in `defaultDurationHistogramBuckets`

Sources/Prometheus/Gauge.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ public final class Gauge: Sendable {
5858
while true {
5959
let bits = self.atomic.load(ordering: .relaxed)
6060
let value = Double(bitPattern: bits) + amount
61-
let (exchanged, _) = self.atomic.compareExchange(expected: bits, desired: value.bitPattern, ordering: .relaxed)
61+
let (exchanged, _) = self.atomic.compareExchange(
62+
expected: bits,
63+
desired: value.bitPattern,
64+
ordering: .relaxed
65+
)
6266
if exchanged {
6367
break
6468
}
@@ -84,7 +88,7 @@ extension Gauge: CoreMetrics.MeterHandler {
8488
public func set(_ value: Double) {
8589
self.set(to: value)
8690
}
87-
91+
8892
public func set(_ value: Int64) {
8993
self.set(to: Double(value))
9094
}

Sources/Prometheus/NIOLock.swift

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,16 @@ typealias LockPrimitive = pthread_mutex_t
4747
#endif
4848

4949
@usableFromInline
50-
enum LockOperations { }
50+
enum LockOperations {}
5151

5252
extension LockOperations {
5353
@inlinable
5454
static func create(_ mutex: UnsafeMutablePointer<LockPrimitive>) {
5555
mutex.assertValidAlignment()
5656

57-
#if os(Windows)
57+
#if os(Windows)
5858
InitializeSRWLock(mutex)
59-
#else
59+
#else
6060
var attr = pthread_mutexattr_t()
6161
pthread_mutexattr_init(&attr)
6262
debugOnly {
@@ -65,43 +65,43 @@ extension LockOperations {
6565

6666
let err = pthread_mutex_init(mutex, &attr)
6767
precondition(err == 0, "\(#function) failed in pthread_mutex with error \(err)")
68-
#endif
68+
#endif
6969
}
7070

7171
@inlinable
7272
static func destroy(_ mutex: UnsafeMutablePointer<LockPrimitive>) {
7373
mutex.assertValidAlignment()
7474

75-
#if os(Windows)
75+
#if os(Windows)
7676
// SRWLOCK does not need to be free'd
77-
#else
77+
#else
7878
let err = pthread_mutex_destroy(mutex)
7979
precondition(err == 0, "\(#function) failed in pthread_mutex with error \(err)")
80-
#endif
80+
#endif
8181
}
8282

8383
@inlinable
8484
static func lock(_ mutex: UnsafeMutablePointer<LockPrimitive>) {
8585
mutex.assertValidAlignment()
8686

87-
#if os(Windows)
87+
#if os(Windows)
8888
AcquireSRWLockExclusive(mutex)
89-
#else
89+
#else
9090
let err = pthread_mutex_lock(mutex)
9191
precondition(err == 0, "\(#function) failed in pthread_mutex with error \(err)")
92-
#endif
92+
#endif
9393
}
9494

9595
@inlinable
9696
static func unlock(_ mutex: UnsafeMutablePointer<LockPrimitive>) {
9797
mutex.assertValidAlignment()
9898

99-
#if os(Windows)
99+
#if os(Windows)
100100
ReleaseSRWLockExclusive(mutex)
101-
#else
101+
#else
102102
let err = pthread_mutex_unlock(mutex)
103103
precondition(err == 0, "\(#function) failed in pthread_mutex with error \(err)")
104-
#endif
104+
#endif
105105
}
106106
}
107107

@@ -188,7 +188,7 @@ final class LockStorage<Value>: ManagedBuffer<Value, LockPrimitive> {
188188
}
189189
}
190190

191-
extension LockStorage: @unchecked Sendable { }
191+
extension LockStorage: @unchecked Sendable {}
192192

193193
/// A threading lock based on `libpthread` instead of `libdispatch`.
194194
///
@@ -251,7 +251,7 @@ extension NIOLock {
251251
}
252252

253253
@inlinable
254-
func withLockVoid(_ body: () throws -> Void) rethrows -> Void {
254+
func withLockVoid(_ body: () throws -> Void) rethrows {
255255
try self.withLock(body)
256256
}
257257
}
@@ -272,6 +272,10 @@ extension UnsafeMutablePointer {
272272
/// https://forums.swift.org/t/support-debug-only-code/11037 for a discussion.
273273
@inlinable
274274
internal func debugOnly(_ body: () -> Void) {
275-
assert({ body(); return true }())
275+
assert(
276+
{
277+
body()
278+
return true
279+
}()
280+
)
276281
}
277-

0 commit comments

Comments
 (0)