mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Support applying macros to imported-as-member declarations
This commit is contained in:
@@ -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))
|
||||
|
||||
@@ -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:)")));
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user