Skip to content

Commit 1d13550

Browse files
authored
Merge pull request #35896 from slavapestov/fix-consuming-getter-assert
SILGen: Fix assertion failure when accessing a property with a __consuming getter
2 parents 00117e8 + c781ac0 commit 1d13550

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
@@ -4266,11 +4266,12 @@ bool SILGenModule::shouldEmitSelfAsRValue(FuncDecl *fn, CanType selfType) {
42664266

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

4272+
assert(method->getDeclContext()->isTypeContext());
4273+
assert(method->isNonMutating() || method->isConsuming());
4274+
42744275
auto fnType = M.Types.getConstantFunctionType(TypeExpansionContext::minimal(),
42754276
methodRef);
42764277
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)