Skip to content

Commit fd2f878

Browse files
authored
[ModuleInterface] Guard layout based prespecializations in swiftinter… (#64695) (#64712)
* [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 5292d6d commit fd2f878

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
@@ -3160,7 +3160,13 @@ static bool usesFeatureVariadicGenerics(Decl *decl) {
31603160
}
31613161

31623162
static bool usesFeatureLayoutPrespecialization(Decl *decl) {
3163-
return false;
3163+
auto &attrs = decl->getAttrs();
3164+
return std::any_of(attrs.begin(), attrs.end(), [](auto *attr) {
3165+
if (auto *specialize = dyn_cast<SpecializeAttr>(attr)) {
3166+
return !specialize->getTypeErasedParams().empty();
3167+
}
3168+
return false;
3169+
});
31643170
}
31653171

31663172
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)