@@ -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);
@@ -2045,7 +2054,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
2045
2054
void checkAllocGlobalInst (AllocGlobalInst *AGI) {
2046
2055
SILGlobalVariable *RefG = AGI->getReferencedGlobal ();
2047
2056
if (auto *VD = RefG->getDecl ()) {
2048
- require (!VD-> isResilient ( F.getModule ().getSwiftModule (),
2057
+ require (!checkResilience (VD, F.getModule ().getSwiftModule (),
2049
2058
F.getResilienceExpansion ()),
2050
2059
" cannot access storage of resilient global" );
2051
2060
}
@@ -2064,7 +2073,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
2064
2073
RefG->getLoweredTypeInContext (F.getTypeExpansionContext ()),
2065
2074
" global_addr/value must be the type of the variable it references" );
2066
2075
if (auto *VD = RefG->getDecl ()) {
2067
- require (!VD-> isResilient ( F.getModule ().getSwiftModule (),
2076
+ require (!checkResilience (VD, F.getModule ().getSwiftModule (),
2068
2077
F.getResilienceExpansion ()),
2069
2078
" cannot access storage of resilient global" );
2070
2079
}
@@ -2752,8 +2761,8 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
2752
2761
require (!structDecl->hasUnreferenceableStorage (),
2753
2762
" Cannot build a struct with unreferenceable storage from elements "
2754
2763
" using StructInst" );
2755
- require (!structDecl-> isResilient ( F.getModule ().getSwiftModule (),
2756
- F.getResilienceExpansion ()),
2764
+ require (!checkResilience (structDecl, F.getModule ().getSwiftModule (),
2765
+ F.getResilienceExpansion ()),
2757
2766
" cannot access storage of resilient struct" );
2758
2767
require (SI->getType ().isObject (),
2759
2768
" StructInst must produce an object" );
@@ -2954,8 +2963,8 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
2954
2963
require (cd, " Operand of dealloc_ref must be of class type" );
2955
2964
2956
2965
if (!DI->canAllocOnStack ()) {
2957
- require (!cd-> isResilient ( F.getModule ().getSwiftModule (),
2958
- F.getResilienceExpansion ()),
2966
+ require (!checkResilience (cd, F.getModule ().getSwiftModule (),
2967
+ F.getResilienceExpansion ()),
2959
2968
" cannot directly deallocate resilient class" );
2960
2969
}
2961
2970
}
@@ -3071,7 +3080,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
3071
3080
" result of struct_extract cannot be address" );
3072
3081
StructDecl *sd = operandTy.getStructOrBoundGenericStruct ();
3073
3082
require (sd, " must struct_extract from struct" );
3074
- require (!sd-> isResilient ( F.getModule ().getSwiftModule (),
3083
+ require (!checkResilience (sd, F.getModule ().getSwiftModule (),
3075
3084
F.getResilienceExpansion ()),
3076
3085
" cannot access storage of resilient struct" );
3077
3086
require (!EI->getField ()->isStatic (),
@@ -3120,7 +3129,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
3120
3129
" must derive struct_element_addr from address" );
3121
3130
StructDecl *sd = operandTy.getStructOrBoundGenericStruct ();
3122
3131
require (sd, " struct_element_addr operand must be struct address" );
3123
- require (!sd-> isResilient ( F.getModule ().getSwiftModule (),
3132
+ require (!checkResilience (sd, F.getModule ().getSwiftModule (),
3124
3133
F.getResilienceExpansion ()),
3125
3134
" cannot access storage of resilient struct" );
3126
3135
require (EI->getType ().isAddress (),
@@ -3153,7 +3162,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
3153
3162
SILType operandTy = EI->getOperand ()->getType ();
3154
3163
ClassDecl *cd = operandTy.getClassOrBoundGenericClass ();
3155
3164
require (cd, " ref_element_addr operand must be a class instance" );
3156
- require (!cd-> isResilient ( F.getModule ().getSwiftModule (),
3165
+ require (!checkResilience (cd, F.getModule ().getSwiftModule (),
3157
3166
F.getResilienceExpansion ()),
3158
3167
" cannot access storage of resilient class" );
3159
3168
@@ -3177,7 +3186,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
3177
3186
SILType operandTy = RTAI->getOperand ()->getType ();
3178
3187
ClassDecl *cd = operandTy.getClassOrBoundGenericClass ();
3179
3188
require (cd, " ref_tail_addr operand must be a class instance" );
3180
- require (!cd-> isResilient ( F.getModule ().getSwiftModule (),
3189
+ require (!checkResilience (cd, F.getModule ().getSwiftModule (),
3181
3190
F.getResilienceExpansion ()),
3182
3191
" cannot access storage of resilient class" );
3183
3192
require (cd, " ref_tail_addr operand must be a class instance" );
@@ -3187,7 +3196,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
3187
3196
SILType operandTy = DSI->getOperand ()->getType ();
3188
3197
StructDecl *sd = operandTy.getStructOrBoundGenericStruct ();
3189
3198
require (sd, " must struct_extract from struct" );
3190
- require (!sd-> isResilient ( F.getModule ().getSwiftModule (),
3199
+ require (!checkResilience (sd, F.getModule ().getSwiftModule (),
3191
3200
F.getResilienceExpansion ()),
3192
3201
" cannot access storage of resilient struct" );
3193
3202
if (F.hasOwnership ()) {
0 commit comments