Skip to content

Commit 0d6b419

Browse files
committed
SILGen: Fix assertion failure when accessing a property with a __consuming getter
We checked isMutating() on the accessor, and if it was false, called isNonMutatingSelfIndirect(), which would assert that the accessor satisfies isNonMutating(). However, isNonMutating() is not the opposite of isMutating(); rather, one of isMutating(), isNonMutating() or isConsuming() is true. Change the assertion to reflect this case. Fixes rdar://problem/74095841.
1 parent c082cf6 commit 0d6b419

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

lib/SILGen/SILGenApply.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4265,11 +4265,12 @@ bool SILGenModule::shouldEmitSelfAsRValue(FuncDecl *fn, CanType selfType) {
42654265

42664266
bool SILGenModule::isNonMutatingSelfIndirect(SILDeclRef methodRef) {
42674267
auto method = methodRef.getFuncDecl();
4268-
assert(method->getDeclContext()->isTypeContext());
4269-
assert(method->isNonMutating());
42704268
if (method->isStatic())
42714269
return false;
42724270

4271+
assert(method->getDeclContext()->isTypeContext());
4272+
assert(method->isNonMutating() || method->isConsuming());
4273+
42734274
auto fnType = M.Types.getConstantFunctionType(TypeExpansionContext::minimal(),
42744275
methodRef);
42754276
auto importAsMember = method->getImportAsMemberStatus();

test/SILGen/value_ownership.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,31 @@ struct Witness: OwnershipProto {
5757

5858
// CHECK-LABEL: sil private [transparent] [thunk] [ossa] @$s15value_ownership7WitnessVAA14OwnershipProtoA2aDP17elidedPropertyGetSSvgTW :
5959
// CHECK-LABEL: sil private [transparent] [thunk] [ossa] @$s15value_ownership7WitnessVAA14OwnershipProtoA2aDP19explicitPropertyGetSSvgTW :
60+
61+
// Check that references to a consuming getter are lowered properly.
62+
63+
func blackHole<T>(_: T) {}
64+
65+
// CHECK-LABEL: sil hidden [ossa] @$s15value_ownership25useConsumingGetterGenericyyxAA14OwnershipProtoRzlF : $@convention(thin) <T where T : OwnershipProto> (@in_guaranteed T) -> () {
66+
func useConsumingGetterGeneric<T : OwnershipProto>(_ t: T) {
67+
// CHECK: [[FN:%.*]] = witness_method $T, #OwnershipProto.explicitPropertyGet!getter : <Self where Self : OwnershipProto> (__owned Self) -> () -> String : $@convention(witness_method: OwnershipProto) <τ_0_0 where τ_0_0 : OwnershipProto> (@in τ_0_0) -> @owned String
68+
// CHECK-NEXT: apply [[FN]]<T>({{%.*}}) : $@convention(witness_method: OwnershipProto) <τ_0_0 where τ_0_0 : OwnershipProto> (@in τ_0_0) -> @owned String
69+
70+
blackHole(t.explicitPropertyGet)
71+
}
72+
73+
// CHECK-LABEL: sil hidden [ossa] @$s15value_ownership29useConsumingGetterExistentialyyAA14OwnershipProto_pF : $@convention(thin) (@in_guaranteed OwnershipProto) -> () {
74+
func useConsumingGetterExistential(_ e: OwnershipProto) {
75+
// CHECK: [[FN:%.*]] = witness_method $@opened("{{.*}}") OwnershipProto, #OwnershipProto.explicitPropertyGet!getter : <Self where Self : OwnershipProto> (__owned Self) -> () -> String, %2 : $*@opened("{{.*}}") OwnershipProto : $@convention(witness_method: OwnershipProto) <τ_0_0 where τ_0_0 : OwnershipProto> (@in τ_0_0) -> @owned String
76+
// CHECK-NEXT: apply [[FN]]<@opened("{{.*}}") OwnershipProto>({{%.*}}) : $@convention(witness_method: OwnershipProto) <τ_0_0 where τ_0_0 : OwnershipProto> (@in τ_0_0) -> @owned String
77+
78+
blackHole(e.explicitPropertyGet)
79+
}
80+
81+
// CHECK-LABEL: sil hidden [ossa] @$s15value_ownership26useConsumingGetterConcreteyyAA7WitnessVF : $@convention(thin) (@guaranteed Witness) -> () {
82+
func useConsumingGetterConcrete(_ c: Witness) {
83+
// CHECK: [[FN:%.*]] = function_ref @$s15value_ownership7WitnessV19explicitPropertyGetSSvg : $@convention(method) (@owned Witness) -> @owned String
84+
// CHECK-NEXT: apply [[FN]]({{%.*}}) : $@convention(method) (@owned Witness) -> @owned String
85+
86+
blackHole(c.explicitPropertyGet)
87+
}

0 commit comments

Comments
 (0)