Skip to content

Commit 2461313

Browse files
committed
SILGen: Add a SILGen test for the @_backDeploy attribute and fix parsing for the attribute so that -verify-syntax-tree passes. The SILGen test doesn't verify anything special yet since we're not emitting thunks yet at call sites.
1 parent 25b59cb commit 2461313

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

lib/Parse/ParseDecl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2927,7 +2927,8 @@ bool Parser::parseNewDeclAttribute(DeclAttributes &Attributes, SourceLoc AtLoc,
29272927
StringRef AttrName = "@_backDeploy";
29282928
ParserStatus Status = parseList(tok::r_paren, LeftLoc, RightLoc, false,
29292929
diag::attr_back_deploy_missing_rparen,
2930-
SyntaxKind::Unknown, [&]() -> ParserStatus {
2930+
SyntaxKind::AvailabilitySpecList,
2931+
[&]() -> ParserStatus {
29312932
ParserStatus ListItemStatus =
29322933
parsePlatformVersionInList(AttrName, PlatformAndVersions);
29332934
if (ListItemStatus.isErrorOrHasCompletion())
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// RUN: %target-swift-emit-silgen %s | %FileCheck %s
2+
// RUN: %target-swift-emit-silgen %s -target %target-cpu-apple-macosx10.50 | %FileCheck %s
3+
// RUN: %target-swift-emit-silgen %s -target %target-cpu-apple-macosx10.60 | %FileCheck %s
4+
// REQUIRES: OS=macosx
5+
6+
// CHECK-LABEL: sil [serialized] [available 10.51] [ossa] @$s21back_deploy_attribute0A12DeployedFuncyyF : $@convention(thin) () -> ()
7+
@available(macOS 10.51, *)
8+
@_backDeploy(macOS 10.50)
9+
public func backDeployedFunc() {}
10+
11+
@available(macOS 10.50, *)
12+
public struct TopLevelStruct {
13+
// CHECK-LABEL: sil [serialized] [available 10.51] [ossa] @$s21back_deploy_attribute14TopLevelStructV0a8DeployedF4FuncyyF : $@convention(method) (TopLevelStruct) -> ()
14+
@available(macOS 10.51, *)
15+
@_backDeploy(macOS 10.50)
16+
public func backDeployedStructFunc() {}
17+
}
18+
19+
20+
// FIXME(backDeploy): Verify SIL in a caller that requires back deployment
21+
22+
23+
// CHECK-LABLEL: sil hidden [available 10.51] [ossa] @$s21back_deploy_attribute21alwaysAvailableCalleryyAA14TopLevelStructVF : $@convention(thin) (TopLevelStruct) -> ()
24+
// CHECK: bb0(%0 : $TopLevelStruct):
25+
@available(macOS 10.51, *)
26+
func alwaysAvailableCaller(_ s: TopLevelStruct) {
27+
/// This function's availability meets the minimum availability of the APIs, so
28+
/// no back deployment logic is required.
29+
30+
// CHECK: %2 = function_ref @$s21back_deploy_attribute0A12DeployedFuncyyF : $@convention(thin) () -> ()
31+
// CHECK: %3 = apply %2() : $@convention(thin) () -> ()
32+
backDeployedFunc()
33+
// CHECK: %4 = function_ref @$s21back_deploy_attribute14TopLevelStructV0a8DeployedF4FuncyyF : $@convention(method) (TopLevelStruct) -> ()
34+
// CHECK: %5 = apply %4(%0) : $@convention(method) (TopLevelStruct) -> ()
35+
s.backDeployedStructFunc()
36+
}

0 commit comments

Comments
 (0)