Skip to content

Commit dbcad66

Browse files
Merge pull request #23324 from aschwaighofer/silgen_getters_global_observing_vars
SILGen: Don't emit getters twice for global observing variables
2 parents 8e14023 + 50e855d commit dbcad66

File tree

2 files changed

+40
-7
lines changed

2 files changed

+40
-7
lines changed

lib/SILGen/SILGen.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1291,7 +1291,9 @@ void SILGenModule::visitVarDecl(VarDecl *vd) {
12911291
auto impl = vd->getImplInfo();
12921292
switch (kind) {
12931293
case AccessorKind::Get:
1294-
return impl.getReadImpl() != ReadImplKind::Get;
1294+
return impl.getReadImpl() != ReadImplKind::Get &&
1295+
!(impl.getReadImpl() == ReadImplKind::Stored &&
1296+
impl.getWriteImpl() == WriteImplKind::StoredWithObservers);
12951297
case AccessorKind::Read:
12961298
return impl.getReadImpl() != ReadImplKind::Read;
12971299
case AccessorKind::Set:

test/SILGen/properties.swift

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -650,12 +650,6 @@ var global_observing_property : Int = zero {
650650

651651
// global_observing_property's setter needs to call didSet.
652652

653-
// CHECK-LABEL: sil hidden [ossa] @$s10properties25global_observing_property{{[_0-9a-zA-Z]*}}vs
654-
// CHECK: function_ref properties.global_observing_property.unsafeMutableAddressor
655-
// CHECK-NEXT: function_ref @$s10properties25global_observing_property{{[_0-9a-zA-Z]*}}vau
656-
// CHECK: function_ref properties.global_observing_property.didset
657-
// CHECK-NEXT: function_ref @$s10properties25global_observing_property{{[_0-9a-zA-Z]*}}vW
658-
659653
// CHECK-LABEL: sil private [ossa] @$s10properties25global_observing_property{{[_0-9a-zA-Z]*}}vW
660654
didSet {
661655
// The didSet implementation needs to call takeInt.
@@ -684,6 +678,12 @@ var global_observing_property : Int = zero {
684678
// CHECK-NOT: function_ref @$s10properties25global_observing_property{{[_0-9a-zA-Z]*}}vW
685679
// CHECK: end sil function
686680
}
681+
// CHECK-LABEL: sil hidden [ossa] @$s10properties25global_observing_property{{[_0-9a-zA-Z]*}}vs
682+
// CHECK: function_ref properties.global_observing_property.unsafeMutableAddressor
683+
// CHECK-NEXT: function_ref @$s10properties25global_observing_property{{[_0-9a-zA-Z]*}}vau
684+
// CHECK: function_ref properties.global_observing_property.didset
685+
// CHECK-NEXT: function_ref @$s10properties25global_observing_property{{[_0-9a-zA-Z]*}}vW
686+
687687
}
688688

689689
func force_global_observing_property_setter() {
@@ -1261,3 +1261,34 @@ func assign_to_tuple() {
12611261
let v = (3, 4)
12621262
s.vv = v
12631263
}
1264+
1265+
// CHECK-LABEL: sil private [ossa] @$s10properties8myglobalSivW
1266+
// CHECK-LABEL: sil [ossa] @$s10properties8myglobalSivg
1267+
// CHECK-LABEL: sil [ossa] @$s10properties8myglobalSivs
1268+
public var myglobal : Int = 1 {
1269+
didSet {
1270+
print("myglobal.didSet")
1271+
}
1272+
}
1273+
1274+
// CHECK-LABEL: sil private [ossa] @$s10properties9myglobal2Sivw
1275+
// CHECK-LABEL: sil [ossa] @$s10properties9myglobal2Sivg
1276+
// CHECK-LABEL: sil [ossa] @$s10properties9myglobal2Sivs
1277+
public var myglobal2 : Int = 1 {
1278+
willSet {
1279+
print("myglobal.willSet")
1280+
}
1281+
}
1282+
1283+
// CHECK-LABEL: sil private [ossa] @$s10properties9myglobal3Sivw
1284+
// CHECK-LABEL: sil private [ossa] @$s10properties9myglobal3SivW
1285+
// CHECK-LABEL: sil [ossa] @$s10properties9myglobal3Sivg
1286+
// CHECK-LABEL: sil [ossa] @$s10properties9myglobal3Sivs
1287+
public var myglobal3 : Int = 1 {
1288+
willSet {
1289+
print("myglobal.willSet")
1290+
}
1291+
didSet {
1292+
print("myglobal.didSet")
1293+
}
1294+
}

0 commit comments

Comments
 (0)