Skip to content

[Rename] Also syntactically rename a macro’s definition #65399

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
Apr 25, 2023

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Apr 24, 2023

Previously we were skipping the macro’s definition (i.e. the part after = in a macro declaration if it wasn’t type checked. Since syntactic rename doesn’t type-check anything, it was thus skippin the macro definition. Add a flag to ASTWalker that allows NameMatcher to opt-out of this behavior.

rdar://108391854

Previously we were skipping the macro’s definition (i.e. the part after `=` in a macro declaration if it wasn’t type checked. Since syntactic rename doesn’t type-check anything, it was thus skippin the macro definition. Add a flag to `ASTWalker` that allows `NameMatcher` to opt-out of this behavior.
@ahoppen
Copy link
Member Author

ahoppen commented Apr 24, 2023

@swift-ci Please smoke test

@ahoppen
Copy link
Member Author

ahoppen commented Apr 24, 2023

@swift-ci Please smoke test Linux

@@ -425,7 +425,8 @@ class Traversal : public ASTVisitor<Traversal, Expr*, Stmt*,
if (auto def = MD->definition) {
// Don't walk into unchecked definitions.
if (auto expansion = dyn_cast<MacroExpansionExpr>(def)) {
if (!expansion->getType().isNull()) {
if (!expansion->getType().isNull() ||
Walker.shouldWalkIntoUncheckedMacroDefinitions()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I suppose this is safer, but do you know what expansion->getType().isNull() was added for? We can walk over un-typechecked ASTs, so it seems like clients should be checking this instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

It was added in aac0406. @DougGregor Do you remember why you added it?

Copy link
Member Author

Choose a reason for hiding this comment

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

@DougGregor and I just chatted about it and he added this check because of a verified crash and thinks that we can fix it in a more principled way than what he did.

I’m going to merge this as-is because it’s a low-risk change this way that we can cherry-pick to 5.9 and will provide a better fix in a follow-up PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

Tracking as rdar://108560477 for reference.

@xedin xedin removed their request for review April 25, 2023 17:20
@ahoppen
Copy link
Member Author

ahoppen commented Apr 25, 2023

@swift-ci Please smoke test

@ahoppen ahoppen merged commit bfe975d into swiftlang:main Apr 25, 2023
@ahoppen ahoppen deleted the ahoppen/rename-macro-definition branch April 25, 2023 22:16
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