Skip to content

[Macros] Remove the ConformanceMacro protocol. #2009

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 1 commit into from
Aug 7, 2023
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
11 changes: 7 additions & 4 deletions Examples/Sources/ExamplePlugin/Macros.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,16 @@ struct MemberDeprecatedMacro: MemberAttributeMacro {
}

/// Add 'Equatable' conformance.
struct EquatableConformanceMacro: ConformanceMacro {
struct EquatableConformanceMacro: ExtensionMacro {
static func expansion(
of node: AttributeSyntax,
providingConformancesOf declaration: some DeclGroupSyntax,
attachedTo declaration: some DeclGroupSyntax,
providingExtensionsOf type: some TypeSyntaxProtocol,
conformingTo protocols: [TypeSyntax],
in context: some MacroExpansionContext
) throws -> [(TypeSyntax, GenericWhereClauseSyntax?)] {
return [("Equatable", nil)]
) throws -> [ExtensionDeclSyntax] {
let ext: DeclSyntax = "extension \(type.trimmed): Equatable {}"
return [ext.cast(ExtensionDeclSyntax.self)]
}
}

Expand Down
1 change: 0 additions & 1 deletion Sources/SwiftSyntaxMacros/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ add_swift_host_library(SwiftSyntaxMacros
MacroProtocols/AccessorMacro.swift
MacroProtocols/AttachedMacro.swift
MacroProtocols/CodeItemMacro.swift
MacroProtocols/ConformanceMacro.swift
MacroProtocols/DeclarationMacro.swift
MacroProtocols/ExpressionMacro.swift
MacroProtocols/ExtensionMacro.swift
Expand Down
68 changes: 0 additions & 68 deletions Sources/SwiftSyntaxMacros/MacroProtocols/ConformanceMacro.swift

This file was deleted.

49 changes: 0 additions & 49 deletions Tests/SwiftSyntaxMacroExpansionTest/MacroSystemTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -642,16 +642,6 @@ public struct DeclsFromStringsMacro: DeclarationMacro, MemberMacro {
}
}

public struct SendableConformanceMacro: ConformanceMacro {
public static func expansion(
of node: AttributeSyntax,
providingConformancesOf declaration: some DeclGroupSyntax,
in context: some MacroExpansionContext
) throws -> [(TypeSyntax, GenericWhereClauseSyntax?)] {
return [("Sendable", nil)]
}
}

public struct SendableExtensionMacro: ExtensionMacro {
public static func expansion(
of node: AttributeSyntax,
Expand Down Expand Up @@ -717,7 +707,6 @@ public let testMacros: [String: Macro.Type] = [
"wrapStoredProperties": WrapStoredProperties.self,
"customTypeWrapper": CustomTypeWrapperMacro.self,
"unwrap": UnwrapMacro.self,
"AddSendable": SendableConformanceMacro.self,
"AddSendableExtension": SendableExtensionMacro.self,
]

Expand Down Expand Up @@ -1537,44 +1526,6 @@ final class MacroSystemTests: XCTestCase {
)
}

func testConformanceExpansion() {
assertMacroExpansion(
"""
@AddSendable
struct MyType {
}
""",
expandedSource: """

struct MyType {
}

extension MyType: Sendable {
}
""",
macros: testMacros,
indentationWidth: indentationWidth
)

assertMacroExpansion(
"""
@AddSendable
extension A.B {
}
""",
expandedSource: """

extension A.B {
}

extension A.B: Sendable {
}
""",
macros: testMacros,
indentationWidth: indentationWidth
)
}

func testExtensionExpansion() {
assertMacroExpansion(
"""
Expand Down