Skip to content

[ASTGen] Generate anonymous closure parameters #79232

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
Feb 10, 2025

Conversation

rintaro
Copy link
Member

@rintaro rintaro commented Feb 8, 2025

E.g. $0
Unlike C++ parser, scan the body for $n references upfront to create ParameterList, before generating the body.

@rintaro
Copy link
Member Author

rintaro commented Feb 8, 2025

@swift-ci Please smoke test

@rintaro rintaro force-pushed the astgen-closure-anonparam branch from b6fa326 to cb049d8 Compare February 8, 2025 03:40
@rintaro
Copy link
Member Author

rintaro commented Feb 8, 2025

@swift-ci Please smoke test

Comment on lines +138 to +139
return llvm::isa_and_present<swift::ClosureExpr>(
llvm::dyn_cast<swift::AbstractClosureExpr>(dc.unbridged()));
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 you should be able to directly check for ClosureExpr since that implements classof for DeclContext

Comment on lines +143 to +144
return llvm::cast<swift::ClosureExpr>(
llvm::cast<swift::AbstractClosureExpr>(dc.unbridged()));
Copy link
Contributor

Choose a reason for hiding this comment

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

Same

Comment on lines +317 to +329
let param = BridgedParamDecl.createParsed(
self.ctx,
declContext: expr.asDeclContext,
specifierLoc: nil,
argName: nil,
argNameLoc: nil,
paramName: ctx.getDollarIdentifier(idx),
paramNameLoc: loc,
type: nil,
defaultValue: nil
)
param.setSpecifier(.default)
param.setImplicit()
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO it would be nicer to expose a createImplicit method, but I don't feel too strongly about it

Comment on lines +1237 to +1239
case UInt8(ascii: "0")...UInt8(ascii: "9"):
let digit = Int(c &- UInt8(ascii: "0"))
result = result * 10 + digit
Copy link
Contributor

Choose a reason for hiding this comment

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

Huh TIL we allow $0001

Copy link
Contributor

Choose a reason for hiding this comment

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

oh no

Copy link
Member Author

Choose a reason for hiding this comment

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

Even $0000 😅

@rintaro rintaro merged commit 04b2174 into swiftlang:main Feb 10, 2025
3 checks passed
@rintaro
Copy link
Member Author

rintaro commented Feb 10, 2025

Let me address the review comments in followups

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.

3 participants