Skip to content

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

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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions include/swift/AST/ASTWalker.h
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,10 @@ class ASTWalker {
/// TODO: Consider changing this to false by default.
virtual bool shouldWalkSerializedTopLevelInternalDecls() { return true; }

/// Whether to walk into the definition of a \c MacroDecl if it hasn't been
/// type-checked yet.
virtual bool shouldWalkIntoUncheckedMacroDefinitions() { return false; }

/// walkToParameterListPre - This method is called when first visiting a
/// ParameterList, before walking into its parameters.
///
Expand Down
1 change: 1 addition & 0 deletions include/swift/IDE/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ class NameMatcher: public ASTWalker {
PreWalkAction walkToTypeReprPre(TypeRepr *T) override;
PreWalkResult<Pattern *> walkToPatternPre(Pattern *P) override;
bool shouldWalkIntoGenericParams() override { return true; }
bool shouldWalkIntoUncheckedMacroDefinitions() override { return true; }

PreWalkResult<ArgumentList *>
walkToArgumentListPre(ArgumentList *ArgList) override;
Expand Down
3 changes: 2 additions & 1 deletion lib/AST/ASTWalker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
if (auto newDef = doIt(def))
MD->definition = newDef;
else
Expand Down
11 changes: 11 additions & 0 deletions test/refactoring/SyntacticRename/macro-definition.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// RUN: %empty-directory(%t.ranges)
// RUN: %refactor -find-rename-ranges -source-filename %s -pos="test" -is-function-like -old-name "StringifyMacro" | %FileCheck %s

// CHECK: struct /*test:def*/<base>StringifyMacro</base> {}
// CHECK: @freestanding(expression)
// CHECK: macro stringify<T>(_ value: T) -> (T, String) = #externalMacro(module: "MyMacroMacros", type: "/*test:ref*/<base>StringifyMacro</base>")

struct /*test:def*/StringifyMacro {}

@freestanding(expression)
macro stringify<T>(_ value: T) -> (T, String) = #externalMacro(module: "MyMacroMacros", type: "/*test:ref*/StringifyMacro")