Skip to content

Commit ead028b

Browse files
committed
Support applying macros to imported-as-member declarations
1 parent f255cf6 commit ead028b

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9669,6 +9669,13 @@ bool ClangImporter::Implementation::addMemberAndAlternatesToExtension(
96699669
if (!isa<AccessorDecl>(alternate))
96709670
ext->addMember(alternate);
96719671
}
9672+
9673+
member->visitAuxiliaryDecls([&](Decl *aux) {
9674+
if (auto auxValue = dyn_cast<ValueDecl>(aux)) {
9675+
ext->addMember(auxValue);
9676+
}
9677+
});
9678+
96729679
return true;
96739680
}
96749681

@@ -9741,6 +9748,16 @@ void ClangImporter::Implementation::insertMembersAndAlternates(
97419748
}
97429749
}
97439750

9751+
// If there are auxiliary declarations (e.g., produced by macros), load
9752+
// those.
9753+
member->visitAuxiliaryDecls([&](Decl *aux) {
9754+
if (auto auxValue = dyn_cast<ValueDecl>(aux)) {
9755+
if (auxValue->getDeclContext() == expectedDC &&
9756+
knownAlternateMembers.insert(auxValue).second)
9757+
members.push_back(auxValue);
9758+
}
9759+
});
9760+
97449761
// If this declaration shouldn't be visible, don't add it to
97459762
// the list.
97469763
if (shouldSuppressDeclImport(nd))
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
11
void async_divide(double x, double y, void (* _Nonnull completionHandler)(double x))
22
__attribute__((swift_attr("@macro_library.AddAsync")));
3+
4+
typedef struct SlowComputer {
5+
} SlowComputer;
6+
7+
void computer_divide(const SlowComputer *computer, double x, double y, void (* _Nonnull completionHandler)(double x))
8+
__attribute__((swift_attr("@macro_library.AddAsync")))
9+
__attribute__((swift_name("SlowComputer.divide(self:_:_:completionHandler:)")));

test/Macros/expand_on_imported.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ func asyncTest(_ value: Int, completionHandler: @escaping (String) -> Void) {
2020
}
2121

2222
@available(SwiftStdlib 5.1, *)
23-
func testAll(x: Double, y: Double) async {
23+
func testAll(x: Double, y: Double, computer: SlowComputer) async {
2424
_ = await asyncTest(17)
2525

2626
let _: Double = await async_divide(1.0, 2.0)
27+
let _: Double = await computer.divide(x, y)
2728
}

test/Macros/print_clang_expand_on_imported.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,9 @@
1212
import CompletionHandlerGlobals
1313

1414
// CHECK: func async_divide(_ x: Double, _ y: Double, _ completionHandler: @convention(c) (Double) -> Void)
15+
16+
// CHECK: extension SlowComputer
17+
// CHECK: public func divide(_ x: Double, _ y: Double) async -> Double
18+
1519
// CHECK: func async_divide(_ x: Double, _ y: Double) async -> Double
1620

0 commit comments

Comments
 (0)