Skip to content

Commit e3b715b

Browse files
Merge pull request #58760 from aschwaighofer/swiftinterface_print_specialize_with_targetFunction
swiftinterface: print _specialize functions with targetFunction parameter in .swiftinterface
2 parents 41ee9ff + 7bfa01a commit e3b715b

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,17 @@ static bool isPublicOrUsableFromInline(Type ty) {
107107
});
108108
}
109109

110+
static bool isPrespecilizationDeclWithTarget(const ValueDecl *vd) {
111+
// Add exported prespecialized symbols.
112+
for (auto *attr : vd->getAttrs().getAttributes<SpecializeAttr>()) {
113+
if (!attr->isExported())
114+
continue;
115+
if (auto *targetFun = attr->getTargetFunctionDecl(vd))
116+
return true;
117+
}
118+
return false;
119+
}
120+
110121
static bool contributesToParentTypeStorage(const AbstractStorageDecl *ASD) {
111122
auto *DC = ASD->getDeclContext()->getAsDecl();
112123
if (!DC) return false;
@@ -178,9 +189,11 @@ PrintOptions PrintOptions::printSwiftInterfaceFile(ModuleDecl *ModuleToPrint,
178189
if (!options.PrintSPIs && D->isSPI())
179190
return false;
180191

181-
// Skip anything that isn't 'public' or '@usableFromInline'.
192+
// Skip anything that isn't 'public' or '@usableFromInline' or has a
193+
// _specialize attribute with a targetFunction parameter.
182194
if (auto *VD = dyn_cast<ValueDecl>(D)) {
183-
if (!isPublicOrUsableFromInline(VD)) {
195+
if (!isPublicOrUsableFromInline(VD) &&
196+
!isPrespecilizationDeclWithTarget(VD)) {
184197
// We do want to print private stored properties, without their
185198
// original names present.
186199
if (auto *ASD = dyn_cast<AbstractStorageDecl>(VD))

test/ModuleInterface/attrs.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,12 @@
1818
// CHECK-NEXT: public var y: Swift.Int
1919
public var y: Int
2020
} // CHECK-NEXT: {{^}$}}
21+
22+
public func someGenericFunction<T>(_ t: T) -> Int { return 0 }
23+
24+
// CHECK: @_specialize(exported: true, kind: full, target: someGenericFunction(_:), where T == Swift.Int)
25+
// CHECK: internal func __specialize_someGenericFunction<T>(_ t: T)
26+
@_specialize(exported: true, target: someGenericFunction(_:), where T == Int)
27+
internal func __specialize_someGenericFunction<T>(_ t: T) -> Int {
28+
fatalError("don't call")
29+
}

0 commit comments

Comments
 (0)