@@ -15,15 +15,23 @@ import SwiftShims
15
15
// Macros are disabled when Swift is built without swift-syntax.
16
16
#if $Macros && hasAttribute(attached)
17
17
18
- /// Converts description definitions to a debugger type summary .
18
+ /// Converts description definitions to a debugger Type Summary .
19
19
///
20
- /// This macro converts compatible `debugDescription` (or `description`)
21
- /// implementations to a debugger type summary. This improves debugging in
22
- /// situations where expression evaluation is not performed, such as the
20
+ /// This macro converts compatible description implementations written in Swift
21
+ /// to an LLDB format known as a Type Summary. A Type Summary is LLDB's
22
+ /// equivalent to `debugDescription`, with the distinction that it does not
23
+ /// execute code inside the debugged process. By avoiding code execution,
24
+ /// descriptions can be produced faster, without potential side effects, and
25
+ /// shown in situations where code execution is not performed, such as the
23
26
/// variable list of an IDE.
24
27
///
25
- /// For example, this code allows the debugger to display strings such as
26
- /// "Rams [11-2]" without invoking `debugDescription`:
28
+ /// Consider this an example. This `Team` struct has a `debugDescription` which
29
+ /// summarizes some key details, such as the team's name. The debugger only
30
+ /// computes this string on demand - typically via the `po` command. By applying
31
+ /// the `DebugDescription` macro, a matching Type Summary is constructed. This
32
+ /// allows the user to show a string like "Rams [11-2]", without executing
33
+ /// `debugDescription`. This improves the usability, performance, and
34
+ /// reliability of the debugging experience.
27
35
///
28
36
/// @DebugDescription
29
37
/// struct Team: CustomDebugStringConvertible {
@@ -34,6 +42,28 @@ import SwiftShims
34
42
/// "\(name) [\(wins)-\(losses)]"
35
43
/// }
36
44
/// }
45
+ ///
46
+ /// The `DebugDescription` macro supports both `debugDescription`, `description`,
47
+ /// as well as a third option: a property named `_debugDescription`. The first
48
+ /// two are implemented when conforming to the `CustomDebugStringConvertible`
49
+ /// and `CustomStringConvertible` protocols. The additional `_debugDescription`
50
+ /// property is useful when both `debugDescription` and `description` are
51
+ /// implemented, but don't meet the requirements of the `DebugDescription`
52
+ /// macro. If `_debugDescription` is implemented, `DebugDescription` choose it
53
+ /// over `debugDescription` and `description`. Likewise, `debugDescription` is
54
+ /// preferred over `description`.
55
+ ///
56
+ /// ### Description Requirements
57
+ ///
58
+ /// The description implementation has the following requirements:
59
+ ///
60
+ /// * The body of the description implementation must a single string
61
+ /// expression. String concatenation is not supported, use string interpolation
62
+ /// instead.
63
+ /// * String interpolation can reference stored properties only, functions calls
64
+ /// and other arbitrary computation are not supported. Of note, conditional
65
+ /// logic and computed properties are not supported.
66
+ /// * Overloaded string interpolation cannot be used.
37
67
@available ( SwiftStdlib 5 . 11 , * )
38
68
@attached ( memberAttribute)
39
69
public macro _DebugDescription( ) =
0 commit comments