@@ -119,6 +119,7 @@ namespace {
119
119
120
120
// / Verify invariants on a key path component.
121
121
void verifyKeyPathComponent (SILModule &M,
122
+ ResilienceExpansion expansion,
122
123
llvm::function_ref<void (bool , StringRef)> require,
123
124
CanType &baseTy,
124
125
CanType leafTy,
@@ -211,13 +212,21 @@ void verifyKeyPathComponent(SILModule &M,
211
212
switch (auto kind = component.getKind ()) {
212
213
case KeyPathPatternComponent::Kind::StoredProperty: {
213
214
auto property = component.getStoredPropertyDecl ();
215
+ if (expansion == ResilienceExpansion::Minimal) {
216
+ require (property->getEffectiveAccess () >= AccessLevel::Public,
217
+ " Key path in serialized function cannot reference non-public "
218
+ " property" );
219
+ }
220
+
214
221
auto fieldTy = baseTy->getTypeOfMember (M.getSwiftModule (), property)
215
222
->getReferenceStorageReferent ()
216
223
->getCanonicalType ();
217
224
require (fieldTy == componentTy,
218
225
" property decl should be a member of the base with the same type "
219
226
" as the component" );
220
227
require (property->hasStorage (), " property must be stored" );
228
+ require (!property->isResilient (M.getSwiftModule (), expansion),
229
+ " cannot access storage of resilient property" );
221
230
auto propertyTy = loweredBaseTy.getFieldType (property, M);
222
231
require (propertyTy.getObjectType ()
223
232
== loweredComponentTy.getObjectType (),
@@ -247,6 +256,12 @@ void verifyKeyPathComponent(SILModule &M,
247
256
// Getter should be <Sig...> @convention(thin) (@in_guaranteed Base) -> @out Result
248
257
{
249
258
auto getter = component.getComputedPropertyGetter ();
259
+ if (expansion == ResilienceExpansion::Minimal) {
260
+ require (getter->hasValidLinkageForFragileRef (),
261
+ " Key path in serialized function should not reference "
262
+ " less visible getters" );
263
+ }
264
+
250
265
auto substGetterType = getter->getLoweredFunctionType ()
251
266
->substGenericArgs (M, patternSubs);
252
267
require (substGetterType->getRepresentation () ==
@@ -286,6 +301,12 @@ void verifyKeyPathComponent(SILModule &M,
286
301
// <Sig...> @convention(thin) (@in_guaranteed Result, @in Base) -> ()
287
302
288
303
auto setter = component.getComputedPropertySetter ();
304
+ if (expansion == ResilienceExpansion::Minimal) {
305
+ require (setter->hasValidLinkageForFragileRef (),
306
+ " Key path in serialized function should not reference "
307
+ " less visible setters" );
308
+ }
309
+
289
310
auto substSetterType = setter->getLoweredFunctionType ()
290
311
->substGenericArgs (M, patternSubs);
291
312
@@ -4242,7 +4263,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
4242
4263
break ;
4243
4264
}
4244
4265
4245
- verifyKeyPathComponent (F.getModule (),
4266
+ verifyKeyPathComponent (F.getModule (), F. getResilienceExpansion (),
4246
4267
[&](bool reqt, StringRef message) { _require (reqt, message); },
4247
4268
baseTy,
4248
4269
leafTy,
@@ -4879,15 +4900,16 @@ void SILProperty::verify(const SILModule &M) const {
4879
4900
4880
4901
if (auto &component = getComponent ()) {
4881
4902
verifyKeyPathComponent (const_cast <SILModule&>(M),
4882
- require,
4883
- baseTy,
4884
- leafTy,
4885
- *component,
4886
- {},
4887
- canSig,
4888
- subs,
4889
- /* property descriptor*/ true ,
4890
- hasIndices);
4903
+ ResilienceExpansion::Maximal,
4904
+ require,
4905
+ baseTy,
4906
+ leafTy,
4907
+ *component,
4908
+ {},
4909
+ canSig,
4910
+ subs,
4911
+ /* property descriptor*/ true ,
4912
+ hasIndices);
4891
4913
// verifyKeyPathComponent updates baseTy to be the projected type of the
4892
4914
// component, which should be the same as the type of the declared storage
4893
4915
require (baseTy == leafTy,
0 commit comments