Skip to content

Commit 5a1f197

Browse files
committed
[Sema] RuntimeMetadata: Workaround for availability checking of generator expressions
The availability checker cannot handle purely synthesized code without any source locations and declaration environment, so we have to disable availability checking and synthesize `if #available` with correct condition during body synthesis.
1 parent 618b9d9 commit 5a1f197

File tree

3 files changed

+106
-13
lines changed

3 files changed

+106
-13
lines changed

lib/Sema/TypeCheckRuntimeMetadataAttr.cpp

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "llvm/ADT/SmallString.h"
2828

2929
using namespace swift;
30+
using namespace constraints;
3031

3132
ArrayRef<CustomAttr *> ValueDecl::getRuntimeDiscoverableAttrs() const {
3233
auto *mutableSelf = const_cast<ValueDecl *>(this);
@@ -173,7 +174,12 @@ Expr *SynthesizeRuntimeMetadataAttrGenerator::evaluate(
173174
/*implicit=*/true),
174175
ArgumentList::forImplicitSingle(ctx, /*label=*/Identifier(), init));
175176

176-
auto resultTy = TypeChecker::typeCheckExpression(result, initContext);
177+
// Note that the availability checking is disabled for generator expression
178+
// because availability checker cannot handle synthesized code without any
179+
// source information (and no declaration for context).
180+
auto resultTy = TypeChecker::typeCheckExpression(
181+
result, initContext, ContextualTypeInfo(),
182+
TypeCheckExprFlags::DisableExprAvailabilityChecking);
177183
if (!resultTy)
178184
return nullptr;
179185

@@ -193,8 +199,6 @@ BraceStmt *SynthesizeRuntimeMetadataAttrGeneratorBody::evaluate(
193199
if (!init)
194200
return nullptr;
195201

196-
auto resultTy = init->getType();
197-
198202
SmallVector<ASTNode, 4> body;
199203

200204
auto declAvailability = attachedTo->getAvailabilityForLinkage();
@@ -217,11 +221,12 @@ BraceStmt *SynthesizeRuntimeMetadataAttrGeneratorBody::evaluate(
217221
auto *wildcardSpec =
218222
new (ctx) OtherPlatformAvailabilitySpec(/*StarLoc=*/SourceLoc());
219223

220-
StmtConditionElement platformCond(PoundAvailableInfo::create(
224+
auto *availabilityInfo = PoundAvailableInfo::create(
221225
ctx, /*PoundLoc=*/SourceLoc(),
222226
/*LParenLoc=*/SourceLoc(), {platformSpec, wildcardSpec},
223227
/*RParenLoc=*/SourceLoc(),
224-
/*isUnavailability=*/false));
228+
/*isUnavailability=*/false);
229+
{ availabilityInfo->setAvailableRange(declAvailability.getOSVersion()); }
225230

226231
NullablePtr<Stmt> thenStmt;
227232
{
@@ -236,10 +241,11 @@ BraceStmt *SynthesizeRuntimeMetadataAttrGeneratorBody::evaluate(
236241

237242
NullablePtr<Stmt> elseStmt;
238243
{
239-
// return nil as Optional<<#attribute type#>>
244+
// return nil
245+
240246
auto *nil =
241247
new (ctx) NilLiteralExpr(/*Loc=*/SourceLoc(), /*implicit=*/true);
242-
nil->setType(resultTy);
248+
nil->setType(init->getType());
243249

244250
auto *returnNil = new (ctx) ReturnStmt(/*loc=*/SourceLoc(), nil,
245251
/*isImplicit=*/true);
@@ -248,11 +254,11 @@ BraceStmt *SynthesizeRuntimeMetadataAttrGeneratorBody::evaluate(
248254
/*rbloc=*/SourceLoc(), /*implicit=*/true);
249255
}
250256

251-
auto *ifStmt = new (ctx)
252-
IfStmt(LabeledStmtInfo(), /*ifLoc=*/SourceLoc(),
253-
ctx.AllocateCopy(ArrayRef<StmtConditionElement>(platformCond)),
254-
thenStmt.get(),
255-
/*ElseLoc=*/SourceLoc(), elseStmt.get(), /*Implicit=*/true);
257+
auto *ifStmt = new (ctx) IfStmt(
258+
LabeledStmtInfo(), /*ifLoc=*/SourceLoc(),
259+
ctx.AllocateCopy(ArrayRef<StmtConditionElement>({availabilityInfo})),
260+
thenStmt.get(),
261+
/*ElseLoc=*/SourceLoc(), elseStmt.get(), /*Implicit=*/true);
256262

257263
body.push_back(ifStmt);
258264
} else {

test/IRGen/runtime_attributes.swift

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
// RUN: %target-swift-frontend -emit-module-path=%t/RAD.swiftmodule -module-name=RAD -enable-experimental-feature RuntimeDiscoverableAttrs %S/Inputs/runtime_attrs.swift
33
// RUN: %target-swift-frontend -primary-file %s -emit-ir -I %t -swift-version 5 -enable-experimental-feature RuntimeDiscoverableAttrs | %IRGenFileCheck %s
44

5-
// REQUIES: asserts
5+
// REQUIRES: asserts
6+
// REQUIRES: OS=macosx
67

78
// First, make sure that we emit:
89
// - accessible function records for each generator
@@ -39,6 +40,12 @@
3940
// CHECK: @"$s18runtime_attributes14TestInference1AaBVmvpfa3RAD6IgnoreHF"
4041
// CHECK: @"$s18runtime_attributes14TestInference2AaBCmvpfa3RAD6IgnoreHF"
4142
// CHECK: @"$s18runtime_attributes14TestInference3AaBOmvpfa3RAD6IgnoreHF"
43+
// CHECK: @"$s18runtime_attributes20testWithAvailabilityyySicvpfaAA0E5TestsHF"
44+
// CHECK: @"$s18runtime_attributes20TypeWithAvailabilityAaBCmvpfaAA0E5TestsHF"
45+
// CHECK: @"$s18runtime_attributes23MembersWithAvailabilityC8staticFnyycvpZfaAA0E5TestsHF"
46+
// CHECK: @"$s18runtime_attributes23MembersWithAvailabilityC6instFnyycvpfaAA0E5TestsHF"
47+
// CHECK: @"$s18runtime_attributes23MembersWithAvailabilityC4propSivpfaAA0E5TestsHF"
48+
// CHECK: @"$s18runtime_attributes20attrIsHigherThanFuncyycvpfaAA13FlagWithAvailHF"
4249

4350
// CHECK: @"$s18runtime_attributes4FlagVHa" = internal constant { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 } { i32 0, i32 trunc (i64 sub (i64 ptrtoint (<{ i32, i32, i32, i32, i32, i32, i32, i32, i32, i16, i16, i16, i16, i8, i8, i8, i8 }>* @"$s18runtime_attributes4FlagVMn" to i64), i64 ptrtoint (i32* getelementptr inbounds ({ i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }, { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }* @"$s18runtime_attributes4FlagVHa", i32 0, i32 1) to i64)) to i32), i32 16, {{.*}} @"$s18runtime_attributes4FlagVHa", i32 0, i32 34) to i64)) to i32) }, section "__TEXT, __swift5_rattrs, regular", align 4
4451

@@ -48,6 +55,10 @@
4855

4956
// CHECK: @"$s3RAD13TestAmbiguityVHa" = internal constant { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 } { i32 0, i32 trunc (i64 sub (i64 ptrtoint (%swift.type_descriptor* @"$s3RAD13TestAmbiguityVMn" to i64), i64 ptrtoint (i32* getelementptr inbounds ({ i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }, { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }* @"$s3RAD13TestAmbiguityVHa", i32 0, i32 1) to i64)) to i32), i32 6, i32 trunc (i64 sub (i64 ptrtoint (<{ [4 x i8], i8 }>* @"symbolic ySic" to i64), i64 ptrtoint (i32* getelementptr inbounds ({ i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }, { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }* @"$s3RAD13TestAmbiguityVHa", i32 0, i32 3) to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint (%swift.accessible_function* @"$s18runtime_attributes4testyySicvpfa3RAD13TestAmbiguityHF" to i64), i64 ptrtoint (i32* getelementptr inbounds ({ i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }, { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }* @"$s3RAD13TestAmbiguityVHa", i32 0, i32 4) to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint (<{ [4 x i8], i8 }>* @"symbolic ySSc" to i64), i64 ptrtoint (i32* getelementptr inbounds ({ i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }, { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }* @"$s3RAD13TestAmbiguityVHa", i32 0, i32 5) to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint (%swift.accessible_function* @"$s18runtime_attributes4testyySScvpfa3RAD13TestAmbiguityHF" to i64), i64 ptrtoint (i32* getelementptr inbounds ({ i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }, { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }* @"$s3RAD13TestAmbiguityVHa", i32 0, i32 6) to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint (<{ [4 x i8], i8, i32, [2 x i8], i8 }>* @"symbolic Siyc_____mc 18runtime_attributes15TestNoAmbiguityV" to i64), i64 ptrtoint (i32* getelementptr inbounds ({ i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }, { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }* @"$s3RAD13TestAmbiguityVHa", i32 0, i32 7) to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint (%swift.accessible_function* @"$s18runtime_attributes15TestNoAmbiguityV10testStaticSiycvpZfa3RAD0cE0HF" to i64), i64 ptrtoint (i32* getelementptr inbounds ({ i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }, { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }* @"$s3RAD13TestAmbiguityVHa", i32 0, i32 8) to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint (<{ [3 x i8], i8, i32, [2 x i8], i8 }>* @"symbolic yyc_____mc 18runtime_attributes15TestNoAmbiguityV" to i64), i64 ptrtoint (i32* getelementptr inbounds ({ i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }, { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }* @"$s3RAD13TestAmbiguityVHa", i32 0, i32 9) to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint (%swift.accessible_function* @"$s18runtime_attributes15TestNoAmbiguityV10testStaticyycvpZfa3RAD0cE0HF" to i64), i64 ptrtoint (i32* getelementptr inbounds ({ i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }, { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }* @"$s3RAD13TestAmbiguityVHa", i32 0, i32 10) to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint (<{ [8 x i8], i8, i32, [1 x i8], i8 }>* @"symbolic ySi_SStc_____c 18runtime_attributes15TestNoAmbiguityV" to i64), i64 ptrtoint (i32* getelementptr inbounds ({ i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }, { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }* @"$s3RAD13TestAmbiguityVHa", i32 0, i32 11) to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint (%swift.accessible_function* @"$s18runtime_attributes15TestNoAmbiguityV8testInstyySi_SStcvpfa3RAD0cE0HF" to i64), i64 ptrtoint (i32* getelementptr inbounds ({ i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }, { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }* @"$s3RAD13TestAmbiguityVHa", i32 0, i32 12) to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint (<{ [8 x i8], i8, i32, [1 x i8], i8 }>* @"symbolic ySi_Sitc_____c 18runtime_attributes15TestNoAmbiguityV" to i64), i64 ptrtoint (i32* getelementptr inbounds ({ i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }, { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }* @"$s3RAD13TestAmbiguityVHa", i32 0, i32 13) to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint (%swift.accessible_function* @"$s18runtime_attributes15TestNoAmbiguityV8testInstyySi_Sitcvpfa3RAD0cE0HF" to i64), i64 ptrtoint (i32* getelementptr inbounds ({ i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }, { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }* @"$s3RAD13TestAmbiguityVHa", i32 0, i32 14) to i64)) to i32) }, section "__TEXT, __swift5_rattrs, regular", align 4
5057

58+
// CHECK: @"$s18runtime_attributes17AvailabilityTestsVHa" = internal constant { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 } { i32 0, i32 trunc (i64 sub (i64 ptrtoint (<{ i32, i32, i32, i32, i32, i32, i32 }>* @"$s18runtime_attributes17AvailabilityTestsVMn" to i64), i64 ptrtoint (i32* getelementptr inbounds ({ i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }, { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }* @"$s18runtime_attributes17AvailabilityTestsVHa", i32 0, i32 1) to i64)) to i32), i32 5, i32 trunc (i64 sub (i64 ptrtoint (<{ [4 x i8], i8 }>* @"symbolic ySic" to i64), i64 ptrtoint (i32* getelementptr inbounds ({ i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }, { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }* @"$s18runtime_attributes17AvailabilityTestsVHa", i32 0, i32 3) to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint (%swift.accessible_function* @"$s18runtime_attributes20testWithAvailabilityyySicvpfaAA0E5TestsHF" to i64), i64 ptrtoint (i32* getelementptr inbounds ({ i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }, { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }* @"$s18runtime_attributes17AvailabilityTestsVHa", i32 0, i32 4) to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint (<{ i8, i32, [1 x i8], i8 }>* @"symbolic _____m 18runtime_attributes20TypeWithAvailabilityC" to i64), i64 ptrtoint (i32* getelementptr inbounds ({ i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }, { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }* @"$s18runtime_attributes17AvailabilityTestsVHa", i32 0, i32 5) to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint (%swift.accessible_function* @"$s18runtime_attributes20TypeWithAvailabilityAaBCmvpfaAA0E5TestsHF" to i64), i64 ptrtoint (i32* getelementptr inbounds ({ i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }, { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }* @"$s18runtime_attributes17AvailabilityTestsVHa", i32 0, i32 6) to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint (<{ [3 x i8], i8, i32, [2 x i8], i8 }>* @"symbolic yyc_____mc 18runtime_attributes23MembersWithAvailabilityC" to i64), i64 ptrtoint (i32* getelementptr inbounds ({ i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }, { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }* @"$s18runtime_attributes17AvailabilityTestsVHa", i32 0, i32 7) to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint (%swift.accessible_function* @"$s18runtime_attributes23MembersWithAvailabilityC8staticFnyycvpZfaAA0E5TestsHF" to i64), i64 ptrtoint (i32* getelementptr inbounds ({ i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }, { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }* @"$s18runtime_attributes17AvailabilityTestsVHa", i32 0, i32 8) to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint (<{ [3 x i8], i8, i32, [1 x i8], i8 }>* @"symbolic yyc_____c 18runtime_attributes23MembersWithAvailabilityC" to i64), i64 ptrtoint (i32* getelementptr inbounds ({ i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }, { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }* @"$s18runtime_attributes17AvailabilityTestsVHa", i32 0, i32 9) to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint (%swift.accessible_function* @"$s18runtime_attributes23MembersWithAvailabilityC6instFnyycvpfaAA0E5TestsHF" to i64), i64 ptrtoint (i32* getelementptr inbounds ({ i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }, { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }* @"$s18runtime_attributes17AvailabilityTestsVHa", i32 0, i32 10) to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint (<{ [2 x i8], i8 }>* @"symbolic Si" to i64), i64 ptrtoint (i32* getelementptr inbounds ({ i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }, { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }* @"$s18runtime_attributes17AvailabilityTestsVHa", i32 0, i32 11) to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint (%swift.accessible_function* @"$s18runtime_attributes23MembersWithAvailabilityC4propSivpfaAA0E5TestsHF" to i64), i64 ptrtoint (i32* getelementptr inbounds ({ i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }, { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }* @"$s18runtime_attributes17AvailabilityTestsVHa", i32 0, i32 12) to i64)) to i32) }, section "__TEXT, __swift5_rattrs, regular", align 4
59+
60+
// CHECK: @"$s18runtime_attributes13FlagWithAvailVHa" = internal constant { i32, i32, i32, i32, i32 } { i32 0, i32 trunc (i64 sub (i64 ptrtoint (<{ i32, i32, i32, i32, i32, i32, i32 }>* @"$s18runtime_attributes13FlagWithAvailVMn" to i64), i64 ptrtoint (i32* getelementptr inbounds ({ i32, i32, i32, i32, i32 }, { i32, i32, i32, i32, i32 }* @"$s18runtime_attributes13FlagWithAvailVHa", i32 0, i32 1) to i64)) to i32), i32 1, i32 trunc (i64 sub (i64 ptrtoint (<{ [3 x i8], i8 }>* @"symbolic yyc" to i64), i64 ptrtoint (i32* getelementptr inbounds ({ i32, i32, i32, i32, i32 }, { i32, i32, i32, i32, i32 }* @"$s18runtime_attributes13FlagWithAvailVHa", i32 0, i32 3) to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint (%swift.accessible_function* @"$s18runtime_attributes20attrIsHigherThanFuncyycvpfaAA13FlagWithAvailHF" to i64), i64 ptrtoint (i32* getelementptr inbounds ({ i32, i32, i32, i32, i32 }, { i32, i32, i32, i32, i32 }* @"$s18runtime_attributes13FlagWithAvailVHa", i32 0, i32 4) to i64)) to i32) }, section "__TEXT, __swift5_rattrs, regular", align 4
61+
5162
import RAD
5263

5364
@runtimeMetadata
@@ -143,3 +154,58 @@ public struct TestInference1 : Ignored {}
143154
public class TestInference2 : Ignored {}
144155
// CHECK-LABEL: define hidden swiftcc i8 @"$s18runtime_attributes14TestInference3AaBOmvpfa3RAD6Ignore"()
145156
public enum TestInference3 : Ignored {}
157+
158+
@runtimeMetadata
159+
struct AvailabilityTests {
160+
init(attachedTo: Any) {}
161+
}
162+
163+
// CHECK-LABEL: define hidden swiftcc i8 @"$s18runtime_attributes20testWithAvailabilityyySicvpfaAA0E5Tests"()
164+
// CHECK: entry:
165+
// CHECK: {{.*}} = call swiftcc i1 @"$ss26_stdlib_isOSVersionAtLeastyBi1_Bw_BwBwtF"(i64 42, i64 0, i64 0)
166+
@available(macOS, introduced: 42.0)
167+
@AvailabilityTests
168+
func testWithAvailability(_: Int) {}
169+
170+
// CHECK-LABEL: define hidden swiftcc i8 @"$s18runtime_attributes20TypeWithAvailabilityAaBCmvpfaAA0E5Tests"()
171+
// CHECK: entry:
172+
// CHECK: {{.*}} = call swiftcc i1 @"$ss26_stdlib_isOSVersionAtLeastyBi1_Bw_BwBwtF"(i64 100, i64 0, i64 0)
173+
@available(macOS, introduced: 100.0)
174+
@AvailabilityTests
175+
class TypeWithAvailability {}
176+
177+
class MembersWithAvailability {
178+
// CHECK-LABEL: define hidden swiftcc i8 @"$s18runtime_attributes23MembersWithAvailabilityC8staticFnyycvpZfaAA0E5Tests"()
179+
// CHECK: entry:
180+
// CHECK: {{.*}} = call swiftcc i1 @"$ss26_stdlib_isOSVersionAtLeastyBi1_Bw_BwBwtF"(i64 201, i64 0, i64 0)
181+
@AvailabilityTests
182+
@available(macOS, introduced: 201.0)
183+
static func staticFn() {}
184+
185+
// CHECK-LABEL: define hidden swiftcc i8 @"$s18runtime_attributes23MembersWithAvailabilityC6instFnyycvpfaAA0E5Tests"()
186+
// CHECK: entry:
187+
// CHECK: {{.*}} = call swiftcc i1 @"$ss26_stdlib_isOSVersionAtLeastyBi1_Bw_BwBwtF"(i64 202, i64 0, i64 0)
188+
@AvailabilityTests
189+
@available(macOS, introduced: 202.0)
190+
func instFn() {}
191+
192+
// CHECK-LABEL: define hidden swiftcc i8 @"$s18runtime_attributes23MembersWithAvailabilityC4propSivpfaAA0E5Tests"()
193+
// CHECK: entry:
194+
// CHECK: {{.*}} = call swiftcc i1 @"$ss26_stdlib_isOSVersionAtLeastyBi1_Bw_BwBwtF"(i64 203, i64 0, i64 0)
195+
@AvailabilityTests
196+
@available(macOS, introduced: 203.0)
197+
var prop: Int { get { 42 } }
198+
}
199+
200+
@runtimeMetadata
201+
@available(macOS, introduced: 110.0)
202+
struct FlagWithAvail {
203+
init(attachedTo: Any) {}
204+
}
205+
206+
// CHECK-LABEL: define hidden swiftcc i8 @"$s18runtime_attributes20attrIsHigherThanFuncyycvpfaAA13FlagWithAvail"()
207+
// CHECK: entry:
208+
// CHECK: {{.*}} = call swiftcc i1 @"$ss26_stdlib_isOSVersionAtLeastyBi1_Bw_BwBwtF"(i64 110, i64 0, i64 0)
209+
@FlagWithAvail
210+
@available(macOS, obsoleted: 100.0)
211+
func attrIsHigherThanFunc() {}

test/type/runtime_discoverable_attrs.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,24 @@ enum Inference3 : Flagged {} // Ok
115115

116116
@Flag("direct flag")
117117
struct Inference4 : Flagged {} // Ok (because @Flag inferred from Flagged is ignored)
118+
119+
@available(macOS, introduced: 42.0)
120+
@Flag("with availability")
121+
func testWithAvailability(_: Int) {} // Ok
122+
123+
@available(macOS, introduced: 100.0)
124+
class TypeWithAvailability : Flagged {} // Ok
125+
126+
class MembersWithAvailability {
127+
@Flag
128+
@available(macOS, introduced: 100.0)
129+
static func staticFn() {} // Ok
130+
131+
@Flag
132+
@available(macOS, introduced: 100.0)
133+
func instFn() {} // Ok
134+
135+
@Flag
136+
@available(macOS, introduced: 100.0)
137+
var prop: Int { get { 0 } } // Ok
138+
}

0 commit comments

Comments
 (0)