Skip to content

Commit ed23756

Browse files
committed
AST: Pattern binding decls inherit their var decl's availability.
This ensures SIL lowering will avoid generating code for unavailable global vars when `-unavailable-decl-optimization=complete` is specfied. Part of rdar://106674022
1 parent 587c277 commit ed23756

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

lib/AST/Availability.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,9 @@ AvailabilityInference::parentDeclForInferredAvailability(const Decl *D) {
181181
return NTD;
182182
}
183183

184+
if (auto *PBD = dyn_cast<PatternBindingDecl>(D))
185+
return PBD->getAnchoringVarDecl(0);
186+
184187
// Clang decls may be inaccurately parented rdar://53956555
185188
if (D->hasClangNode())
186189
return nullptr;

test/SILGen/unavailable_decl_optimization.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66
// CHECK-NO-STRIP: s4Test14globalConstantSbvp
77
// CHECK-NO-STRIP: s4Test14globalConstant_WZ
88
// CHECK-NO-STRIP: s4Test14globalConstantSbvau
9-
// FIXME: global var isn't stripped
10-
// HECK-STRIP-NOT: s4Test14globalConstant_Wz
11-
// HECK-STRIP-NOT: s4Test14globalConstantSbvp
12-
// HECK-STRIP-NOT: s4Test14globalConstant_WZ
13-
// HECK-STRIP-NOT: s4Test14globalConstantSbvau
9+
// CHECK-STRIP-NOT: s4Test14globalConstant_Wz
10+
// CHECK-STRIP-NOT: s4Test14globalConstantSbvp
11+
// CHECK-STRIP-NOT: s4Test14globalConstant_WZ
12+
// CHECK-STRIP-NOT: s4Test14globalConstantSbvau
1413
@available(*, unavailable)
1514
public let globalConstant = true
1615

0 commit comments

Comments
 (0)