Skip to content
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

[ASTGen] ParamDecl generation improvements #79456

Merged
merged 2 commits into from
Feb 19, 2025

Conversation

rintaro
Copy link
Member

@rintaro rintaro commented Feb 18, 2025

DefaultArgumentInitializer decl context for the default argument value.

Modified the flow in C++ parser too. It used to be:

  1. Create the initializer context when parsing the expression
  2. Remember the created initializers in DefaultArgumentInfo
  3. Construct ParamDecl without initContext
  4. Create FunctionDecl
  5. Set the initContext's parent via DefaultArgumentInitializer::changeFunction
  6. Set the ParamDecl.initContext in the same function

This seemed pretty complicated, especially when we can:

  1. Create the initializer context when parsing/generating the expression
  2. Construct ParamDecl with the initContext
  3. Make ParameterList::setDeclContextOfParamDecls set the initContext's parent too.

Generate attributes on ParamDecls

Simple independent change. We didn't generate and set the attributes on function parameters.

@rintaro
Copy link
Member Author

rintaro commented Feb 18, 2025

@swift-ci Please smoke test

Copy link
Contributor

@hamishknight hamishknight left a comment

Choose a reason for hiding this comment

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

Nice cleanup!

@@ -1515,10 +1514,6 @@ class Parser {
/// all the arguments, not just those that have default arguments.
unsigned claimNextIndex() { return NextIndex++; }
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like claimNextIndex is unused?

Copy link
Contributor

Choose a reason for hiding this comment

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

Would also be nice to see if we could remove HasDefaultArgument, seems like the diagnostic logic there could either be plumbed down or check the ParameterList itself

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, DefaultArgumentInfo does mostly nothing anymore. I guess HasDefaultArgument diagnostic can be sinked into TyoeCheckDeclPrimary. I will try it in followups, those diagnostics are needed in ASTGen mode too.

@rintaro
Copy link
Member Author

rintaro commented Feb 18, 2025

@swift-ci Pease smoke test

@rintaro
Copy link
Member Author

rintaro commented Feb 19, 2025

@swift-ci Please smoke test

@rintaro
Copy link
Member Author

rintaro commented Feb 19, 2025

@swift-ci please smoke test Linux

1 similar comment
@rintaro
Copy link
Member Author

rintaro commented Feb 19, 2025

@swift-ci please smoke test Linux

@rintaro rintaro enabled auto-merge February 19, 2025 20:55
@rintaro rintaro merged commit e5d5026 into swiftlang:main Feb 19, 2025
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