Skip to content

[Macros] Opaque params in expansion functions in macro protocols #1774

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
Jun 14, 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
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,9 @@ public protocol AccessorMacro: AttachedMacro {
/// Expand a macro that's expressed as a custom attribute attached to
/// the given declaration. The result is a set of accessors for the
/// declaration.
static func expansion<
Context: MacroExpansionContext,
Declaration: DeclSyntaxProtocol
>(
static func expansion(
of node: AttributeSyntax,
providingAccessorsOf declaration: Declaration,
in context: Context
providingAccessorsOf declaration: some DeclSyntaxProtocol,
in context: some MacroExpansionContext
) throws -> [AccessorDeclSyntax]
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@ import SwiftSyntax
public protocol CodeItemMacro: FreestandingMacro {
/// Expand a macro described by the given freestanding macro expansion
/// declaration within the given context to produce a set of declarations.
static func expansion<
Node: FreestandingMacroExpansionSyntax,
Context: MacroExpansionContext
>(
of node: Node,
in context: Context
static func expansion(
of node: some FreestandingMacroExpansionSyntax,
in context: some MacroExpansionContext
) throws -> [CodeBlockItemSyntax]
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,9 @@ public protocol ConformanceMacro: AttachedMacro {
/// - Returns: the set of `(type, where-clause?)` pairs that each provide the
/// protocol type to which the declared type conforms, along with
/// an optional where clause.
static func expansion<
Declaration: DeclGroupSyntax,
Context: MacroExpansionContext
>(
static func expansion(
of node: AttributeSyntax,
providingConformancesOf declaration: Declaration,
in context: Context
providingConformancesOf declaration: some DeclGroupSyntax,
in context: some MacroExpansionContext
) throws -> [(TypeSyntax, GenericWhereClauseSyntax?)]
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,9 @@ import SwiftSyntax
public protocol DeclarationMacro: FreestandingMacro {
/// Expand a macro described by the given freestanding macro expansion
/// declaration within the given context to produce a set of declarations.
static func expansion<
Node: FreestandingMacroExpansionSyntax,
Context: MacroExpansionContext
>(
of node: Node,
in context: Context
static func expansion(
of node: some FreestandingMacroExpansionSyntax,
in context: some MacroExpansionContext
) throws -> [DeclSyntax]

/// Whether to copy attributes on the expansion syntax to expanded declarations,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@ import SwiftSyntax
public protocol ExpressionMacro: FreestandingMacro {
/// Expand a macro described by the given freestanding macro expansion
/// within the given context to produce a replacement expression.
static func expansion<
Node: FreestandingMacroExpansionSyntax,
Context: MacroExpansionContext
>(
of node: Node,
in context: Context
static func expansion(
of node: some FreestandingMacroExpansionSyntax,
in context: some MacroExpansionContext
) throws -> ExprSyntax
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,10 @@ public protocol MemberAttributeMacro: AttachedMacro {
/// - context: The context in which to perform the macro expansion.
///
/// - Returns: the set of attributes to apply to the given member.
static func expansion<
Declaration: DeclGroupSyntax,
MemberDeclaration: DeclSyntaxProtocol,
Context: MacroExpansionContext
>(
static func expansion(
of node: AttributeSyntax,
attachedTo declaration: Declaration,
providingAttributesFor member: MemberDeclaration,
in context: Context
attachedTo declaration: some DeclGroupSyntax,
providingAttributesFor member: some DeclSyntaxProtocol,
in context: some MacroExpansionContext
) throws -> [AttributeSyntax]
}
9 changes: 3 additions & 6 deletions Sources/SwiftSyntaxMacros/MacroProtocols/MemberMacro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,9 @@ public protocol MemberMacro: AttachedMacro {
///
/// - Returns: the set of member declarations introduced by this macro, which
/// are nested inside the `attachedTo` declaration.
static func expansion<
Declaration: DeclGroupSyntax,
Context: MacroExpansionContext
>(
static func expansion(
of node: AttributeSyntax,
providingMembersOf declaration: Declaration,
in context: Context
providingMembersOf declaration: some DeclGroupSyntax,
in context: some MacroExpansionContext
) throws -> [DeclSyntax]
}
9 changes: 3 additions & 6 deletions Sources/SwiftSyntaxMacros/MacroProtocols/PeerMacro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,9 @@ public protocol PeerMacro: AttachedMacro {
///
/// The macro expansion can introduce "peer" declarations that sit alongside
/// the given declaration.
static func expansion<
Context: MacroExpansionContext,
Declaration: DeclSyntaxProtocol
>(
static func expansion(
of node: AttributeSyntax,
providingPeersOf declaration: Declaration,
in context: Context
providingPeersOf declaration: some DeclSyntaxProtocol,
in context: some MacroExpansionContext
) throws -> [DeclSyntax]
}