@@ -104,6 +104,15 @@ static bool isArchetypeValidInFunction(ArchetypeType *A, const SILFunction *F) {
104
104
105
105
namespace {
106
106
107
+ // / When resilience is bypassed, direct access is legal, but the decls are still
108
+ // / resilient.
109
+ template <typename DeclType>
110
+ bool checkResilience (DeclType *D, ModuleDecl *M,
111
+ ResilienceExpansion expansion) {
112
+ return !D->getModuleContext ()->getBypassResilience () &&
113
+ D->isResilient (M, expansion);
114
+ }
115
+
107
116
// / Metaprogramming-friendly base class.
108
117
template <class Impl >
109
118
class SILVerifierBase : public SILInstructionVisitor <Impl> {
@@ -234,7 +243,7 @@ void verifyKeyPathComponent(SILModule &M,
234
243
" property decl should be a member of the base with the same type "
235
244
" as the component" );
236
245
require (property->hasStorage (), " property must be stored" );
237
- require (!property-> isResilient ( M.getSwiftModule (), expansion),
246
+ require (!checkResilience (property, M.getSwiftModule (), expansion),
238
247
" cannot access storage of resilient property" );
239
248
auto propertyTy =
240
249
loweredBaseTy.getFieldType (property, M, typeExpansionContext);
@@ -1970,7 +1979,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
1970
1979
void checkAllocGlobalInst (AllocGlobalInst *AGI) {
1971
1980
SILGlobalVariable *RefG = AGI->getReferencedGlobal ();
1972
1981
if (auto *VD = RefG->getDecl ()) {
1973
- require (!VD-> isResilient ( F.getModule ().getSwiftModule (),
1982
+ require (!checkResilience (VD, F.getModule ().getSwiftModule (),
1974
1983
F.getResilienceExpansion ()),
1975
1984
" cannot access storage of resilient global" );
1976
1985
}
@@ -1989,7 +1998,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
1989
1998
RefG->getLoweredTypeInContext (F.getTypeExpansionContext ()),
1990
1999
" global_addr/value must be the type of the variable it references" );
1991
2000
if (auto *VD = RefG->getDecl ()) {
1992
- require (!VD-> isResilient ( F.getModule ().getSwiftModule (),
2001
+ require (!checkResilience (VD, F.getModule ().getSwiftModule (),
1993
2002
F.getResilienceExpansion ()),
1994
2003
" cannot access storage of resilient global" );
1995
2004
}
@@ -2677,8 +2686,8 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
2677
2686
require (!structDecl->hasUnreferenceableStorage (),
2678
2687
" Cannot build a struct with unreferenceable storage from elements "
2679
2688
" using StructInst" );
2680
- require (!structDecl-> isResilient ( F.getModule ().getSwiftModule (),
2681
- F.getResilienceExpansion ()),
2689
+ require (!checkResilience (structDecl, F.getModule ().getSwiftModule (),
2690
+ F.getResilienceExpansion ()),
2682
2691
" cannot access storage of resilient struct" );
2683
2692
require (SI->getType ().isObject (),
2684
2693
" StructInst must produce an object" );
@@ -2879,8 +2888,8 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
2879
2888
require (cd, " Operand of dealloc_ref must be of class type" );
2880
2889
2881
2890
if (!DI->canAllocOnStack ()) {
2882
- require (!cd-> isResilient ( F.getModule ().getSwiftModule (),
2883
- F.getResilienceExpansion ()),
2891
+ require (!checkResilience (cd, F.getModule ().getSwiftModule (),
2892
+ F.getResilienceExpansion ()),
2884
2893
" cannot directly deallocate resilient class" );
2885
2894
}
2886
2895
}
@@ -2996,7 +3005,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
2996
3005
" result of struct_extract cannot be address" );
2997
3006
StructDecl *sd = operandTy.getStructOrBoundGenericStruct ();
2998
3007
require (sd, " must struct_extract from struct" );
2999
- require (!sd-> isResilient ( F.getModule ().getSwiftModule (),
3008
+ require (!checkResilience (sd, F.getModule ().getSwiftModule (),
3000
3009
F.getResilienceExpansion ()),
3001
3010
" cannot access storage of resilient struct" );
3002
3011
require (!EI->getField ()->isStatic (),
@@ -3045,7 +3054,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
3045
3054
" must derive struct_element_addr from address" );
3046
3055
StructDecl *sd = operandTy.getStructOrBoundGenericStruct ();
3047
3056
require (sd, " struct_element_addr operand must be struct address" );
3048
- require (!sd-> isResilient ( F.getModule ().getSwiftModule (),
3057
+ require (!checkResilience (sd, F.getModule ().getSwiftModule (),
3049
3058
F.getResilienceExpansion ()),
3050
3059
" cannot access storage of resilient struct" );
3051
3060
require (EI->getType ().isAddress (),
@@ -3078,7 +3087,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
3078
3087
SILType operandTy = EI->getOperand ()->getType ();
3079
3088
ClassDecl *cd = operandTy.getClassOrBoundGenericClass ();
3080
3089
require (cd, " ref_element_addr operand must be a class instance" );
3081
- require (!cd-> isResilient ( F.getModule ().getSwiftModule (),
3090
+ require (!checkResilience (cd, F.getModule ().getSwiftModule (),
3082
3091
F.getResilienceExpansion ()),
3083
3092
" cannot access storage of resilient class" );
3084
3093
@@ -3102,7 +3111,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
3102
3111
SILType operandTy = RTAI->getOperand ()->getType ();
3103
3112
ClassDecl *cd = operandTy.getClassOrBoundGenericClass ();
3104
3113
require (cd, " ref_tail_addr operand must be a class instance" );
3105
- require (!cd-> isResilient ( F.getModule ().getSwiftModule (),
3114
+ require (!checkResilience (cd, F.getModule ().getSwiftModule (),
3106
3115
F.getResilienceExpansion ()),
3107
3116
" cannot access storage of resilient class" );
3108
3117
require (cd, " ref_tail_addr operand must be a class instance" );
@@ -3112,7 +3121,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
3112
3121
SILType operandTy = DSI->getOperand ()->getType ();
3113
3122
StructDecl *sd = operandTy.getStructOrBoundGenericStruct ();
3114
3123
require (sd, " must struct_extract from struct" );
3115
- require (!sd-> isResilient ( F.getModule ().getSwiftModule (),
3124
+ require (!checkResilience (sd, F.getModule ().getSwiftModule (),
3116
3125
F.getResilienceExpansion ()),
3117
3126
" cannot access storage of resilient struct" );
3118
3127
if (F.hasOwnership ()) {
0 commit comments