@@ -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
@@ -4750,12 +4753,17 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
4750
4753
auto pattern = KPI->getPattern ();
4751
4754
SubstitutionMap patternSubs = KPI->getSubstitutions ();
4752
4755
requireSameType (
4753
- baseTy, pattern->getRootType ().subst (patternSubs)->getCanonicalType (),
4756
+ F.getLoweredType (baseTy).getASTType (),
4757
+ F.getLoweredType (
4758
+ pattern->getRootType ().subst (patternSubs)->getCanonicalType ()).getASTType (),
4754
4759
" keypath root type should match root type of keypath pattern" );
4755
4760
4756
4761
auto leafTy = CanType (kpBGT->getGenericArgs ()[1 ]);
4757
4762
requireSameType (
4758
- leafTy, pattern->getValueType ().subst (patternSubs)->getCanonicalType (),
4763
+ F.getLoweredType (leafTy).getASTType (),
4764
+ F.getLoweredType (
4765
+ pattern->getValueType ().subst (patternSubs)->getCanonicalType ())
4766
+ .getASTType (),
4759
4767
" keypath value type should match value type of keypath pattern" );
4760
4768
4761
4769
{
@@ -4776,7 +4784,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
4776
4784
break ;
4777
4785
}
4778
4786
4779
- verifyKeyPathComponent (F.getModule (), F.getResilienceExpansion (),
4787
+ verifyKeyPathComponent (F.getModule (), F.getTypeExpansionContext (),
4780
4788
[&](bool reqt, StringRef message) { _require (reqt, message); },
4781
4789
baseTy,
4782
4790
leafTy,
@@ -4789,7 +4797,8 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
4789
4797
}
4790
4798
}
4791
4799
requireSameType (
4792
- CanType (baseTy), CanType (leafTy),
4800
+ F.getLoweredType (CanType (baseTy)).getASTType (),
4801
+ F.getLoweredType (CanType (leafTy)).getASTType (),
4793
4802
" final component should match leaf value type of key path type" );
4794
4803
}
4795
4804
@@ -5609,8 +5618,11 @@ void SILProperty::verify(const SILModule &M) const {
5609
5618
};
5610
5619
5611
5620
if (auto &component = getComponent ()) {
5621
+ auto typeExpansionContext =
5622
+ TypeExpansionContext::noOpaqueTypeArchetypesSubstitution (
5623
+ ResilienceExpansion::Maximal);
5612
5624
verifyKeyPathComponent (const_cast <SILModule&>(M),
5613
- ResilienceExpansion::Maximal ,
5625
+ typeExpansionContext ,
5614
5626
require,
5615
5627
baseTy,
5616
5628
leafTy,
0 commit comments