Skip to content

Commit bed616c

Browse files
committed
SILGen: Stub unavailable protocol witness thunks.
Part of rdar://107388493
1 parent 963f10a commit bed616c

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

lib/SILGen/SILGenConstructor.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,9 @@ void SILGenFunction::emitEnumConstructor(EnumElementDecl *element) {
750750
auto &enumTI =
751751
SGM.Types.getTypeLowering(enumTy, TypeExpansionContext::minimal());
752752

753+
if (shouldLowerToUnavailableCodeStub(element))
754+
emitApplyOfUnavailableCodeReached();
755+
753756
RegularLocation Loc(element);
754757
CleanupLocation CleanupLoc(element);
755758
Loc.markAutoGenerated();

lib/SILGen/SILGenPoly.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4966,6 +4966,9 @@ void SILGenFunction::emitProtocolWitness(
49664966
SmallVector<ManagedValue, 8> origParams;
49674967
collectThunkParams(loc, origParams);
49684968

4969+
if (shouldLowerToUnavailableCodeStub(witness.getDecl()))
4970+
emitApplyOfUnavailableCodeReached();
4971+
49694972
if (enterIsolation) {
49704973
// If we are supposed to enter the actor, do so now by hopping to the
49714974
// actor.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// RUN: %target-swift-emit-silgen -module-name Test -parse-as-library %s -verify -unavailable-decl-optimization=stub | %FileCheck %s --check-prefixes=CHECK
2+
3+
public struct S {}
4+
5+
public protocol P {
6+
static func requirement(_ s: S) -> Self
7+
}
8+
9+
public enum EnumWithProtocolWitness {
10+
@available(*, unavailable)
11+
case requirement(_ s: S)
12+
}
13+
14+
@available(*, unavailable)
15+
extension EnumWithProtocolWitness: P {}
16+
17+
// protocol witness for static P.requirement(_:) in conformance EnumWithProtocolWitness
18+
//
19+
// CHECK-LABEL: sil {{.*}} @$s4Test23EnumWithProtocolWitnessOAA1PA2aDP11requirementyxAA1SVFZTW
20+
// CHECK: [[FNREF:%.*]] = function_ref @$ss31_diagnoseUnavailableCodeReacheds5NeverOyF
21+
// CHECK-NEXT: [[APPLY:%.*]] = apply [[FNREF]]()
22+
// CHECK: {{%.*}} = function_ref @$s4Test23EnumWithProtocolWitnessO11requirementyAcA1SVcACmF
23+
// CHECK: } // end sil function '$s4Test23EnumWithProtocolWitnessOAA1PA2aDP11requirementyxAA1SVFZTW'
24+
//
25+
// EnumWithProtocolWitness.requirement(_:)
26+
//
27+
// CHECK-LABEL: sil {{.*}} @$s4Test23EnumWithProtocolWitnessO11requirementyAcA1SVcACmF
28+
// CHECK: [[FNREF:%.*]] = function_ref @$ss31_diagnoseUnavailableCodeReacheds5NeverOyF
29+
// CHECK-NEXT: [[APPLY:%.*]] = apply [[FNREF]]()
30+
// CHECK: enum $EnumWithProtocolWitness, #EnumWithProtocolWitness.requirement!enumelt
31+
// CHECK: } // end sil function '$s4Test23EnumWithProtocolWitnessO11requirementyAcA1SVcACmF'

0 commit comments

Comments
 (0)