Skip to content

Commit e2b3659

Browse files
committed
Factor into two macros (@DougGregor); Apply feedback (@ahoppen)
1 parent 21c6c47 commit e2b3659

14 files changed

+403
-218
lines changed

lib/Macros/Sources/SwiftMacros/DebugDescriptionMacro.swift

Lines changed: 326 additions & 177 deletions
Large diffs are not rendered by default.

test/Macros/DebugDescription/either_description.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,19 @@
44
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -typecheck -enable-experimental-feature SymbolLinkageMarkers -plugin-path %swift-plugin-dir -dump-macro-expansions > %t/expansions-dump.txt 2>&1
55
// RUN: %FileCheck %s < %t/expansions-dump.txt
66

7-
@attached(peer, names: suffixed(_lldb_summary))
7+
@attached(memberAttribute)
88
public macro _DebugDescription() =
99
#externalMacro(module: "SwiftMacros", type: "DebugDescriptionMacro")
1010

11+
@attached(peer, names: named(_lldb_summary))
12+
public macro _DebugDescriptionProperty(_ debugIdentifier: String, _ computedProperties: [String]) =
13+
#externalMacro(module: "SwiftMacros", type: "_DebugDescriptionPropertyMacro")
14+
1115
@_DebugDescription
1216
struct MyStruct1: CustomStringConvertible {
1317
var description: String { "thirty" }
1418
}
15-
// CHECK: let MyStruct1_lldb_summary = (
19+
// CHECK: static let _lldb_summary = (
1620
// CHECK: /* version */ 1 as UInt8,
1721
// CHECK: /* record size */ 24 as UInt8,
1822
// CHECK: /* "main.MyStruct1" */ 15 as UInt8, 109 as UInt8, 97 as UInt8, 105 as UInt8, 110 as UInt8, 46 as UInt8, 77 as UInt8, 121 as UInt8, 83 as UInt8, 116 as UInt8, 114 as UInt8, 117 as UInt8, 99 as UInt8, 116 as UInt8, 49 as UInt8, 0 as UInt8,
@@ -23,7 +27,7 @@ struct MyStruct1: CustomStringConvertible {
2327
struct MyStruct2: CustomDebugStringConvertible {
2428
var debugDescription: String { "thirty" }
2529
}
26-
// CHECK: let MyStruct2_lldb_summary = (
30+
// CHECK: static let _lldb_summary = (
2731
// CHECK: /* version */ 1 as UInt8,
2832
// CHECK: /* record size */ 24 as UInt8,
2933
// CHECK: /* "main.MyStruct2" */ 15 as UInt8, 109 as UInt8, 97 as UInt8, 105 as UInt8, 110 as UInt8, 46 as UInt8, 77 as UInt8, 121 as UInt8, 83 as UInt8, 116 as UInt8, 114 as UInt8, 117 as UInt8, 99 as UInt8, 116 as UInt8, 50 as UInt8, 0 as UInt8,

test/Macros/DebugDescription/error_complex_implementation.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,19 @@
33
// RUN: %empty-directory(%t)
44
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -typecheck -verify -plugin-path %swift-plugin-dir
55

6-
@attached(peer, names: suffixed(_lldb_summary))
6+
@attached(memberAttribute)
77
public macro _DebugDescription() =
88
#externalMacro(module: "SwiftMacros", type: "DebugDescriptionMacro")
99

10+
@attached(peer, names: named(_lldb_summary))
11+
public macro _DebugDescriptionProperty(_ debugIdentifier: String, _ computedProperties: [String]) =
12+
#externalMacro(module: "SwiftMacros", type: "_DebugDescriptionPropertyMacro")
13+
1014
@_DebugDescription
1115
struct MyStruct {
1216
var flag: Bool
1317

14-
// expected-error @+1 {{debugDescription must consist of a single string literal}}
18+
// expected-error @+1 {{body must consist of a single string literal}}
1519
var debugDescription: String {
1620
flag ? "yes" : "no"
1721
}

test/Macros/DebugDescription/error_computed_properties.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@
33
// RUN: %empty-directory(%t)
44
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -typecheck -verify -plugin-path %swift-plugin-dir
55

6-
@attached(peer, names: suffixed(_lldb_summary))
6+
@attached(memberAttribute)
77
public macro _DebugDescription() =
88
#externalMacro(module: "SwiftMacros", type: "DebugDescriptionMacro")
99

10+
@attached(peer, names: named(_lldb_summary))
11+
public macro _DebugDescriptionProperty(_ debugIdentifier: String, _ computedProperties: [String]) =
12+
#externalMacro(module: "SwiftMacros", type: "_DebugDescriptionPropertyMacro")
13+
1014
@_DebugDescription
1115
struct MyStruct {
1216
var name: String { "thirty" }

test/Macros/DebugDescription/error_custom_interpolation.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@
33
// RUN: %empty-directory(%t)
44
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -typecheck -verify -plugin-path %swift-plugin-dir
55

6-
@attached(peer, names: suffixed(_lldb_summary))
6+
@attached(memberAttribute)
77
public macro _DebugDescription() =
88
#externalMacro(module: "SwiftMacros", type: "DebugDescriptionMacro")
99

10+
@attached(peer, names: named(_lldb_summary))
11+
public macro _DebugDescriptionProperty(_ debugIdentifier: String, _ computedProperties: [String]) =
12+
#externalMacro(module: "SwiftMacros", type: "_DebugDescriptionPropertyMacro")
13+
1014
extension DefaultStringInterpolation {
1115
fileprivate func appendInterpolation(custom: Int) {}
1216
fileprivate func appendInterpolation<A, B>(_ a: A, _ b: B) {}

test/Macros/DebugDescription/error_interpolation_expression.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@
33
// RUN: %empty-directory(%t)
44
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -typecheck -verify -plugin-path %swift-plugin-dir
55

6-
@attached(peer, names: suffixed(_lldb_summary))
6+
@attached(memberAttribute)
77
public macro _DebugDescription() =
88
#externalMacro(module: "SwiftMacros", type: "DebugDescriptionMacro")
99

10+
@attached(peer, names: named(_lldb_summary))
11+
public macro _DebugDescriptionProperty(_ debugIdentifier: String, _ computedProperties: [String]) =
12+
#externalMacro(module: "SwiftMacros", type: "_DebugDescriptionPropertyMacro")
13+
1014
@_DebugDescription
1115
struct MyStruct {
12-
// expected-error @+1 {{unsupported expression; stored properties only}}
16+
// expected-error @+1 {{only references to stored properties are allowed}}
1317
var debugDescription: String { "\(1)" }
1418
}

test/Macros/DebugDescription/error_no_description.swift

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

test/Macros/DebugDescription/error_protocol.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@
33
// RUN: %empty-directory(%t)
44
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -typecheck -verify -plugin-path %swift-plugin-dir
55

6-
@attached(peer, names: suffixed(_lldb_summary))
6+
@attached(memberAttribute)
77
public macro _DebugDescription() =
88
#externalMacro(module: "SwiftMacros", type: "DebugDescriptionMacro")
99

10-
// expected-error @+1 {{must be attached to a struct/class/enum/extension}}
10+
@attached(peer, names: named(_lldb_summary))
11+
public macro _DebugDescriptionProperty(_ debugIdentifier: String, _ computedProperties: [String]) =
12+
#externalMacro(module: "SwiftMacros", type: "_DebugDescriptionPropertyMacro")
13+
14+
// expected-error @+1 {{cannot be attached to a protocol}}
1115
@_DebugDescription
1216
protocol MyProto {
17+
func action()
1318
}

test/Macros/DebugDescription/explicit_self_property.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,20 @@
44
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -typecheck -enable-experimental-feature SymbolLinkageMarkers -plugin-path %swift-plugin-dir -dump-macro-expansions > %t/expansions-dump.txt 2>&1
55
// RUN: %FileCheck %s < %t/expansions-dump.txt
66

7-
@attached(peer, names: suffixed(_lldb_summary))
7+
@attached(memberAttribute)
88
public macro _DebugDescription() =
99
#externalMacro(module: "SwiftMacros", type: "DebugDescriptionMacro")
1010

11+
@attached(peer, names: named(_lldb_summary))
12+
public macro _DebugDescriptionProperty(_ debugIdentifier: String, _ computedProperties: [String]) =
13+
#externalMacro(module: "SwiftMacros", type: "_DebugDescriptionPropertyMacro")
14+
1115
@_DebugDescription
1216
struct MyStruct: CustomDebugStringConvertible {
1317
var name: String = "thirty"
1418
var debugDescription: String { "name: \(self.name)" }
1519
}
16-
// CHECK: let MyStruct_lldb_summary = (
20+
// CHECK: static let _lldb_summary = (
1721
// CHECK: /* version */ 1 as UInt8,
1822
// CHECK: /* record size */ 34 as UInt8,
1923
// CHECK: /* "main.MyStruct" */ 14 as UInt8, 109 as UInt8, 97 as UInt8, 105 as UInt8, 110 as UInt8, 46 as UInt8, 77 as UInt8, 121 as UInt8, 83 as UInt8, 116 as UInt8, 114 as UInt8, 117 as UInt8, 99 as UInt8, 116 as UInt8, 0 as UInt8,
@@ -25,7 +29,7 @@ class MyClass: CustomDebugStringConvertible {
2529
var name: String = "thirty"
2630
var debugDescription: String { "name: \(self.name)" }
2731
}
28-
// CHECK: let MyClass_lldb_summary = (
32+
// CHECK: static let _lldb_summary = (
2933
// CHECK: /* version */ 1 as UInt8,
3034
// CHECK: /* record size */ 33 as UInt8,
3135
// CHECK: /* "main.MyClass" */ 13 as UInt8, 109 as UInt8, 97 as UInt8, 105 as UInt8, 110 as UInt8, 46 as UInt8, 77 as UInt8, 121 as UInt8, 67 as UInt8, 108 as UInt8, 97 as UInt8, 115 as UInt8, 115 as UInt8, 0 as UInt8,

test/Macros/DebugDescription/implicit_self_property.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,20 @@
44
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -typecheck -enable-experimental-feature SymbolLinkageMarkers -plugin-path %swift-plugin-dir -dump-macro-expansions > %t/expansions-dump.txt 2>&1
55
// RUN: %FileCheck %s < %t/expansions-dump.txt
66

7-
@attached(peer, names: suffixed(_lldb_summary))
7+
@attached(memberAttribute)
88
public macro _DebugDescription() =
99
#externalMacro(module: "SwiftMacros", type: "DebugDescriptionMacro")
1010

11+
@attached(peer, names: named(_lldb_summary))
12+
public macro _DebugDescriptionProperty(_ debugIdentifier: String, _ computedProperties: [String]) =
13+
#externalMacro(module: "SwiftMacros", type: "_DebugDescriptionPropertyMacro")
14+
1115
@_DebugDescription
1216
struct MyStruct: CustomDebugStringConvertible {
1317
var name: String = "thirty"
1418
var debugDescription: String { "name: \(name)" }
1519
}
16-
// CHECK: let MyStruct_lldb_summary = (
20+
// CHECK: static let _lldb_summary = (
1721
// CHECK: /* version */ 1 as UInt8,
1822
// CHECK: /* record size */ 34 as UInt8,
1923
// CHECK: /* "main.MyStruct" */ 14 as UInt8, 109 as UInt8, 97 as UInt8, 105 as UInt8, 110 as UInt8, 46 as UInt8, 77 as UInt8, 121 as UInt8, 83 as UInt8, 116 as UInt8, 114 as UInt8, 117 as UInt8, 99 as UInt8, 116 as UInt8, 0 as UInt8,
@@ -25,7 +29,7 @@ class MyClass: CustomDebugStringConvertible {
2529
var name: String = "thirty"
2630
var debugDescription: String { "name: \(name)" }
2731
}
28-
// CHECK: let MyClass_lldb_summary = (
32+
// CHECK: static let _lldb_summary = (
2933
// CHECK: /* version */ 1 as UInt8,
3034
// CHECK: /* record size */ 33 as UInt8,
3135
// CHECK: /* "main.MyClass" */ 13 as UInt8, 109 as UInt8, 97 as UInt8, 105 as UInt8, 110 as UInt8, 46 as UInt8, 77 as UInt8, 121 as UInt8, 67 as UInt8, 108 as UInt8, 97 as UInt8, 115 as UInt8, 115 as UInt8, 0 as UInt8,

test/Macros/DebugDescription/linkage.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@
44
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -typecheck -enable-experimental-feature SymbolLinkageMarkers -plugin-path %swift-plugin-dir -dump-macro-expansions > %t/expansions-dump.txt 2>&1
55
// RUN: %FileCheck %s < %t/expansions-dump.txt
66

7-
@attached(peer, names: suffixed(_lldb_summary))
7+
@attached(memberAttribute)
88
public macro _DebugDescription() =
99
#externalMacro(module: "SwiftMacros", type: "DebugDescriptionMacro")
1010

11+
@attached(peer, names: named(_lldb_summary))
12+
public macro _DebugDescriptionProperty(_ debugIdentifier: String, _ computedProperties: [String]) =
13+
#externalMacro(module: "SwiftMacros", type: "_DebugDescriptionPropertyMacro")
14+
1115
@_DebugDescription
1216
struct MyStruct: CustomDebugStringConvertible {
1317
var debugDescription: String { "thirty" }
@@ -20,5 +24,5 @@ struct MyStruct: CustomDebugStringConvertible {
2024
// CHECK: @_section("__DATA_CONST,__lldbsummaries")
2125
// CHECK: #endif
2226
// CHECK: @_used
23-
// CHECK: let MyStruct_lldb_summary = (
27+
// CHECK: static let _lldb_summary = (
2428

test/Macros/DebugDescription/long_string.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@
44
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -typecheck -enable-experimental-feature SymbolLinkageMarkers -plugin-path %swift-plugin-dir -dump-macro-expansions > %t/expansions-dump.txt 2>&1
55
// RUN: %FileCheck %s < %t/expansions-dump.txt
66

7-
@attached(peer, names: suffixed(_lldb_summary))
7+
@attached(memberAttribute)
88
public macro _DebugDescription() =
99
#externalMacro(module: "SwiftMacros", type: "DebugDescriptionMacro")
1010

11+
@attached(peer, names: named(_lldb_summary))
12+
public macro _DebugDescriptionProperty(_ debugIdentifier: String, _ computedProperties: [String]) =
13+
#externalMacro(module: "SwiftMacros", type: "_DebugDescriptionPropertyMacro")
14+
1115
@_DebugDescription
1216
struct MyStruct: CustomDebugStringConvertible {
1317
var debugDescription: String {
@@ -19,7 +23,7 @@ struct MyStruct: CustomDebugStringConvertible {
1923
"""
2024
}
2125
}
22-
// CHECK: let MyStruct_lldb_summary = (
26+
// CHECK: static let _lldb_summary = (
2327
// CHECK: /* version */ 1 as UInt8,
2428
// CHECK: /* record size */ 192 as UInt8, 2 as UInt8,
2529
// CHECK: 8-bit integer. See https://en.wikipedia.org/wiki/LEB128" */ 175 as UInt8, 2 as UInt8, 65 as UInt8,

test/Macros/DebugDescription/property_chain.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,20 @@
44
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -typecheck -enable-experimental-feature SymbolLinkageMarkers -plugin-path %swift-plugin-dir -dump-macro-expansions > %t/expansions-dump.txt 2>&1
55
// RUN: %FileCheck %s < %t/expansions-dump.txt
66

7-
@attached(peer, names: suffixed(_lldb_summary))
7+
@attached(memberAttribute)
88
public macro _DebugDescription() =
99
#externalMacro(module: "SwiftMacros", type: "DebugDescriptionMacro")
1010

11+
@attached(peer, names: named(_lldb_summary))
12+
public macro _DebugDescriptionProperty(_ debugIdentifier: String, _ computedProperties: [String]) =
13+
#externalMacro(module: "SwiftMacros", type: "_DebugDescriptionPropertyMacro")
14+
1115
@_DebugDescription
1216
struct MyStruct: CustomDebugStringConvertible {
1317
var name: String = "thirty"
1418
var debugDescription: String { "\(self.name.count) \(name.count)" }
1519
}
16-
// CHECK: let MyStruct_lldb_summary = (
20+
// CHECK: static let _lldb_summary = (
1721
// CHECK: /* version */ 1 as UInt8,
1822
// CHECK: /* record size */ 52 as UInt8,
1923
// CHECK: /* "main.MyStruct" */ 14 as UInt8, 109 as UInt8, 97 as UInt8, 105 as UInt8, 110 as UInt8, 46 as UInt8, 77 as UInt8, 121 as UInt8, 83 as UInt8, 116 as UInt8, 114 as UInt8, 117 as UInt8, 99 as UInt8, 116 as UInt8, 0 as UInt8,
@@ -25,7 +29,7 @@ class MyClass: CustomDebugStringConvertible {
2529
var name: String = "thirty"
2630
var debugDescription: String { "\(self.name.count) \(name.count)" }
2731
}
28-
// CHECK: let MyClass_lldb_summary = (
32+
// CHECK: static let _lldb_summary = (
2933
// CHECK: /* version */ 1 as UInt8,
3034
// CHECK: /* record size */ 51 as UInt8,
3135
// CHECK: /* "main.MyClass" */ 13 as UInt8, 109 as UInt8, 97 as UInt8, 105 as UInt8, 110 as UInt8, 46 as UInt8, 77 as UInt8, 121 as UInt8, 67 as UInt8, 108 as UInt8, 97 as UInt8, 115 as UInt8, 115 as UInt8, 0 as UInt8,

test/Macros/DebugDescription/static_string.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,19 @@
44
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -typecheck -enable-experimental-feature SymbolLinkageMarkers -plugin-path %swift-plugin-dir -dump-macro-expansions > %t/expansions-dump.txt 2>&1
55
// RUN: %FileCheck %s < %t/expansions-dump.txt
66

7-
@attached(peer, names: suffixed(_lldb_summary))
7+
@attached(memberAttribute)
88
public macro _DebugDescription() =
99
#externalMacro(module: "SwiftMacros", type: "DebugDescriptionMacro")
1010

11+
@attached(peer, names: named(_lldb_summary))
12+
public macro _DebugDescriptionProperty(_ debugIdentifier: String, _ computedProperties: [String]) =
13+
#externalMacro(module: "SwiftMacros", type: "_DebugDescriptionPropertyMacro")
14+
1115
@_DebugDescription
1216
struct MyStruct: CustomDebugStringConvertible {
1317
var debugDescription: String { "thirty" }
1418
}
15-
// CHECK: let MyStruct_lldb_summary = (
19+
// CHECK: static let _lldb_summary = (
1620
// CHECK: /* version */ 1 as UInt8,
1721
// CHECK: /* record size */ 23 as UInt8,
1822
// CHECK: /* "main.MyStruct" */ 14 as UInt8, 109 as UInt8, 97 as UInt8, 105 as UInt8, 110 as UInt8, 46 as UInt8, 77 as UInt8, 121 as UInt8, 83 as UInt8, 116 as UInt8, 114 as UInt8, 117 as UInt8, 99 as UInt8, 116 as UInt8, 0 as UInt8,
@@ -23,7 +27,7 @@ struct MyStruct: CustomDebugStringConvertible {
2327
class MyClass: CustomDebugStringConvertible {
2428
var debugDescription: String { "thirty" }
2529
}
26-
// CHECK: let MyClass_lldb_summary = (
30+
// CHECK: static let _lldb_summary = (
2731
// CHECK: /* version */ 1 as UInt8,
2832
// CHECK: /* record size */ 22 as UInt8,
2933
// CHECK: /* "main.MyClass" */ 13 as UInt8, 109 as UInt8, 97 as UInt8, 105 as UInt8, 110 as UInt8, 46 as UInt8, 77 as UInt8, 121 as UInt8, 67 as UInt8, 108 as UInt8, 97 as UInt8, 115 as UInt8, 115 as UInt8, 0 as UInt8,
@@ -34,7 +38,7 @@ class MyClass: CustomDebugStringConvertible {
3438
class MyEnum: CustomDebugStringConvertible {
3539
var debugDescription: String { "thirty" }
3640
}
37-
// CHECK: let MyEnum_lldb_summary = (
41+
// CHECK: static let _lldb_summary = (
3842
// CHECK: /* version */ 1 as UInt8,
3943
// CHECK: /* record size */ 21 as UInt8,
4044
// CHECK: /* "main.MyEnum" */ 12 as UInt8, 109 as UInt8, 97 as UInt8, 105 as UInt8, 110 as UInt8, 46 as UInt8, 77 as UInt8, 121 as UInt8, 69 as UInt8, 110 as UInt8, 117 as UInt8, 109 as UInt8, 0 as UInt8,

0 commit comments

Comments
 (0)