Skip to content

[Macros] Implement peer declaration macros with expansion #1196

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 3 commits into from
Jan 7, 2023

Conversation

DougGregor
Copy link
Member

@DougGregor DougGregor commented Jan 7, 2023

Peer declaration macros are applied to a declaration via an attribute,
but are responsible for generating "peer" declarations that go
alongside the declaration to which the attribute is attached.
Implement the addCompletionHandler example, which takes:

@addCompletionHandler
func f(a: Int, for b: String, _ value: Double) async -> String { }

and adds the following peer declaration:

func f(a: Int, for b: String, _ value: Double, completionHandler: (String) -> Void) {
  Task {
    completionHandler(await f(a: a, for: b, value))
  }
}

Peer declaration macros are applied to a declaration via an attribute,
but are responsible for generating "peer" declarations that go
alongside the declaration to which the attribute is attached.
Implement the `addCompletionHandler` example, which takes:

    @addCompletionHandler
    func f(a: Int, for b: String, _ value: Double) async -> String { }

and adds the following peer declaration:

    func f(a: Int, for b: String, _ value: Double,
completionHandler: (String) -> Void) {
      Task {
        completionHandler(await f(a: a, for: b, value))
      }
    }
This makes sure we eliminate the macro uses from the resulting source
file.
@DougGregor DougGregor requested a review from ahoppen as a code owner January 7, 2023 06:59
@DougGregor
Copy link
Member Author

@swift-ci please test

@@ -12,7 +12,6 @@

import SwiftSyntax
import SwiftParser
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like SwiftParser isn't needed here either

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, the macro protocols have a bunch of extra imports. I've cleaned them up locally.

@DougGregor
Copy link
Member Author

@swift-ci please test macOS

2 similar comments
@DougGregor
Copy link
Member Author

@swift-ci please test macOS

@DougGregor
Copy link
Member Author

@swift-ci please test macOS

@DougGregor DougGregor merged commit f5f45e2 into swiftlang:main Jan 7, 2023
@DougGregor DougGregor deleted the peer-declaration-macros branch January 7, 2023 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants