Skip to content

[Debugging] Add DebugDescriptionMacro experimental feature #73070

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/swift/Basic/Features.def
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,9 @@ EXPERIMENTAL_FEATURE(ObjCImplementation, true)
// Enable @implementation on @_cdecl functions.
EXPERIMENTAL_FEATURE(CImplementation, true)

// Enable the stdlib @DebugDescription macro.
EXPERIMENTAL_FEATURE(DebugDescriptionMacro, false)

#undef EXPERIMENTAL_FEATURE_EXCLUDED_FROM_MODULE_INTERFACE
#undef EXPERIMENTAL_FEATURE
#undef UPCOMING_FEATURE
Expand Down
2 changes: 2 additions & 0 deletions lib/AST/FeatureSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,8 @@ UNINTERESTING_FEATURE(IsolatedAny2)
UNINTERESTING_FEATURE(ObjCImplementation)
UNINTERESTING_FEATURE(CImplementation)

UNINTERESTING_FEATURE(DebugDescriptionMacro)

// ----------------------------------------------------------------------------
// MARK: - FeatureSet
// ----------------------------------------------------------------------------
Expand Down
4 changes: 4 additions & 0 deletions lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1513,6 +1513,10 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
}
}

// @DebugDescription uses @_section and @_used attributes.
if (Opts.hasFeature(Feature::DebugDescriptionMacro))
Opts.enableFeature(Feature::SymbolLinkageMarkers);

#if SWIFT_ENABLE_EXPERIMENTAL_PARSER_VALIDATION
/// Enable round trip parsing via the new swift parser unless it is disabled
/// explicitly. The new Swift parser can have mismatches with C++ parser -
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ endif()

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

set(swift_core_incorporate_object_libraries)
list(APPEND swift_core_incorporate_object_libraries swiftRuntime)
Expand Down
6 changes: 3 additions & 3 deletions stdlib/public/core/DebuggerSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import SwiftShims

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

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

/// Internal-only macro. See `@_DebugDescription`.
/// Internal-only macro. See `@DebugDescription`.
@attached(peer, names: named(_lldb_summary))
public macro _DebugDescriptionProperty(_ debugIdentifier: String, _ computedProperties: [String]) =
#externalMacro(module: "SwiftMacros", type: "_DebugDescriptionPropertyMacro")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//===----------------------------------------------------------------------===//

#if !$Embedded
@_DebugDescription
@DebugDescription
extension ObjectIdentifier {
var _debugDescription: String {
return "ObjectIdentifier(\(_value))"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -verify -plugin-path %swift-plugin-dir

@_DebugDescription
@DebugDescription
struct MyStruct {
var flag: Bool

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -verify -plugin-path %swift-plugin-dir

@_DebugDescription
@DebugDescription
struct MyStruct {
var name: String { "thirty" }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ extension DefaultStringInterpolation {
fileprivate func appendInterpolation<A, B>(_ a: A, _ b: B) {}
}

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

@_DebugDescription
@DebugDescription
struct MyStruct2 {
// expected-error @+1 {{unsupported custom string interpolation expression}}
var debugDescription: String { "\(30, true)" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -verify -plugin-path %swift-plugin-dir

@_DebugDescription
@DebugDescription
struct MyStruct {
// expected-error @+1 {{only references to stored properties are allowed}}
var debugDescription: String { "\(1)" }
Expand Down
2 changes: 1 addition & 1 deletion test/Macros/DebugDescription/error_protocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -verify -plugin-path %swift-plugin-dir

// expected-error @+1 {{cannot be attached to a protocol}}
@_DebugDescription
@DebugDescription
protocol MyProto {
func action()
}
6 changes: 3 additions & 3 deletions test/Macros/DebugDescription/explicit_self_property.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// REQUIRES: swift_swift_parser

// RUN: %empty-directory(%t)
// 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
// 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
// RUN: %FileCheck %s < %t/expansions-dump.txt

@_DebugDescription
@DebugDescription
struct MyStruct: CustomDebugStringConvertible {
var name: String = "thirty"
var debugDescription: String { "name: \(self.name)" }
Expand All @@ -16,7 +16,7 @@ struct MyStruct: CustomDebugStringConvertible {
// 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
// CHECK: )

@_DebugDescription
@DebugDescription
class MyClass: CustomDebugStringConvertible {
var name: String = "thirty"
var debugDescription: String { "name: \(self.name)" }
Expand Down
4 changes: 2 additions & 2 deletions test/Macros/DebugDescription/extension.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// REQUIRES: swift_swift_parser

// RUN: %empty-directory(%t)
// 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
// 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
// RUN: %FileCheck %s < %t/expansions-dump.txt

struct MyStruct {}

@_DebugDescription
@DebugDescription
extension MyStruct {
var debugDescription: String { "thirty" }
}
Expand Down
6 changes: 3 additions & 3 deletions test/Macros/DebugDescription/implicit_self_property.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// REQUIRES: swift_swift_parser

// RUN: %empty-directory(%t)
// 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
// 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
// RUN: %FileCheck %s < %t/expansions-dump.txt

@_DebugDescription
@DebugDescription
struct MyStruct: CustomDebugStringConvertible {
var name: String = "thirty"
var debugDescription: String { "name: \(name)" }
Expand All @@ -16,7 +16,7 @@ struct MyStruct: CustomDebugStringConvertible {
// 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
// CHECK: )

@_DebugDescription
@DebugDescription
class MyClass: CustomDebugStringConvertible {
var name: String = "thirty"
var debugDescription: String { "name: \(name)" }
Expand Down
4 changes: 2 additions & 2 deletions test/Macros/DebugDescription/linkage.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// REQUIRES: swift_swift_parser

// RUN: %empty-directory(%t)
// 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
// 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
// RUN: %FileCheck %s < %t/expansions-dump.txt

@_DebugDescription
@DebugDescription
struct MyStruct: CustomDebugStringConvertible {
var debugDescription: String { "thirty" }
}
Expand Down
4 changes: 2 additions & 2 deletions test/Macros/DebugDescription/long_string.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// REQUIRES: swift_swift_parser

// RUN: %empty-directory(%t)
// 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
// 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
// RUN: %FileCheck %s < %t/expansions-dump.txt

@_DebugDescription
@DebugDescription
struct MyStruct: CustomDebugStringConvertible {
var debugDescription: String {
"""
Expand Down
6 changes: 3 additions & 3 deletions test/Macros/DebugDescription/property_chain.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// REQUIRES: swift_swift_parser

// RUN: %empty-directory(%t)
// 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
// 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
// RUN: %FileCheck %s < %t/expansions-dump.txt

@_DebugDescription
@DebugDescription
struct MyStruct: CustomDebugStringConvertible {
var name: String = "thirty"
var debugDescription: String { "\(self.name.count) \(name.count)" }
Expand All @@ -16,7 +16,7 @@ struct MyStruct: CustomDebugStringConvertible {
// 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
// CHECK: )

@_DebugDescription
@DebugDescription
class MyClass: CustomDebugStringConvertible {
var name: String = "thirty"
var debugDescription: String { "\(self.name.count) \(name.count)" }
Expand Down
8 changes: 4 additions & 4 deletions test/Macros/DebugDescription/static_string.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// REQUIRES: swift_swift_parser

// RUN: %empty-directory(%t)
// 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
// 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
// RUN: %FileCheck %s < %t/expansions-dump.txt

@_DebugDescription
@DebugDescription
struct MyStruct: CustomDebugStringConvertible {
var debugDescription: String { "thirty" }
}
Expand All @@ -15,7 +15,7 @@ struct MyStruct: CustomDebugStringConvertible {
// 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
// CHECK: )

@_DebugDescription
@DebugDescription
class MyClass: CustomDebugStringConvertible {
var debugDescription: String { "thirty" }
}
Expand All @@ -26,7 +26,7 @@ class MyClass: CustomDebugStringConvertible {
// 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
// CHECK: )

@_DebugDescription
@DebugDescription
class MyEnum: CustomDebugStringConvertible {
var debugDescription: String { "thirty" }
}
Expand Down
8 changes: 4 additions & 4 deletions test/Macros/DebugDescription/supported_description.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// REQUIRES: swift_swift_parser

// RUN: %empty-directory(%t)
// 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
// 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
// RUN: %FileCheck %s < %t/expansions-dump.txt

@_DebugDescription
@DebugDescription
struct MyStruct1: CustomStringConvertible {
var description: String { "thirty" }
}
Expand All @@ -15,7 +15,7 @@ struct MyStruct1: CustomStringConvertible {
// 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
// CHECK: )

@_DebugDescription
@DebugDescription
struct MyStruct2: CustomDebugStringConvertible {
var description: String { "thirty" }
var debugDescription: String { "eleven" }
Expand All @@ -27,7 +27,7 @@ struct MyStruct2: CustomDebugStringConvertible {
// 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
// CHECK: )

@_DebugDescription
@DebugDescription
struct MyStruct3: CustomDebugStringConvertible {
var description: String { "thirty" }
var debugDescription: String { "eleven" }
Expand Down