Skip to content

Commit 30145e9

Browse files
committed
[Macros] Remove nested peer macro expansion.
1 parent 3ddd25b commit 30145e9

File tree

2 files changed

+11
-18
lines changed

2 files changed

+11
-18
lines changed

lib/Sema/TypeCheckMacros.cpp

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -417,21 +417,13 @@ bool ExpandSynthesizedMemberMacroRequest::evaluate(Evaluator &evaluator,
417417
}
418418

419419
bool ExpandPeerMacroRequest::evaluate(Evaluator &evaluator, Decl *decl) const {
420-
SmallVector<Decl *, 2> peers;
420+
bool addedPeers = false;
421421
decl->forEachAttachedMacro(MacroRole::Peer,
422422
[&](CustomAttr *attr, MacroDecl *macro) {
423-
expandPeers(attr, macro, decl, peers);
423+
addedPeers |= expandPeers(attr, macro, decl);
424424
});
425425

426-
// Expand all peers that have attached peer macros.
427-
for (auto *peer : peers) {
428-
(void)evaluateOrDefault(
429-
evaluator,
430-
ExpandPeerMacroRequest{peer},
431-
false);
432-
}
433-
434-
return !peers.empty();
426+
return addedPeers;
435427
}
436428

437429
/// Determine whether the given source file is from an expansion of the given
@@ -1086,16 +1078,16 @@ bool swift::expandMembers(CustomAttr *attr, MacroDecl *macro, Decl *decl) {
10861078
return synthesizedMembers;
10871079
}
10881080

1089-
void swift::expandPeers(CustomAttr *attr, MacroDecl *macro, Decl *decl,
1090-
SmallVectorImpl<Decl *> &peers) {
1081+
bool swift::expandPeers(CustomAttr *attr, MacroDecl *macro, Decl *decl) {
10911082
auto macroSourceFile = evaluateAttachedMacro(macro, decl, attr,
10921083
/*passParentContext*/false,
10931084
MacroRole::Peer);
10941085
if (!macroSourceFile)
1095-
return;
1086+
return false;
10961087

10971088
PrettyStackTraceDecl debugStack("applying expanded peer macro", decl);
10981089

1090+
bool addedPeers = false;
10991091
auto *parent = decl->getDeclContext();
11001092
auto topLevelDecls = macroSourceFile->getTopLevelDecls();
11011093
for (auto peer : topLevelDecls) {
@@ -1110,8 +1102,10 @@ void swift::expandPeers(CustomAttr *attr, MacroDecl *macro, Decl *decl,
11101102
continue;
11111103
}
11121104

1113-
peers.push_back(peer);
1105+
addedPeers = true;
11141106
}
1107+
1108+
return addedPeers;
11151109
}
11161110

11171111
MacroDecl *

lib/Sema/TypeCheckMacros.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,8 @@ bool expandMembers(CustomAttr *attr, MacroDecl *macro, Decl *decl);
6767
/// Expand the peer declarations for the given declaration based on
6868
/// the custom attribute that references the given macro.
6969
///
70-
/// Populates the \c peers vector with the expanded peer declarations.
71-
void expandPeers(CustomAttr *attr, MacroDecl *macro, Decl *decl,
72-
SmallVectorImpl<Decl *> &peers);
70+
/// Returns \c true if the macro added new peers, \c false otherwise.
71+
bool expandPeers(CustomAttr *attr, MacroDecl *macro, Decl *decl);
7372

7473
} // end namespace swift
7574

0 commit comments

Comments
 (0)