Skip to content

[Debug] Remove temp workaround in DebugDescriptionMacro #70746

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
Merged
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
28 changes: 0 additions & 28 deletions lib/Macros/Sources/SwiftMacros/DebugDescriptionMacro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import SwiftSyntax
import SwiftSyntaxMacros
import SwiftDiagnostics
import _StringProcessing // for String.contains(_:)

public enum DebugDescriptionMacro {}
public enum _DebugDescriptionPropertyMacro {}
Expand Down Expand Up @@ -51,18 +50,6 @@ extension DebugDescriptionMacro: MemberAttributeMacro {
return []
}

// Expansion is performed multiple times. Exit early to avoid emitting duplicate macros,
// which leads to duplicate symbol errors. To distinguish been invocations, inspect the
// current mangled name. This ignores the invocation that adds a "__vg" suffix to the member
// name, ex "description__vg". See https://github.com/apple/swift/pull/65559.
let mangledName = context.makeUniqueName("").text
let substring = "\(propertyName)__vg"
// Ex: "15description__vg"
let runlengthSubstring = "\(substring.count)\(substring)"
guard !mangledName.hasSubstring(runlengthSubstring) else {
return []
}

var properties: [String: PatternBindingSyntax] = [:]
for member in declaration.memberBlock.members {
for binding in member.decl.as(VariableDeclSyntax.self)?.bindings ?? [] {
Expand Down Expand Up @@ -501,18 +488,3 @@ extension Collection {
count == 1 ? first : nil
}
}

extension String {
fileprivate func hasSubstring(_ substring: String) -> Bool {
if #available(macOS 13, *) {
return self.contains(substring)
}

for index in self.indices {
if self.suffix(from: index).hasPrefix(substring) {
return true
}
}
return false
}
}