Skip to content

Commit 5de6ec1

Browse files
committed
[Debugging] Add DebugDescriptionMacro experimental feature (#73070)
This removes the leading underscore from the macro. (cherry picked from commit 4ccf315)
1 parent f4d7327 commit 5de6ec1

19 files changed

+43
-34
lines changed

include/swift/Basic/Features.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,9 @@ EXPERIMENTAL_FEATURE(CImplementation, true)
385385
// Enable @sensitive attribute.
386386
EXPERIMENTAL_FEATURE(Sensitive, true)
387387

388+
// Enable the stdlib @DebugDescription macro.
389+
EXPERIMENTAL_FEATURE(DebugDescriptionMacro, false)
390+
388391
#undef EXPERIMENTAL_FEATURE_EXCLUDED_FROM_MODULE_INTERFACE
389392
#undef EXPERIMENTAL_FEATURE
390393
#undef UPCOMING_FEATURE

lib/AST/FeatureSet.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,8 @@ static bool usesFeatureSensitive(Decl *decl) {
710710
return decl->getAttrs().hasAttribute<SensitiveAttr>();
711711
}
712712

713+
UNINTERESTING_FEATURE(DebugDescriptionMacro)
714+
713715
// ----------------------------------------------------------------------------
714716
// MARK: - FeatureSet
715717
// ----------------------------------------------------------------------------

lib/Frontend/CompilerInvocation.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1538,6 +1538,10 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
15381538
Opts.DisableDynamicActorIsolation |=
15391539
Args.hasArg(OPT_disable_dynamic_actor_isolation);
15401540

1541+
// @DebugDescription uses @_section and @_used attributes.
1542+
if (Opts.hasFeature(Feature::DebugDescriptionMacro))
1543+
Opts.enableFeature(Feature::SymbolLinkageMarkers);
1544+
15411545
#if SWIFT_ENABLE_EXPERIMENTAL_PARSER_VALIDATION
15421546
/// Enable round trip parsing via the new swift parser unless it is disabled
15431547
/// explicitly. The new Swift parser can have mismatches with C++ parser -

stdlib/public/core/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ endif()
329329

330330
list(APPEND swift_stdlib_compile_flags "-external-plugin-path"
331331
"${swift_lib_dir}/swift/host/plugins#${swift_bin_dir}/swift-plugin-server")
332-
list(APPEND swift_stdlib_compile_flags "-enable-experimental-feature" "SymbolLinkageMarkers")
332+
list(APPEND swift_stdlib_compile_flags "-enable-experimental-feature" "DebugDescriptionMacro")
333333

334334
set(swift_core_incorporate_object_libraries)
335335
list(APPEND swift_core_incorporate_object_libraries swiftRuntime)

stdlib/public/core/DebuggerSupport.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import SwiftShims
1414

1515
// Macros are disabled when Swift is built without swift-syntax.
16-
#if $Macros && hasAttribute(attached)
16+
#if $Macros && $DebugDescriptionMacro && hasAttribute(attached)
1717

1818
/// Converts description definitions to a debugger Type Summary.
1919
///
@@ -65,10 +65,10 @@ import SwiftShims
6565
/// logic and computed properties are not supported.
6666
/// * Overloaded string interpolation cannot be used.
6767
@attached(memberAttribute)
68-
public macro _DebugDescription() =
68+
public macro DebugDescription() =
6969
#externalMacro(module: "SwiftMacros", type: "DebugDescriptionMacro")
7070

71-
/// Internal-only macro. See `@_DebugDescription`.
71+
/// Internal-only macro. See `@DebugDescription`.
7272
@attached(peer, names: named(_lldb_summary))
7373
public macro _DebugDescriptionProperty(_ debugIdentifier: String, _ computedProperties: [String]) =
7474
#externalMacro(module: "SwiftMacros", type: "_DebugDescriptionPropertyMacro")

stdlib/public/core/ObjectIdentifier+DebugDescription.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#if !$Embedded
14-
@_DebugDescription
14+
@DebugDescription
1515
extension ObjectIdentifier {
1616
var _debugDescription: String {
1717
return "ObjectIdentifier(\(_value))"

test/Macros/DebugDescription/error_complex_implementation.swift

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

6-
@_DebugDescription
6+
@DebugDescription
77
struct MyStruct {
88
var flag: Bool
99

test/Macros/DebugDescription/error_computed_properties.swift

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

6-
@_DebugDescription
6+
@DebugDescription
77
struct MyStruct {
88
var name: String { "thirty" }
99

test/Macros/DebugDescription/error_custom_interpolation.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ extension DefaultStringInterpolation {
88
fileprivate func appendInterpolation<A, B>(_ a: A, _ b: B) {}
99
}
1010

11-
@_DebugDescription
11+
@DebugDescription
1212
struct MyStruct1 {
1313
// expected-error @+1 {{unsupported custom string interpolation expression}}
1414
var debugDescription: String { "\(custom: 30)" }
1515
}
1616

17-
@_DebugDescription
17+
@DebugDescription
1818
struct MyStruct2 {
1919
// expected-error @+1 {{unsupported custom string interpolation expression}}
2020
var debugDescription: String { "\(30, true)" }

test/Macros/DebugDescription/error_interpolation_expression.swift

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

6-
@_DebugDescription
6+
@DebugDescription
77
struct MyStruct {
88
// expected-error @+1 {{only references to stored properties are allowed}}
99
var debugDescription: String { "\(1)" }

test/Macros/DebugDescription/error_protocol.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -verify -plugin-path %swift-plugin-dir
55

66
// expected-error @+1 {{cannot be attached to a protocol}}
7-
@_DebugDescription
7+
@DebugDescription
88
protocol MyProto {
99
func action()
1010
}

test/Macros/DebugDescription/explicit_self_property.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// REQUIRES: swift_swift_parser
22

33
// RUN: %empty-directory(%t)
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
4+
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -enable-experimental-feature DebugDescriptionMacro -plugin-path %swift-plugin-dir -dump-macro-expansions > %t/expansions-dump.txt 2>&1
55
// RUN: %FileCheck %s < %t/expansions-dump.txt
66

7-
@_DebugDescription
7+
@DebugDescription
88
struct MyStruct: CustomDebugStringConvertible {
99
var name: String = "thirty"
1010
var debugDescription: String { "name: \(self.name)" }
@@ -16,7 +16,7 @@ struct MyStruct: CustomDebugStringConvertible {
1616
// CHECK: /* "name: ${var.name}" */ 18 as UInt8, 110 as UInt8, 97 as UInt8, 109 as UInt8, 101 as UInt8, 58 as UInt8, 32 as UInt8, 36 as UInt8, 123 as UInt8, 118 as UInt8, 97 as UInt8, 114 as UInt8, 46 as UInt8, 110 as UInt8, 97 as UInt8, 109 as UInt8, 101 as UInt8, 125 as UInt8, 0 as UInt8
1717
// CHECK: )
1818

19-
@_DebugDescription
19+
@DebugDescription
2020
class MyClass: CustomDebugStringConvertible {
2121
var name: String = "thirty"
2222
var debugDescription: String { "name: \(self.name)" }

test/Macros/DebugDescription/extension.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// REQUIRES: swift_swift_parser
22

33
// RUN: %empty-directory(%t)
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
4+
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -enable-experimental-feature DebugDescriptionMacro -plugin-path %swift-plugin-dir -dump-macro-expansions > %t/expansions-dump.txt 2>&1
55
// RUN: %FileCheck %s < %t/expansions-dump.txt
66

77
struct MyStruct {}
88

9-
@_DebugDescription
9+
@DebugDescription
1010
extension MyStruct {
1111
var debugDescription: String { "thirty" }
1212
}

test/Macros/DebugDescription/implicit_self_property.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// REQUIRES: swift_swift_parser
22

33
// RUN: %empty-directory(%t)
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
4+
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -enable-experimental-feature DebugDescriptionMacro -plugin-path %swift-plugin-dir -dump-macro-expansions > %t/expansions-dump.txt 2>&1
55
// RUN: %FileCheck %s < %t/expansions-dump.txt
66

7-
@_DebugDescription
7+
@DebugDescription
88
struct MyStruct: CustomDebugStringConvertible {
99
var name: String = "thirty"
1010
var debugDescription: String { "name: \(name)" }
@@ -16,7 +16,7 @@ struct MyStruct: CustomDebugStringConvertible {
1616
// CHECK: /* "name: ${var.name}" */ 18 as UInt8, 110 as UInt8, 97 as UInt8, 109 as UInt8, 101 as UInt8, 58 as UInt8, 32 as UInt8, 36 as UInt8, 123 as UInt8, 118 as UInt8, 97 as UInt8, 114 as UInt8, 46 as UInt8, 110 as UInt8, 97 as UInt8, 109 as UInt8, 101 as UInt8, 125 as UInt8, 0 as UInt8
1717
// CHECK: )
1818

19-
@_DebugDescription
19+
@DebugDescription
2020
class MyClass: CustomDebugStringConvertible {
2121
var name: String = "thirty"
2222
var debugDescription: String { "name: \(name)" }

test/Macros/DebugDescription/linkage.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// REQUIRES: swift_swift_parser
22

33
// RUN: %empty-directory(%t)
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
4+
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -enable-experimental-feature DebugDescriptionMacro -plugin-path %swift-plugin-dir -dump-macro-expansions > %t/expansions-dump.txt 2>&1
55
// RUN: %FileCheck %s < %t/expansions-dump.txt
66

7-
@_DebugDescription
7+
@DebugDescription
88
struct MyStruct: CustomDebugStringConvertible {
99
var debugDescription: String { "thirty" }
1010
}

test/Macros/DebugDescription/long_string.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// REQUIRES: swift_swift_parser
22

33
// RUN: %empty-directory(%t)
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
4+
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -enable-experimental-feature DebugDescriptionMacro -plugin-path %swift-plugin-dir -dump-macro-expansions > %t/expansions-dump.txt 2>&1
55
// RUN: %FileCheck %s < %t/expansions-dump.txt
66

7-
@_DebugDescription
7+
@DebugDescription
88
struct MyStruct: CustomDebugStringConvertible {
99
var debugDescription: String {
1010
"""

test/Macros/DebugDescription/property_chain.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// REQUIRES: swift_swift_parser
22

33
// RUN: %empty-directory(%t)
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
4+
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -enable-experimental-feature DebugDescriptionMacro -plugin-path %swift-plugin-dir -dump-macro-expansions > %t/expansions-dump.txt 2>&1
55
// RUN: %FileCheck %s < %t/expansions-dump.txt
66

7-
@_DebugDescription
7+
@DebugDescription
88
struct MyStruct: CustomDebugStringConvertible {
99
var name: String = "thirty"
1010
var debugDescription: String { "\(self.name.count) \(name.count)" }
@@ -16,7 +16,7 @@ struct MyStruct: CustomDebugStringConvertible {
1616
// CHECK: /* "${var.name.count} ${var.name.count}" */ 36 as UInt8, 36 as UInt8, 123 as UInt8, 118 as UInt8, 97 as UInt8, 114 as UInt8, 46 as UInt8, 110 as UInt8, 97 as UInt8, 109 as UInt8, 101 as UInt8, 46 as UInt8, 99 as UInt8, 111 as UInt8, 117 as UInt8, 110 as UInt8, 116 as UInt8, 125 as UInt8, 32 as UInt8, 36 as UInt8, 123 as UInt8, 118 as UInt8, 97 as UInt8, 114 as UInt8, 46 as UInt8, 110 as UInt8, 97 as UInt8, 109 as UInt8, 101 as UInt8, 46 as UInt8, 99 as UInt8, 111 as UInt8, 117 as UInt8, 110 as UInt8, 116 as UInt8, 125 as UInt8, 0 as UInt8
1717
// CHECK: )
1818

19-
@_DebugDescription
19+
@DebugDescription
2020
class MyClass: CustomDebugStringConvertible {
2121
var name: String = "thirty"
2222
var debugDescription: String { "\(self.name.count) \(name.count)" }

test/Macros/DebugDescription/static_string.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// REQUIRES: swift_swift_parser
22

33
// RUN: %empty-directory(%t)
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
4+
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -enable-experimental-feature DebugDescriptionMacro -plugin-path %swift-plugin-dir -dump-macro-expansions > %t/expansions-dump.txt 2>&1
55
// RUN: %FileCheck %s < %t/expansions-dump.txt
66

7-
@_DebugDescription
7+
@DebugDescription
88
struct MyStruct: CustomDebugStringConvertible {
99
var debugDescription: String { "thirty" }
1010
}
@@ -15,7 +15,7 @@ struct MyStruct: CustomDebugStringConvertible {
1515
// CHECK: /* "thirty" */ 7 as UInt8, 116 as UInt8, 104 as UInt8, 105 as UInt8, 114 as UInt8, 116 as UInt8, 121 as UInt8, 0 as UInt8
1616
// CHECK: )
1717

18-
@_DebugDescription
18+
@DebugDescription
1919
class MyClass: CustomDebugStringConvertible {
2020
var debugDescription: String { "thirty" }
2121
}
@@ -26,7 +26,7 @@ class MyClass: CustomDebugStringConvertible {
2626
// CHECK: /* "thirty" */ 7 as UInt8, 116 as UInt8, 104 as UInt8, 105 as UInt8, 114 as UInt8, 116 as UInt8, 121 as UInt8, 0 as UInt8
2727
// CHECK: )
2828

29-
@_DebugDescription
29+
@DebugDescription
3030
class MyEnum: CustomDebugStringConvertible {
3131
var debugDescription: String { "thirty" }
3232
}

test/Macros/DebugDescription/supported_description.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// REQUIRES: swift_swift_parser
22

33
// RUN: %empty-directory(%t)
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
4+
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -enable-experimental-feature DebugDescriptionMacro -plugin-path %swift-plugin-dir -dump-macro-expansions > %t/expansions-dump.txt 2>&1
55
// RUN: %FileCheck %s < %t/expansions-dump.txt
66

7-
@_DebugDescription
7+
@DebugDescription
88
struct MyStruct1: CustomStringConvertible {
99
var description: String { "thirty" }
1010
}
@@ -15,7 +15,7 @@ struct MyStruct1: CustomStringConvertible {
1515
// CHECK: /* "thirty" */ 7 as UInt8, 116 as UInt8, 104 as UInt8, 105 as UInt8, 114 as UInt8, 116 as UInt8, 121 as UInt8, 0 as UInt8
1616
// CHECK: )
1717

18-
@_DebugDescription
18+
@DebugDescription
1919
struct MyStruct2: CustomDebugStringConvertible {
2020
var description: String { "thirty" }
2121
var debugDescription: String { "eleven" }
@@ -27,7 +27,7 @@ struct MyStruct2: CustomDebugStringConvertible {
2727
// CHECK: /* "eleven" */ 7 as UInt8, 101 as UInt8, 108 as UInt8, 101 as UInt8, 118 as UInt8, 101 as UInt8, 110 as UInt8, 0 as UInt8
2828
// CHECK: )
2929

30-
@_DebugDescription
30+
@DebugDescription
3131
struct MyStruct3: CustomDebugStringConvertible {
3232
var description: String { "thirty" }
3333
var debugDescription: String { "eleven" }

0 commit comments

Comments
 (0)