Skip to content

[Refactoring] Several improvements to memberwise initializer generation #58718

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

ahoppen
Copy link
Member

@ahoppen ahoppen commented May 6, 2022

Generating a memberwise init would skip over properties with property wrappers. Switch the implementation of memberwise init generation closer to the one that generates the implicit memberwise init by also using getMembers() instead of getStoredProperties().


If type has no memberwise initializable members, generate an empty initializer instead of failing.


Previously, we were dropping backticks, which might lead to invalid code if the type member was a keyword. Maintain any backticks from type members in the generated memberwise initializer.

rdar://89057767
rdar://81888671

@ahoppen ahoppen requested a review from bnbarham May 6, 2022 17:26
@ahoppen
Copy link
Member Author

ahoppen commented May 6, 2022

@swift-ci Please smoke test

ahoppen added 2 commits May 6, 2022 19:55
…ise init

Generating a memberwise init would skip over properties with property wrappers. Switch the implementation of memberwise init generation closer to the one that generates the implicit memberwise init by also using `getMembers()` instead of `getStoredProperties()`.

rdar://89057767
@ahoppen ahoppen force-pushed the pr/generate-memberwise-property-wrapper branch from 4ad16cd to 8862e01 Compare May 6, 2022 18:04
@ahoppen
Copy link
Member Author

ahoppen commented May 6, 2022

@swift-ci Please smoke test

…mberwise initializer

Previously, we were dropping backticks, which might lead to invalid code if the type member was a keyword.

rdar://81888671
@ahoppen ahoppen changed the title [Refactoring] Add members with property wrappers to generated memberwise init [Refactoring] Several improvements to memberwise initializer generation May 6, 2022
@@ -3147,26 +3147,24 @@ bool RefactoringActionLocalizeString::performChange() {
}

struct MemberwiseParameter {
Identifier Name;
CharSourceRange NameRange;
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if Identifier should have a bit for whether it needs backticks or not. I think there's a bunch of bugs involving not adding backticks and it'd be nice if we instead had a method in Identifier that would get the actual text for the name.

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 don’t think it should because we use pointer equality to compare Identifiers and we want to consider two identifiers identical even if one has backticks and the other doesn’t. In general, I think the usual compilation doesn’t care about backticks, it’s only us who care.

Copy link
Contributor

Choose a reason for hiding this comment

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

That's true. Just seems so wrong that we have to extract text here.

@bnbarham
Copy link
Contributor

bnbarham commented May 6, 2022

LGTM. I find it weird that we provide defaults for ! but given there's a whole bunch of tests for it... I assume we had some reason?

@bnbarham
Copy link
Contributor

bnbarham commented May 6, 2022

Oh - one more test you could add is for a member with get/set.

@ahoppen
Copy link
Member Author

ahoppen commented May 8, 2022

@swift-ci Please smoke test

@ahoppen ahoppen merged commit 379ad6c into swiftlang:main May 9, 2022
@ahoppen ahoppen deleted the pr/generate-memberwise-property-wrapper branch May 9, 2022 15:05
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