Skip to content

Commit b2c4c3c

Browse files
committed
Declare _DebugDescription in stdlib
1 parent 3c45cd3 commit b2c4c3c

13 files changed

+46
-108
lines changed

stdlib/public/core/DebuggerSupport.swift

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,40 @@
1212

1313
import SwiftShims
1414

15+
#if $Macros && hasAttribute(attached)
16+
17+
/// Converts description definitions to a debugger type summary.
18+
///
19+
/// This macro converts compatible `debugDescription` (or `description`)
20+
/// implementations to a debugger type summary. This improves debugging in
21+
/// situations where expression evaluation is not performed, such as the
22+
/// variable list of an IDE.
23+
///
24+
/// For example, this code allows the debugger to display strings such as
25+
/// "Rams [11-2]" without invoking `debugDescription`:
26+
///
27+
/// @DebugDescription
28+
/// struct Team: CustomDebugStringConvertible {
29+
/// var name: String
30+
/// var wins, losses: Int
31+
///
32+
/// var debugDescription: String {
33+
/// "\(name) [\(wins)-\(losses)]"
34+
/// }
35+
/// }
36+
@available(SwiftStdlib 5.11, *)
37+
@attached(memberAttribute)
38+
public macro _DebugDescription() =
39+
#externalMacro(module: "SwiftMacros", type: "DebugDescriptionMacro")
40+
41+
/// Internal-only macro. See `@_DebugDescription`.
42+
@available(SwiftStdlib 5.11, *)
43+
@attached(peer, names: named(_lldb_summary))
44+
public macro _DebugDescriptionProperty(_ debugIdentifier: String, _ computedProperties: [String]) =
45+
#externalMacro(module: "SwiftMacros", type: "_DebugDescriptionPropertyMacro")
46+
47+
#endif
48+
1549
#if SWIFT_ENABLE_REFLECTION
1650

1751
@frozen // namespace

test/Macros/DebugDescription/either_description.swift

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
11
// REQUIRES: swift_swift_parser
22

33
// RUN: %empty-directory(%t)
4-
// 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
4+
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -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(memberAttribute)
8-
public macro _DebugDescription() =
9-
#externalMacro(module: "SwiftMacros", type: "DebugDescriptionMacro")
10-
11-
@attached(peer, names: named(_lldb_summary))
12-
public macro _DebugDescriptionProperty(_ debugIdentifier: String, _ computedProperties: [String]) =
13-
#externalMacro(module: "SwiftMacros", type: "_DebugDescriptionPropertyMacro")
14-
157
@_DebugDescription
168
struct MyStruct1: CustomStringConvertible {
179
var description: String { "thirty" }

test/Macros/DebugDescription/error_complex_implementation.swift

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
11
// REQUIRES: swift_swift_parser
22

33
// RUN: %empty-directory(%t)
4-
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -typecheck -verify -plugin-path %swift-plugin-dir
5-
6-
@attached(memberAttribute)
7-
public macro _DebugDescription() =
8-
#externalMacro(module: "SwiftMacros", type: "DebugDescriptionMacro")
9-
10-
@attached(peer, names: named(_lldb_summary))
11-
public macro _DebugDescriptionProperty(_ debugIdentifier: String, _ computedProperties: [String]) =
12-
#externalMacro(module: "SwiftMacros", type: "_DebugDescriptionPropertyMacro")
4+
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -verify -plugin-path %swift-plugin-dir
135

146
@_DebugDescription
157
struct MyStruct {

test/Macros/DebugDescription/error_computed_properties.swift

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
11
// REQUIRES: swift_swift_parser
22

33
// RUN: %empty-directory(%t)
4-
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -typecheck -verify -plugin-path %swift-plugin-dir
5-
6-
@attached(memberAttribute)
7-
public macro _DebugDescription() =
8-
#externalMacro(module: "SwiftMacros", type: "DebugDescriptionMacro")
9-
10-
@attached(peer, names: named(_lldb_summary))
11-
public macro _DebugDescriptionProperty(_ debugIdentifier: String, _ computedProperties: [String]) =
12-
#externalMacro(module: "SwiftMacros", type: "_DebugDescriptionPropertyMacro")
4+
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -verify -plugin-path %swift-plugin-dir
135

146
@_DebugDescription
157
struct MyStruct {

test/Macros/DebugDescription/error_custom_interpolation.swift

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
11
// REQUIRES: swift_swift_parser
22

33
// RUN: %empty-directory(%t)
4-
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -typecheck -verify -plugin-path %swift-plugin-dir
5-
6-
@attached(memberAttribute)
7-
public macro _DebugDescription() =
8-
#externalMacro(module: "SwiftMacros", type: "DebugDescriptionMacro")
9-
10-
@attached(peer, names: named(_lldb_summary))
11-
public macro _DebugDescriptionProperty(_ debugIdentifier: String, _ computedProperties: [String]) =
12-
#externalMacro(module: "SwiftMacros", type: "_DebugDescriptionPropertyMacro")
4+
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -verify -plugin-path %swift-plugin-dir
135

146
extension DefaultStringInterpolation {
157
fileprivate func appendInterpolation(custom: Int) {}

test/Macros/DebugDescription/error_interpolation_expression.swift

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
11
// REQUIRES: swift_swift_parser
22

33
// RUN: %empty-directory(%t)
4-
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -typecheck -verify -plugin-path %swift-plugin-dir
5-
6-
@attached(memberAttribute)
7-
public macro _DebugDescription() =
8-
#externalMacro(module: "SwiftMacros", type: "DebugDescriptionMacro")
9-
10-
@attached(peer, names: named(_lldb_summary))
11-
public macro _DebugDescriptionProperty(_ debugIdentifier: String, _ computedProperties: [String]) =
12-
#externalMacro(module: "SwiftMacros", type: "_DebugDescriptionPropertyMacro")
4+
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -verify -plugin-path %swift-plugin-dir
135

146
@_DebugDescription
157
struct MyStruct {

test/Macros/DebugDescription/error_protocol.swift

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
11
// REQUIRES: swift_swift_parser
22

33
// RUN: %empty-directory(%t)
4-
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -typecheck -verify -plugin-path %swift-plugin-dir
5-
6-
@attached(memberAttribute)
7-
public macro _DebugDescription() =
8-
#externalMacro(module: "SwiftMacros", type: "DebugDescriptionMacro")
9-
10-
@attached(peer, names: named(_lldb_summary))
11-
public macro _DebugDescriptionProperty(_ debugIdentifier: String, _ computedProperties: [String]) =
12-
#externalMacro(module: "SwiftMacros", type: "_DebugDescriptionPropertyMacro")
4+
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -verify -plugin-path %swift-plugin-dir
135

146
// expected-error @+1 {{cannot be attached to a protocol}}
157
@_DebugDescription

test/Macros/DebugDescription/explicit_self_property.swift

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
11
// REQUIRES: swift_swift_parser
22

33
// RUN: %empty-directory(%t)
4-
// 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
4+
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -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(memberAttribute)
8-
public macro _DebugDescription() =
9-
#externalMacro(module: "SwiftMacros", type: "DebugDescriptionMacro")
10-
11-
@attached(peer, names: named(_lldb_summary))
12-
public macro _DebugDescriptionProperty(_ debugIdentifier: String, _ computedProperties: [String]) =
13-
#externalMacro(module: "SwiftMacros", type: "_DebugDescriptionPropertyMacro")
14-
157
@_DebugDescription
168
struct MyStruct: CustomDebugStringConvertible {
179
var name: String = "thirty"

test/Macros/DebugDescription/implicit_self_property.swift

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
11
// REQUIRES: swift_swift_parser
22

33
// RUN: %empty-directory(%t)
4-
// 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
4+
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -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(memberAttribute)
8-
public macro _DebugDescription() =
9-
#externalMacro(module: "SwiftMacros", type: "DebugDescriptionMacro")
10-
11-
@attached(peer, names: named(_lldb_summary))
12-
public macro _DebugDescriptionProperty(_ debugIdentifier: String, _ computedProperties: [String]) =
13-
#externalMacro(module: "SwiftMacros", type: "_DebugDescriptionPropertyMacro")
14-
157
@_DebugDescription
168
struct MyStruct: CustomDebugStringConvertible {
179
var name: String = "thirty"

test/Macros/DebugDescription/linkage.swift

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
11
// REQUIRES: swift_swift_parser
22

33
// RUN: %empty-directory(%t)
4-
// 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
4+
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -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(memberAttribute)
8-
public macro _DebugDescription() =
9-
#externalMacro(module: "SwiftMacros", type: "DebugDescriptionMacro")
10-
11-
@attached(peer, names: named(_lldb_summary))
12-
public macro _DebugDescriptionProperty(_ debugIdentifier: String, _ computedProperties: [String]) =
13-
#externalMacro(module: "SwiftMacros", type: "_DebugDescriptionPropertyMacro")
14-
157
@_DebugDescription
168
struct MyStruct: CustomDebugStringConvertible {
179
var debugDescription: String { "thirty" }

test/Macros/DebugDescription/long_string.swift

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
11
// REQUIRES: swift_swift_parser
22

33
// RUN: %empty-directory(%t)
4-
// 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
4+
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -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(memberAttribute)
8-
public macro _DebugDescription() =
9-
#externalMacro(module: "SwiftMacros", type: "DebugDescriptionMacro")
10-
11-
@attached(peer, names: named(_lldb_summary))
12-
public macro _DebugDescriptionProperty(_ debugIdentifier: String, _ computedProperties: [String]) =
13-
#externalMacro(module: "SwiftMacros", type: "_DebugDescriptionPropertyMacro")
14-
157
@_DebugDescription
168
struct MyStruct: CustomDebugStringConvertible {
179
var debugDescription: String {

test/Macros/DebugDescription/property_chain.swift

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
11
// REQUIRES: swift_swift_parser
22

33
// RUN: %empty-directory(%t)
4-
// 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
4+
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -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(memberAttribute)
8-
public macro _DebugDescription() =
9-
#externalMacro(module: "SwiftMacros", type: "DebugDescriptionMacro")
10-
11-
@attached(peer, names: named(_lldb_summary))
12-
public macro _DebugDescriptionProperty(_ debugIdentifier: String, _ computedProperties: [String]) =
13-
#externalMacro(module: "SwiftMacros", type: "_DebugDescriptionPropertyMacro")
14-
157
@_DebugDescription
168
struct MyStruct: CustomDebugStringConvertible {
179
var name: String = "thirty"

test/Macros/DebugDescription/static_string.swift

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
11
// REQUIRES: swift_swift_parser
22

33
// RUN: %empty-directory(%t)
4-
// 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
4+
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -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(memberAttribute)
8-
public macro _DebugDescription() =
9-
#externalMacro(module: "SwiftMacros", type: "DebugDescriptionMacro")
10-
11-
@attached(peer, names: named(_lldb_summary))
12-
public macro _DebugDescriptionProperty(_ debugIdentifier: String, _ computedProperties: [String]) =
13-
#externalMacro(module: "SwiftMacros", type: "_DebugDescriptionPropertyMacro")
14-
157
@_DebugDescription
168
struct MyStruct: CustomDebugStringConvertible {
179
var debugDescription: String { "thirty" }

0 commit comments

Comments
 (0)