Support applying macros to imported-as-member declarations

This commit is contained in:
Doug Gregor
2024-09-16 15:19:22 -07:00
parent f255cf6922
commit ead028bb11
4 changed files with 30 additions and 1 deletions

View File

@@ -9669,6 +9669,13 @@ bool ClangImporter::Implementation::addMemberAndAlternatesToExtension(
if (!isa<AccessorDecl>(alternate))
ext->addMember(alternate);
}
member->visitAuxiliaryDecls([&](Decl *aux) {
if (auto auxValue = dyn_cast<ValueDecl>(aux)) {
ext->addMember(auxValue);
}
});
return true;
}
@@ -9741,6 +9748,16 @@ void ClangImporter::Implementation::insertMembersAndAlternates(
}
}
// If there are auxiliary declarations (e.g., produced by macros), load
// those.
member->visitAuxiliaryDecls([&](Decl *aux) {
if (auto auxValue = dyn_cast<ValueDecl>(aux)) {
if (auxValue->getDeclContext() == expectedDC &&
knownAlternateMembers.insert(auxValue).second)
members.push_back(auxValue);
}
});
// If this declaration shouldn't be visible, don't add it to
// the list.
if (shouldSuppressDeclImport(nd))

View File

@@ -1,2 +1,9 @@
void async_divide(double x, double y, void (* _Nonnull completionHandler)(double x))
__attribute__((swift_attr("@macro_library.AddAsync")));
typedef struct SlowComputer {
} SlowComputer;
void computer_divide(const SlowComputer *computer, double x, double y, void (* _Nonnull completionHandler)(double x))
__attribute__((swift_attr("@macro_library.AddAsync")))
__attribute__((swift_name("SlowComputer.divide(self:_:_:completionHandler:)")));

View File

@@ -20,8 +20,9 @@ func asyncTest(_ value: Int, completionHandler: @escaping (String) -> Void) {
}
@available(SwiftStdlib 5.1, *)
func testAll(x: Double, y: Double) async {
func testAll(x: Double, y: Double, computer: SlowComputer) async {
_ = await asyncTest(17)
let _: Double = await async_divide(1.0, 2.0)
let _: Double = await computer.divide(x, y)
}

View File

@@ -12,5 +12,9 @@
import CompletionHandlerGlobals
// CHECK: func async_divide(_ x: Double, _ y: Double, _ completionHandler: @convention(c) (Double) -> Void)
// CHECK: extension SlowComputer
// CHECK: public func divide(_ x: Double, _ y: Double) async -> Double
// CHECK: func async_divide(_ x: Double, _ y: Double) async -> Double