Skip to content

Commit 1fd61a3

Browse files
committed
Remove support for looking up names in nested expansions.
1 parent c896530 commit 1fd61a3

File tree

10 files changed

+9
-106
lines changed

10 files changed

+9
-106
lines changed

include/swift/AST/Decl.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8476,7 +8476,6 @@ class MacroExpansionDecl : public Decl {
84768476
ArgumentList *getArgs() const { return ArgList; }
84778477
void setArgs(ArgumentList *args) { ArgList = args; }
84788478
ArrayRef<ASTNode> getRewritten() const;
8479-
ArrayRef<ASTNode> getFlattenedExpansion() const;
84808479
ConcreteDeclRef getMacroRef() const { return macroRef; }
84818480
void setMacroRef(ConcreteDeclRef ref) { macroRef = ref; }
84828481

include/swift/AST/TypeCheckRequests.h

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3828,23 +3828,6 @@ class ExpandMacroExpansionDeclRequest
38283828
bool isCached() const { return true; }
38293829
};
38303830

3831-
class RecursivelyExpandMacroExpansionDeclRequest
3832-
: public SimpleRequest<RecursivelyExpandMacroExpansionDeclRequest,
3833-
ArrayRef<ASTNode>(MacroExpansionDecl *),
3834-
RequestFlags::Cached> {
3835-
public:
3836-
using SimpleRequest::SimpleRequest;
3837-
3838-
private:
3839-
friend SimpleRequest;
3840-
3841-
ArrayRef<ASTNode>
3842-
evaluate(Evaluator &evaluator, MacroExpansionDecl *med) const;
3843-
3844-
public:
3845-
bool isCached() const { return true; }
3846-
};
3847-
38483831
/// Expand all accessor macros attached to the given declaration.
38493832
///
38503833
/// Produces the set of macro expansion buffer IDs.

include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -431,9 +431,6 @@ SWIFT_REQUEST(TypeChecker, ExternalMacroDefinitionRequest,
431431
SWIFT_REQUEST(TypeChecker, ExpandMacroExpansionDeclRequest,
432432
ArrayRef<ASTNode> (MacroExpansionDecl *),
433433
Cached, NoLocationInfo)
434-
SWIFT_REQUEST(TypeChecker, RecursivelyExpandMacroExpansionDeclRequest,
435-
ArrayRef<ASTNode> (MacroExpansionDecl *),
436-
Cached, NoLocationInfo)
437434
SWIFT_REQUEST(TypeChecker, ExpandMemberAttributeMacros,
438435
ArrayRef<unsigned>(Decl *),
439436
Cached, NoLocationInfo)

lib/AST/Decl.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10010,13 +10010,6 @@ ArrayRef<ASTNode> MacroExpansionDecl::getRewritten() const {
1001010010
ExpandMacroExpansionDeclRequest{mutableThis}, {});
1001110011
}
1001210012

10013-
ArrayRef<ASTNode> MacroExpansionDecl::getFlattenedExpansion() const {
10014-
auto mutableThis = const_cast<MacroExpansionDecl *>(this);
10015-
return evaluateOrDefault(
10016-
getASTContext().evaluator,
10017-
RecursivelyExpandMacroExpansionDeclRequest{mutableThis}, {});
10018-
}
10019-
1002010013
NominalTypeDecl *
1002110014
ValueDecl::getRuntimeDiscoverableAttrTypeDecl(CustomAttr *attr) const {
1002210015
auto &ctx = getASTContext();

lib/AST/Module.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3812,9 +3812,9 @@ void FileUnit::getExpandedTopLevelDecls(SmallVectorImpl<Decl*> &results) const {
38123812
getTopLevelDecls(nonExpandedDecls);
38133813
for (auto *decl : nonExpandedDecls) {
38143814
if (auto *med = dyn_cast<MacroExpansionDecl>(decl)) {
3815-
for (auto node : med->getFlattenedExpansion())
3816-
if (auto *decl = node.dyn_cast<Decl *>())
3817-
results.push_back(decl);
3815+
med->visitAuxiliaryDecls([&](Decl *decl) {
3816+
results.push_back(decl);
3817+
});
38183818
} else {
38193819
results.push_back(decl);
38203820
}

lib/AST/NameLookup.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,9 +1514,9 @@ populateLookupTableEntryFromMacroExpansions(ASTContext &ctx,
15141514
DeclName name,
15151515
NominalTypeDecl *dc) {
15161516
auto expandAndPopulate = [&](MacroExpansionDecl *med) {
1517-
for (auto node : med->getFlattenedExpansion())
1518-
if (auto *decl = node.dyn_cast<Decl *>())
1519-
table.addMember(decl);
1517+
med->visitAuxiliaryDecls([&](Decl *decl) {
1518+
table.addMember(decl);
1519+
});
15201520
};
15211521

15221522
for (auto *member : dc->getCurrentMembersWithoutLoading()) {

lib/Sema/TypeCheckDecl.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2840,9 +2840,9 @@ static ArrayRef<Decl *> evaluateMembersRequest(
28402840
}
28412841

28422842
if (auto *med = dyn_cast<MacroExpansionDecl>(member)) {
2843-
for (auto node : med->getFlattenedExpansion())
2844-
if (auto *decl = node.dyn_cast<Decl *>())
2845-
result.push_back(decl);
2843+
med->visitAuxiliaryDecls([&](Decl *decl) {
2844+
result.push_back(decl);
2845+
});
28462846
continue;
28472847
}
28482848

lib/Sema/TypeCheckDeclPrimary.cpp

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3785,36 +3785,3 @@ ExpandMacroExpansionDeclRequest::evaluate(Evaluator &evaluator,
37853785
assert(roles.contains(MacroRole::Declaration));
37863786
return expandFreestandingMacro(MED);
37873787
}
3788-
3789-
static void collectMacroExpansions(ASTNode node,
3790-
SmallVectorImpl<ASTNode> &result) {
3791-
if (auto *expr = node.dyn_cast<Expr *>()) {
3792-
if (auto *mee = dyn_cast<MacroExpansionExpr>(expr)) {
3793-
if (!mee->getRewritten()) {
3794-
if (auto *med = mee->getSubstituteDecl()) {
3795-
med->visitAuxiliaryDecls([&](Decl *decl) {
3796-
collectMacroExpansions(decl, result);
3797-
});
3798-
return;
3799-
}
3800-
}
3801-
}
3802-
} else if (auto *decl = node.dyn_cast<Decl *>()) {
3803-
if (auto *med = dyn_cast<MacroExpansionDecl>(decl)) {
3804-
med->visitAuxiliaryDecls([&](Decl *decl) {
3805-
collectMacroExpansions(decl, result);
3806-
});
3807-
return;
3808-
}
3809-
}
3810-
result.push_back(node);
3811-
}
3812-
3813-
ArrayRef<ASTNode>
3814-
RecursivelyExpandMacroExpansionDeclRequest::evaluate(
3815-
Evaluator &evaluator, MacroExpansionDecl *med) const {
3816-
SmallVector<ASTNode, 4> result;
3817-
for (auto node : med->getRewritten())
3818-
collectMacroExpansions(node, result);
3819-
return med->getASTContext().AllocateCopy(result);
3820-
}

test/Macros/Inputs/syntax_macro_definitions.swift

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,29 +1029,3 @@ public struct DefineStructWithUnqualifiedLookupMacro: DeclarationMacro {
10291029
"""]
10301030
}
10311031
}
1032-
1033-
public struct NestedDeclarationsMacro: DeclarationMacro {
1034-
public static func expansion(
1035-
of node: some FreestandingMacroExpansionSyntax,
1036-
in context: some MacroExpansionContext
1037-
) throws -> [DeclSyntax] {
1038-
return [
1039-
"""
1040-
1041-
#bitwidthNumberedStructs("Nested")
1042-
""",
1043-
"""
1044-
1045-
@NewType<Int>
1046-
public struct MyNewType {}
1047-
""",
1048-
// FIXME: Request cycle
1049-
// """
1050-
//
1051-
// struct NestedStruct {
1052-
// #bitwidthNumberedStructs("NestedStructMember")
1053-
// }
1054-
// """
1055-
]
1056-
}
1057-
}

test/Macros/macro_expand_freestanding.swift

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919
// Test non-arbitrary names
2020
@freestanding(declaration, names: named(A), named(B), named(foo), named(addOne))
2121
macro defineDeclsWithKnownNames() = #externalMacro(module: "MacroDefinition", type: "DefineDeclsWithKnownNamesMacro")
22-
// Test nested expansions
23-
@freestanding(declaration, names: arbitrary)
24-
macro nestedDeclarations() = #externalMacro(module: "MacroDefinition", type: "NestedDeclarationsMacro")
2522
// Test expanding to an attached macro.
2623
@attached(
2724
member,
@@ -60,7 +57,6 @@ func testFreestandingMacroExpansion() {
6057
struct Foo2 {
6158
#bitwidthNumberedStructs("MyIntTwo", blah: false)
6259
#defineDeclsWithKnownNames()
63-
#nestedDeclarations()
6460
}
6561
// CHECK: MyIntTwo8
6662
print(Foo2.MyIntTwo8.self)
@@ -78,12 +74,6 @@ func testFreestandingMacroExpansion() {
7874
print(Foo2().foo)
7975
// CHECK: 2
8076
print(Foo2().addOne(1))
81-
// CHECK: Nested8
82-
print(Foo2.Nested8.self)
83-
// CHECK: Int
84-
print(Foo2.MyNewType.RawValue.self)
85-
// CHECK: NestedStruct.NestedStructMember8
86-
// print(Foo2.NestedStruct.NestedStructMember8.self)
8777

8878
#if TEST_DIAGNOSTICS
8979
struct Foo3 {

0 commit comments

Comments
 (0)