Skip to content

Commit 45b8cfd

Browse files
authored
[ModuleInterface] Guard layout based prespecializations in swiftinter… (#64695)
* [ModuleInterface] Guard layout based prespecializations in swiftinterface files rdar://107269447 To allow compilers that don't have this feature enabled to parse interface files that contain declarations that use layout based prespecializations, it has to be guarded. * Incorporate feedback
1 parent 55e9e28 commit 45b8cfd

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3176,7 +3176,13 @@ static bool usesFeatureVariadicGenerics(Decl *decl) {
31763176
}
31773177

31783178
static bool usesFeatureLayoutPrespecialization(Decl *decl) {
3179-
return false;
3179+
auto &attrs = decl->getAttrs();
3180+
return std::any_of(attrs.begin(), attrs.end(), [](auto *attr) {
3181+
if (auto *specialize = dyn_cast<SpecializeAttr>(attr)) {
3182+
return !specialize->getTypeErasedParams().empty();
3183+
}
3184+
return false;
3185+
});
31803186
}
31813187

31823188
static bool usesFeatureLayoutStringValueWitnesses(Decl *decl) {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// RUN: %target-swift-emit-module-interface(%t/LayoutPrespec.swiftinterface) %s -enable-experimental-feature LayoutPrespecialization -module-name LayoutPrespec -disable-availability-checking
4+
// RUN: %target-swift-typecheck-module-from-interface(%t/LayoutPrespec.swiftinterface) -module-name LayoutPrespec -disable-availability-checking
5+
// RUN: %target-swift-typecheck-module-from-interface(%t/LayoutPrespec.swiftinterface) -module-name LayoutPrespec -enable-experimental-feature LayoutPrespecialization -disable-availability-checking
6+
// RUN: %FileCheck %s < %t/LayoutPrespec.swiftinterface
7+
8+
// CHECK: #if compiler(>=5.3) && $LayoutPrespecialization
9+
// CHECK-NEXT: @_specialize(exported: true, kind: full, where @_noMetadata A : _Class)
10+
// CHECK-NEXT: public func test<A>(a: A) -> A
11+
// CHECK-NEXT: #endif
12+
@_specialize(exported: true, where @_noMetadata A : _Class)
13+
public func test<A>(a: A) -> A {
14+
return a
15+
}

0 commit comments

Comments
 (0)