Skip to content

[Macros] Expression macro as caller-side default argument #70602

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

Conversation

ApolloZhu
Copy link
Contributor

@ApolloZhu ApolloZhu commented Dec 22, 2023

Implementation for [Pitch] Expression macro as caller-side default argument

Corresponding Swift Syntax PR: swiftlang/swift-syntax#2447

Resolves rdar://112031348

@ApolloZhu ApolloZhu self-assigned this Dec 22, 2023
@ApolloZhu ApolloZhu force-pushed the macro/expression-as-default-argument branch from 21938c9 to b2baf7c Compare January 9, 2024 01:34
@ApolloZhu ApolloZhu requested review from DougGregor, hborla, ahoppen and CodaFi and removed request for CodaFi January 13, 2024 00:40
@ApolloZhu
Copy link
Contributor Author

@swift-ci please smoke test

@ApolloZhu ApolloZhu marked this pull request as ready for review January 13, 2024 00:43
@ApolloZhu ApolloZhu changed the title Expression macro as caller-side default argument [Macros] Expression macro as caller-side default argument Jan 13, 2024
@ApolloZhu
Copy link
Contributor Author

@swift-ci please smoke test

@ApolloZhu ApolloZhu force-pushed the macro/expression-as-default-argument branch from 248e821 to 594d56b Compare January 17, 2024 00:36
@ApolloZhu
Copy link
Contributor Author

@swift-ci please smoke test

@ApolloZhu ApolloZhu requested a review from artemcm as a code owner January 23, 2024 00:38
Copy link
Member

@DougGregor DougGregor left a comment

Choose a reason for hiding this comment

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

This is looking very good. There are a few tests we still need:

  • One that serializes a public function using a default argument that's a macro expansion, then calls it from another module
  • One that prints an API with a public function containing such a default argument into a .swiftinterface fiel
  • One that checks the access control restrictions on the macros that can be used from a default argument

@DougGregor
Copy link
Member

swiftlang/swift-syntax#2447
@swift-ci Please build toolchain

@DougGregor
Copy link
Member

This will also make #isolation usable as a default argument without further work

@DougGregor
Copy link
Member

@swift-ci please build toolchain

@DougGregor
Copy link
Member

swiftlang/swift-syntax#2447
@swift-ci Please smoke test

Test shadowed variable of same type

Fully type check caller side macro expansion

Skip macro default arg caller side expr at decl primary

Test macro expand more complex expressions

Set synthesized expression as implicit

Add test case for with argument, not compiling currently

Test with swiftinterface

Always use the string representation of the default argument

Now works across module boundary

Check works for multiple files

Make default argument expression work in single file

Use expected-error

Disallow expression macro as default argument

Using as a sub expression in default argument still allowed as expression macros behave the same as built-in magic literals
Need to use variable from caller side context
@ApolloZhu ApolloZhu force-pushed the macro/expression-as-default-argument branch from 44aed25 to 8da4b1e Compare February 7, 2024 00:58
@ApolloZhu
Copy link
Contributor Author

swiftlang/swift-syntax#2447
@swift-ci Please smoke test

@ApolloZhu
Copy link
Contributor Author

swiftlang/swift-syntax#2447
@swift-ci Please build toolchain

@ApolloZhu ApolloZhu requested a review from DougGregor February 7, 2024 01:02
@DougGregor DougGregor merged commit 81ffafd into swiftlang:main Feb 15, 2024
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