Skip to content

Commit 23a6b30

Browse files
authored
Merge pull request #79323 from slavapestov/fix-issue-79304-6.1
[6.1] SILGen: Fix verifier error when forming keypath to subscript with resilient index type
2 parents fd383dc + f4c8e73 commit 23a6b30

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

lib/SILGen/SILGenExpr.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4098,7 +4098,6 @@ lowerKeyPathSubscriptIndexTypes(
40984098
SmallVectorImpl<IndexTypePair> &indexPatterns,
40994099
SubscriptDecl *subscript,
41004100
SubstitutionMap subscriptSubs,
4101-
ResilienceExpansion expansion,
41024101
bool &needsGenericContext) {
41034102
// Capturing an index value dependent on the generic context means we
41044103
// need the generic context captured in the key path.
@@ -4118,7 +4117,8 @@ lowerKeyPathSubscriptIndexTypes(
41184117

41194118
auto indexLoweredTy = SGM.Types.getLoweredType(
41204119
AbstractionPattern::getOpaque(), indexTy,
4121-
TypeExpansionContext::noOpaqueTypeArchetypesSubstitution(expansion));
4120+
TypeExpansionContext::noOpaqueTypeArchetypesSubstitution(
4121+
ResilienceExpansion::Minimal));
41224122
indexLoweredTy = indexLoweredTy.mapTypeOutOfContext();
41234123
indexPatterns.push_back({indexTy->mapTypeOutOfContext()
41244124
->getCanonicalType(),
@@ -4345,7 +4345,6 @@ SILGenModule::emitKeyPathComponentForDecl(SILLocation loc,
43454345
SmallVector<IndexTypePair, 4> indexTypes;
43464346
lowerKeyPathSubscriptIndexTypes(*this, indexTypes,
43474347
decl, subs,
4348-
expansion,
43494348
needsGenericContext);
43504349

43514350
SmallVector<KeyPathPatternComponent::Index, 4> indexPatterns;

test/SILGen/keypaths_resilient.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %target-swift-emit-silgen %s -enable-library-evolution | %FileCheck %s
2+
3+
public enum E: Hashable {
4+
case e
5+
}
6+
7+
public struct S {
8+
public var dict: [E: Int] = [:]
9+
}
10+
11+
public func f() {
12+
let _ = \S.dict[.e]
13+
}
14+
15+
// CHECK-LABEL: sil [ossa] @$s18keypaths_resilient1fyyF : $@convention(thin) () -> () {
16+
// CHECK: [[ARG:%.*]] = alloc_stack $E
17+
// CHECK: store %1 to [trivial] [[ARG]]
18+
// CHECK: {{%.*}} = keypath $WritableKeyPath<S, Optional<Int>>, (root $S; stored_property #S.dict : $Dictionary<E, Int>; settable_property $Optional<Int>, id @$sSDyq_Sgxcig : $@convention(method) <τ_0_0, τ_0_1 where τ_0_0 : Hashable> (@in_guaranteed τ_0_0, @guaranteed Dictionary<τ_0_0, τ_0_1>) -> @out Optional<τ_0_1>, getter @$sSDyq_SgxcipSDy18keypaths_resilient1EOSiGADSiTK : $@convention(keypath_accessor_getter) (@in_guaranteed Dictionary<E, Int>, @in_guaranteed E) -> @out Optional<Int>, setter @$sSDyq_SgxcipSDy18keypaths_resilient1EOSiGADSiTk : $@convention(keypath_accessor_setter) (@in_guaranteed Optional<Int>, @inout Dictionary<E, Int>, @in_guaranteed E) -> (), indices [%$0 : $E : $*E], indices_equals @$s18keypaths_resilient1EOTH : $@convention(keypath_accessor_equals) (@in_guaranteed E, @in_guaranteed E) -> Bool, indices_hash @$s18keypaths_resilient1EOTh : $@convention(keypath_accessor_hash) (@in_guaranteed E) -> Int, external #Dictionary.subscript<E, Int>) ([[ARG]])
19+
// CHECK: return

0 commit comments

Comments
 (0)