Skip to content

[5.9][ModuleInterface] Guard layout based prespecializations in swiftinter… #64712

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/AST/ASTPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3160,7 +3160,13 @@ static bool usesFeatureVariadicGenerics(Decl *decl) {
}

static bool usesFeatureLayoutPrespecialization(Decl *decl) {
return false;
auto &attrs = decl->getAttrs();
return std::any_of(attrs.begin(), attrs.end(), [](auto *attr) {
if (auto *specialize = dyn_cast<SpecializeAttr>(attr)) {
return !specialize->getTypeErasedParams().empty();
}
return false;
});
}

static bool usesFeatureLayoutStringValueWitnesses(Decl *decl) {
Expand Down
15 changes: 15 additions & 0 deletions test/ModuleInterface/layout_pre_specialization.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// RUN: %empty-directory(%t)

// RUN: %target-swift-emit-module-interface(%t/LayoutPrespec.swiftinterface) %s -enable-experimental-feature LayoutPrespecialization -module-name LayoutPrespec -disable-availability-checking
// RUN: %target-swift-typecheck-module-from-interface(%t/LayoutPrespec.swiftinterface) -module-name LayoutPrespec -disable-availability-checking
// RUN: %target-swift-typecheck-module-from-interface(%t/LayoutPrespec.swiftinterface) -module-name LayoutPrespec -enable-experimental-feature LayoutPrespecialization -disable-availability-checking
// RUN: %FileCheck %s < %t/LayoutPrespec.swiftinterface

// CHECK: #if compiler(>=5.3) && $LayoutPrespecialization
// CHECK-NEXT: @_specialize(exported: true, kind: full, where @_noMetadata A : _Class)
// CHECK-NEXT: public func test<A>(a: A) -> A
// CHECK-NEXT: #endif
@_specialize(exported: true, where @_noMetadata A : _Class)
public func test<A>(a: A) -> A {
return a
}