@@ -130,7 +130,7 @@ namespace {
130
130
131
131
// / Verify invariants on a key path component.
132
132
void verifyKeyPathComponent (SILModule &M,
133
- ResilienceExpansion expansion ,
133
+ TypeExpansionContext typeExpansionContext ,
134
134
llvm::function_ref<void (bool , StringRef)> require,
135
135
CanType &baseTy,
136
136
CanType leafTy,
@@ -141,16 +141,17 @@ void verifyKeyPathComponent(SILModule &M,
141
141
bool forPropertyDescriptor,
142
142
bool hasIndices) {
143
143
auto &C = M.getASTContext ();
144
- auto typeExpansionContext =
145
- TypeExpansionContext::noOpaqueTypeArchetypesSubstitution (expansion);
144
+ auto expansion = typeExpansionContext.getResilienceExpansion ();
146
145
auto opaque = AbstractionPattern::getOpaque ();
147
146
auto loweredBaseTy =
148
147
M.Types .getLoweredType (opaque, baseTy, typeExpansionContext);
149
148
auto componentTy = component.getComponentType ().subst (patternSubs)
150
149
->getCanonicalType ();
151
150
auto loweredComponentTy =
152
151
M.Types .getLoweredType (opaque, componentTy, typeExpansionContext);
153
-
152
+ auto getTypeInExpansionContext = [&](CanType ty) -> CanType {
153
+ return M.Types .getLoweredType (opaque, ty, typeExpansionContext).getASTType ();
154
+ };
154
155
auto checkIndexEqualsAndHash = [&]{
155
156
if (!component.getSubscriptIndices ().empty ()) {
156
157
// Equals should be
@@ -236,7 +237,8 @@ void verifyKeyPathComponent(SILModule &M,
236
237
auto fieldTy = baseTy->getTypeOfMember (M.getSwiftModule (), property)
237
238
->getReferenceStorageReferent ()
238
239
->getCanonicalType ();
239
- require (fieldTy == componentTy,
240
+ require (getTypeInExpansionContext (fieldTy) ==
241
+ getTypeInExpansionContext (componentTy),
240
242
" property decl should be a member of the base with the same type "
241
243
" as the component" );
242
244
require (property->hasStorage (), " property must be stored" );
@@ -289,10 +291,11 @@ void verifyKeyPathComponent(SILModule &M,
289
291
auto baseParam = substGetterType->getParameters ()[0 ];
290
292
require (baseParam.getConvention () == normalArgConvention,
291
293
" getter base parameter should have normal arg convention" );
292
- require (baseParam.getArgumentType (M, substGetterType, typeExpansionContext)
293
- == loweredBaseTy.getASTType (),
294
+ require (getTypeInExpansionContext (baseParam.getArgumentType (
295
+ M, substGetterType, typeExpansionContext)) ==
296
+ loweredBaseTy.getASTType (),
294
297
" getter base parameter should match base of component" );
295
-
298
+
296
299
if (hasIndices) {
297
300
auto indicesParam = substGetterType->getParameters ()[1 ];
298
301
require (indicesParam.getConvention ()
@@ -310,11 +313,11 @@ void verifyKeyPathComponent(SILModule &M,
310
313
auto result = substGetterType->getResults ()[0 ];
311
314
require (result.getConvention () == ResultConvention::Indirect,
312
315
" getter result should be @out" );
313
- require (
314
- result. getReturnValueType ( M, substGetterType, typeExpansionContext) ==
315
- loweredComponentTy.getASTType (),
316
- " getter result should match the maximal abstraction of the "
317
- " formal component type" );
316
+ require (getTypeInExpansionContext (result. getReturnValueType (
317
+ M, substGetterType, typeExpansionContext) ) ==
318
+ getTypeInExpansionContext ( loweredComponentTy.getASTType () ),
319
+ " getter result should match the maximal abstraction of the "
320
+ " formal component type" );
318
321
}
319
322
320
323
if (kind == KeyPathPatternComponent::Kind::SettableProperty) {
@@ -363,9 +366,9 @@ void verifyKeyPathComponent(SILModule &M,
363
366
" indices pointer should be an UnsafeRawPointer" );
364
367
}
365
368
366
- require (newValueParam.getArgumentType (M, substSetterType,
367
- typeExpansionContext) ==
368
- loweredComponentTy.getASTType (),
369
+ require (getTypeInExpansionContext ( newValueParam.getArgumentType (
370
+ M, substSetterType, typeExpansionContext) ) ==
371
+ getTypeInExpansionContext ( loweredComponentTy.getASTType () ),
369
372
" setter value should match the maximal abstraction of the "
370
373
" formal component type" );
371
374
@@ -4736,12 +4739,17 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
4736
4739
auto pattern = KPI->getPattern ();
4737
4740
SubstitutionMap patternSubs = KPI->getSubstitutions ();
4738
4741
requireSameType (
4739
- baseTy, pattern->getRootType ().subst (patternSubs)->getCanonicalType (),
4742
+ F.getLoweredType (baseTy).getASTType (),
4743
+ F.getLoweredType (
4744
+ pattern->getRootType ().subst (patternSubs)->getCanonicalType ()).getASTType (),
4740
4745
" keypath root type should match root type of keypath pattern" );
4741
4746
4742
4747
auto leafTy = CanType (kpBGT->getGenericArgs ()[1 ]);
4743
4748
requireSameType (
4744
- leafTy, pattern->getValueType ().subst (patternSubs)->getCanonicalType (),
4749
+ F.getLoweredType (leafTy).getASTType (),
4750
+ F.getLoweredType (
4751
+ pattern->getValueType ().subst (patternSubs)->getCanonicalType ())
4752
+ .getASTType (),
4745
4753
" keypath value type should match value type of keypath pattern" );
4746
4754
4747
4755
{
@@ -4762,7 +4770,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
4762
4770
break ;
4763
4771
}
4764
4772
4765
- verifyKeyPathComponent (F.getModule (), F.getResilienceExpansion (),
4773
+ verifyKeyPathComponent (F.getModule (), F.getTypeExpansionContext (),
4766
4774
[&](bool reqt, StringRef message) { _require (reqt, message); },
4767
4775
baseTy,
4768
4776
leafTy,
@@ -4775,7 +4783,8 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
4775
4783
}
4776
4784
}
4777
4785
requireSameType (
4778
- CanType (baseTy), CanType (leafTy),
4786
+ F.getLoweredType (CanType (baseTy)).getASTType (),
4787
+ F.getLoweredType (CanType (leafTy)).getASTType (),
4779
4788
" final component should match leaf value type of key path type" );
4780
4789
}
4781
4790
@@ -5595,8 +5604,11 @@ void SILProperty::verify(const SILModule &M) const {
5595
5604
};
5596
5605
5597
5606
if (auto &component = getComponent ()) {
5607
+ auto typeExpansionContext =
5608
+ TypeExpansionContext::noOpaqueTypeArchetypesSubstitution (
5609
+ ResilienceExpansion::Maximal);
5598
5610
verifyKeyPathComponent (const_cast <SILModule&>(M),
5599
- ResilienceExpansion::Maximal ,
5611
+ typeExpansionContext ,
5600
5612
require,
5601
5613
baseTy,
5602
5614
leafTy,
0 commit comments