Skip to content

Commit 501a468

Browse files
committed
nfc: std lib style tweaks
1 parent ab01026 commit 501a468

File tree

5 files changed

+74
-58
lines changed

5 files changed

+74
-58
lines changed

tools/swiftdt/Sources/swiftdt/Inspector.swift

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ class Inspector {
99

1010
init?(pid: pid_t) {
1111
task = Self.findTask(pid, tryForkCorpse: false)
12-
if task == 0 {
13-
return nil
14-
}
12+
if task == 0 { return nil }
13+
1514
symbolicator = CSSymbolicatorCreateWithTask(task)
1615
swiftCore = CSSymbolicatorGetSymbolOwnerWithNameAtTime(
1716
symbolicator, "libswiftCore.dylib", kCSNow)
@@ -95,7 +94,7 @@ class Inspector {
9594
}
9695

9796
private func instance(_ context: UnsafeMutableRawPointer?) -> Inspector {
98-
return Unmanaged.fromOpaque(context!).takeUnretainedValue()
97+
Unmanaged.fromOpaque(context!).takeUnretainedValue()
9998
}
10099

101100
private func QueryDataLayoutFn(context: UnsafeMutableRawPointer?,
@@ -116,25 +115,29 @@ private func ReadBytesFn(
116115
context: UnsafeMutableRawPointer?,
117116
address: swift_addr_t,
118117
size: UInt64,
119-
outContext: UnsafeMutablePointer<UnsafeMutableRawPointer?>?) ->
120-
UnsafeRawPointer? {
121-
return task_peek(instance(context).task, address, size)
118+
outContext: UnsafeMutablePointer<UnsafeMutableRawPointer?>?
119+
) -> UnsafeRawPointer? {
120+
task_peek(instance(context).task, address, size)
122121
}
123122

124-
private func GetStringLengthFn(context: UnsafeMutableRawPointer?,
125-
address: swift_addr_t) -> UInt64 {
123+
private func GetStringLengthFn(
124+
context: UnsafeMutableRawPointer?,
125+
address: swift_addr_t
126+
) -> UInt64 {
126127
let maybeStr = task_peek_string(instance(context).task, address)
127128
guard let str = maybeStr else { return 0 }
128129
return UInt64(strlen(str))
129130
}
130131

131-
private func GetSymbolAddressFn(context: UnsafeMutableRawPointer?,
132-
name: UnsafePointer<CChar>?,
133-
length: UInt64) -> swift_addr_t {
132+
private func GetSymbolAddressFn(
133+
context: UnsafeMutableRawPointer?,
134+
name: UnsafePointer<CChar>?,
135+
length: UInt64
136+
) -> swift_addr_t {
134137
let nameStr: String = name!.withMemoryRebound(to: UInt8.self,
135-
capacity: Int(length), {
138+
capacity: Int(length)) {
136139
let buffer = UnsafeBufferPointer(start: $0, count: Int(length))
137140
return String(decoding: buffer, as: UTF8.self)
138-
})
141+
}
139142
return instance(context).getAddr(symbolName: nameStr)
140143
}

tools/swiftdt/Sources/swiftdt/InterpolationExtensions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ extension DefaultStringInterpolation {
55
appendInterpolation("0x")
66
appendInterpolation(String(hex, radix: 16))
77
}
8-
}
8+
}

tools/swiftdt/Sources/swiftdt/RemoteMirrorExtensions.swift

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,31 +27,34 @@ extension SwiftReflectionContextRef {
2727
}
2828

2929
func iterateConformanceCache(
30-
call: (swift_reflection_ptr_t, swift_reflection_ptr_t) -> Void) throws {
31-
var call = call
30+
_ body: (swift_reflection_ptr_t, swift_reflection_ptr_t) -> Void
31+
) throws {
32+
var body = body
3233
let errStr = swift_reflection_iterateConformanceCache(self, {
3334
let callPtr = $2!.bindMemory(to:
3435
((swift_reflection_ptr_t, swift_reflection_ptr_t) -> Void).self,
3536
capacity: 1)
3637
callPtr.pointee($0, $1)
37-
}, &call)
38+
}, &body)
3839
try throwError(str: errStr)
3940
}
4041

4142
func iterateMetadataAllocations(
42-
call: (swift_metadata_allocation_t) -> Void) throws {
43-
var call = call
43+
_ body: (swift_metadata_allocation_t) -> Void
44+
) throws {
45+
var body = body
4446
let errStr = swift_reflection_iterateMetadataAllocations(self, {
4547
let callPtr = $1!.bindMemory(to:
4648
((swift_metadata_allocation_t) -> Void).self, capacity: 1)
4749
callPtr.pointee($0)
48-
}, &call)
50+
}, &body)
4951
try throwError(str: errStr)
5052
}
5153

52-
func metadataPointer(allocation: swift_metadata_allocation_t)
53-
-> swift_reflection_ptr_t {
54-
return swift_reflection_allocationMetadataPointer(self, allocation)
54+
func metadataPointer(
55+
allocation: swift_metadata_allocation_t
56+
) -> swift_reflection_ptr_t {
57+
swift_reflection_allocationMetadataPointer(self, allocation)
5558
}
5659

5760
private func throwError(str: UnsafePointer<CChar>?) throws {

tools/swiftdt/Sources/swiftdt/main.swift

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,33 @@ func argFail(_ message: String) -> Never {
88
}
99

1010
func machErrStr(_ kr: kern_return_t) -> String {
11-
let errStr = String(cString: mach_error_string(kr))
12-
let errHex = String(kr, radix: 16)
13-
return "\(errStr) (0x\(errHex))"
11+
let errStr = String(cString: mach_error_string(kr))
12+
let errHex = String(kr, radix: 16)
13+
return "\(errStr) (0x\(errHex))"
1414
}
1515

1616
func dumpConformanceCache(context: SwiftReflectionContextRef) throws {
17-
try context.iterateConformanceCache(call: { type, proto in
17+
try context.iterateConformanceCache { type, proto in
1818
let typeName = context.name(metadata: type) ?? "<unknown>"
1919
let protoName = context.name(proto: proto) ?? "<unknown>"
2020
print("Conformance: \(typeName): \(protoName)")
21-
})
21+
}
2222
}
2323

2424
func dumpMetadataAllocations(context: SwiftReflectionContextRef) throws {
2525
var allocations: [swift_metadata_allocation_t] = []
2626
var metadatas: [swift_reflection_ptr_t] = []
27-
try context.iterateMetadataAllocations(call: { allocation in
27+
try context.iterateMetadataAllocations { allocation in
2828
allocations.append(allocation)
2929
print("Metadata allocation at: \(hex: allocation.Ptr) " +
3030
"size: \(allocation.Size) tag: \(allocation.Tag)")
3131
let ptr = context.metadataPointer(allocation: allocation)
3232
if ptr != 0 {
3333
metadatas.append(ptr)
3434
}
35-
})
35+
}
3636

37-
allocations.sort(by: { $0.Ptr < $1.Ptr })
37+
allocations.sort { $0.Ptr < $1.Ptr }
3838
for metadata in metadatas {
3939
let name = context.name(metadata: metadata) ?? "<unknown>"
4040
print("Metadata \(hex: metadata)")
@@ -50,8 +50,9 @@ func dumpMetadataAllocations(context: SwiftReflectionContextRef) throws {
5050
}
5151
}
5252

53-
func makeReflectionContext(nameOrPid: String)
54-
-> (Inspector, SwiftReflectionContextRef) {
53+
func makeReflectionContext(
54+
nameOrPid: String
55+
) -> (Inspector, SwiftReflectionContextRef) {
5556
guard let pid = pidFromHint(nameOrPid) else {
5657
argFail("Cannot find pid/process \(nameOrPid)")
5758
}
@@ -60,28 +61,30 @@ func makeReflectionContext(nameOrPid: String)
6061
argFail("Failed to inspect pid \(pid) (are you running as root?)")
6162
}
6263

63-
guard let reflectionContext
64-
= swift_reflection_createReflectionContextWithDataLayout(
64+
guard let reflectionContext = swift_reflection_createReflectionContextWithDataLayout(
6565
inspector.passContext(),
6666
Inspector.Callbacks.QueryDataLayout,
6767
Inspector.Callbacks.Free,
6868
Inspector.Callbacks.ReadBytes,
6969
Inspector.Callbacks.GetStringLength,
70-
Inspector.Callbacks.GetSymbolAddress) else {
70+
Inspector.Callbacks.GetSymbolAddress
71+
) else {
7172
argFail("Failed to create reflection context")
7273
}
74+
7375
return (inspector, reflectionContext)
7476
}
7577

7678
func withReflectionContext(
7779
nameOrPid: String,
78-
call: (SwiftReflectionContextRef) throws -> Void) throws {
80+
_ body: (SwiftReflectionContextRef) throws -> Void
81+
) throws {
7982
let (inspector, context) = makeReflectionContext(nameOrPid: nameOrPid)
8083
defer {
8184
swift_reflection_destroyReflectionContext(context)
8285
inspector.destroyContext()
8386
}
84-
try call(context)
87+
try body(context)
8588
}
8689

8790
struct Swiftdt: ParsableCommand {

tools/swiftdt/Sources/swiftdt/symbolication.swift

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -60,25 +60,30 @@ func pidFromHint(_ hint: String) -> pid_t? {
6060
}
6161

6262
func CSSymbolicatorCreateWithTask(_ task: task_t) -> CSTypeRef {
63-
return Sym.CSSymbolicatorCreateWithTask(task)
63+
Sym.CSSymbolicatorCreateWithTask(task)
6464
}
6565

66-
func CSSymbolicatorGetSymbolOwnerWithNameAtTime(_ symbolicator: CSTypeRef,
67-
_ name: String,
68-
_ time: CSMachineTime)
69-
-> CSTypeRef {
70-
return Sym.CSSymbolicatorGetSymbolOwnerWithNameAtTime(symbolicator, name, time)
66+
func CSSymbolicatorGetSymbolOwnerWithNameAtTime(
67+
_ symbolicator: CSTypeRef,
68+
_ name: String,
69+
_ time: CSMachineTime
70+
) -> CSTypeRef {
71+
Sym.CSSymbolicatorGetSymbolOwnerWithNameAtTime(symbolicator, name, time)
7172
}
7273

7374
@discardableResult
74-
func CSSymbolOwnerForeachSymbol(_ symbolOwner: CSTypeRef,
75-
_ iterator: (CSTypeRef) -> Void) -> UInt {
76-
return Sym.CSSymbolOwnerForeachSymbol(symbolOwner, iterator)
75+
func CSSymbolOwnerForeachSymbol(
76+
_ symbolOwner: CSTypeRef,
77+
_ iterator: (CSTypeRef) -> Void
78+
) -> UInt {
79+
Sym.CSSymbolOwnerForeachSymbol(symbolOwner, iterator)
7780
}
7881

79-
func CSSymbolOwnerGetSymbolWithMangledName(_ owner: CSTypeRef, _ name: String)
80-
-> CSTypeRef {
81-
return Sym.CSSymbolOwnerGetSymbolWithMangledName(owner, name)
82+
func CSSymbolOwnerGetSymbolWithMangledName(
83+
_ owner: CSTypeRef,
84+
_ name: String
85+
) -> CSTypeRef {
86+
Sym.CSSymbolOwnerGetSymbolWithMangledName(owner, name)
8287
}
8388

8489
func CSSymbolGetName(_ sym: CSTypeRef) -> String? {
@@ -92,11 +97,11 @@ func CSSymbolGetMangledName(_ sym: CSTypeRef) -> String? {
9297
}
9398

9499
func CSSymbolIsFunction(_ sym: CSTypeRef) -> Bool {
95-
return Sym.CSSymbolIsFunction(sym)
100+
Sym.CSSymbolIsFunction(sym)
96101
}
97102

98103
func CSSymbolGetRange(_ sym: CSTypeRef) -> Range {
99-
return Sym.CSSymbolGetRange(sym)
104+
Sym.CSSymbolGetRange(sym)
100105
}
101106

102107
func task_start_peeking(_ task: task_t) -> Bool {
@@ -109,8 +114,9 @@ func task_start_peeking(_ task: task_t) -> Bool {
109114
return false
110115
}
111116

112-
func task_peek(_ task: task_t, _ start: mach_vm_address_t, _ size: mach_vm_size_t) ->
113-
UnsafeRawPointer? {
117+
func task_peek(
118+
_ task: task_t, _ start: mach_vm_address_t, _ size: mach_vm_size_t
119+
) -> UnsafeRawPointer? {
114120
var ptr: UnsafeRawPointer? = nil
115121
let result = Sym.task_peek(task, start, size, &ptr)
116122
if result != KERN_SUCCESS {
@@ -120,9 +126,10 @@ func task_peek(_ task: task_t, _ start: mach_vm_address_t, _ size: mach_vm_size_
120126
return ptr
121127
}
122128

123-
func task_peek_string(_ task: task_t, _ addr: mach_vm_address_t) ->
124-
UnsafeMutablePointer<CChar>? {
125-
return Sym.task_peek_string(task, addr)
129+
func task_peek_string(
130+
_ task: task_t, _ addr: mach_vm_address_t
131+
) -> UnsafeMutablePointer<CChar>? {
132+
Sym.task_peek_string(task, addr)
126133
}
127134

128135
func task_stop_peeking(_ task: task_t) {

0 commit comments

Comments
 (0)