Skip to content

[ASTGen] Generate MacroDecl #77412

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
Nov 15, 2024
Merged

[ASTGen] Generate MacroDecl #77412

merged 3 commits into from
Nov 15, 2024

Conversation

rintaro
Copy link
Member

@rintaro rintaro commented Nov 6, 2024

Also basic macro role attributes.

@rintaro rintaro force-pushed the astgen-macrodecl branch 5 times, most recently from 5cf4eb6 to f8f3651 Compare November 11, 2024 22:02
@rintaro
Copy link
Member Author

rintaro commented Nov 11, 2024

@swift-ci Please smoke test

@rintaro rintaro force-pushed the astgen-macrodecl branch 3 times, most recently from b01701b to 643570b Compare November 13, 2024 18:01
@rintaro
Copy link
Member Author

rintaro commented Nov 13, 2024

@swift-ci Please smoke test

@rintaro
Copy link
Member Author

rintaro commented Nov 14, 2024

@swift-ci Please smoke test

@rintaro rintaro marked this pull request as ready for review November 14, 2024 04:33
@rintaro
Copy link
Member Author

rintaro commented Nov 14, 2024

@swift-ci Please smoke test

Comment on lines 397 to 401
case BridgedMacroRoleNone:
break;
}
assert(false && "invalid macro role");
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Will this compile in a no-asserts build? Should this be llvm_unreachable instead?

let type = self.generate(type: node.attributeName)

let argList: BridgedArgumentList?
if let args = node.arguments {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if let args = node.arguments {
if let args = node.arguments {

Comment on lines +1179 to +1181
if !self.declContext.isLocalContext && initContext == nil {
initContext = BridgedPatternBindingInitializer.create(declContext: self.declContext)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This reminds me, currently we create these even when attached to non-PatternBindingDecls :( This crashes (rdar://100585434):

@attached(member)
macro M<T>(_ x: T) = #externalMacro(module: "", type: "")

@M({})
struct S {}

Not to be solved in this PR though 😄

Copy link
Member Author

Choose a reason for hiding this comment

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

Huh. Do we only need it for PBD? If so, I think we should just pre-create PatternBindingInitializer when generating PatternBindingDecl if it has any attributes or initializers, and generate the attributes and the initializers with withDeclContext

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe we need some local context to contextualize closures for the non-PatternBindingDecl cases, but it can't be PatternBindingInitializer, we probably need a new kind of context (or maybe we could rework PatternBindingInitializer such that it doesn't assume it's on a PBD).

Copy link
Member Author

Choose a reason for hiding this comment

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

I see let me leave this as is for now :)

@rintaro
Copy link
Member Author

rintaro commented Nov 14, 2024

@swift-ci Please smoke test

@rintaro rintaro enabled auto-merge November 14, 2024 23:11
@rintaro rintaro merged commit 03319e5 into swiftlang:main Nov 15, 2024
3 checks passed
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