Skip to content

SILGen: Don't emit getters twice for global observing variables #23324

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/SILGen/SILGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1291,7 +1291,9 @@ void SILGenModule::visitVarDecl(VarDecl *vd) {
auto impl = vd->getImplInfo();
switch (kind) {
case AccessorKind::Get:
return impl.getReadImpl() != ReadImplKind::Get;
return impl.getReadImpl() != ReadImplKind::Get &&
!(impl.getReadImpl() == ReadImplKind::Stored &&
impl.getWriteImpl() == WriteImplKind::StoredWithObservers);
case AccessorKind::Read:
return impl.getReadImpl() != ReadImplKind::Read;
case AccessorKind::Set:
Expand Down
43 changes: 37 additions & 6 deletions test/SILGen/properties.swift
Original file line number Diff line number Diff line change
Expand Up @@ -650,12 +650,6 @@ var global_observing_property : Int = zero {

// global_observing_property's setter needs to call didSet.

// CHECK-LABEL: sil hidden [ossa] @$s10properties25global_observing_property{{[_0-9a-zA-Z]*}}vs
// CHECK: function_ref properties.global_observing_property.unsafeMutableAddressor
// CHECK-NEXT: function_ref @$s10properties25global_observing_property{{[_0-9a-zA-Z]*}}vau
// CHECK: function_ref properties.global_observing_property.didset
// CHECK-NEXT: function_ref @$s10properties25global_observing_property{{[_0-9a-zA-Z]*}}vW

// CHECK-LABEL: sil private [ossa] @$s10properties25global_observing_property{{[_0-9a-zA-Z]*}}vW
didSet {
// The didSet implementation needs to call takeInt.
Expand Down Expand Up @@ -684,6 +678,12 @@ var global_observing_property : Int = zero {
// CHECK-NOT: function_ref @$s10properties25global_observing_property{{[_0-9a-zA-Z]*}}vW
// CHECK: end sil function
}
// CHECK-LABEL: sil hidden [ossa] @$s10properties25global_observing_property{{[_0-9a-zA-Z]*}}vs
// CHECK: function_ref properties.global_observing_property.unsafeMutableAddressor
// CHECK-NEXT: function_ref @$s10properties25global_observing_property{{[_0-9a-zA-Z]*}}vau
// CHECK: function_ref properties.global_observing_property.didset
// CHECK-NEXT: function_ref @$s10properties25global_observing_property{{[_0-9a-zA-Z]*}}vW

}

func force_global_observing_property_setter() {
Expand Down Expand Up @@ -1261,3 +1261,34 @@ func assign_to_tuple() {
let v = (3, 4)
s.vv = v
}

// CHECK-LABEL: sil private [ossa] @$s10properties8myglobalSivW
// CHECK-LABEL: sil [ossa] @$s10properties8myglobalSivg
// CHECK-LABEL: sil [ossa] @$s10properties8myglobalSivs
public var myglobal : Int = 1 {
didSet {
print("myglobal.didSet")
}
}

// CHECK-LABEL: sil private [ossa] @$s10properties9myglobal2Sivw
// CHECK-LABEL: sil [ossa] @$s10properties9myglobal2Sivg
// CHECK-LABEL: sil [ossa] @$s10properties9myglobal2Sivs
public var myglobal2 : Int = 1 {
willSet {
print("myglobal.willSet")
}
}

// CHECK-LABEL: sil private [ossa] @$s10properties9myglobal3Sivw
// CHECK-LABEL: sil private [ossa] @$s10properties9myglobal3SivW
// CHECK-LABEL: sil [ossa] @$s10properties9myglobal3Sivg
// CHECK-LABEL: sil [ossa] @$s10properties9myglobal3Sivs
public var myglobal3 : Int = 1 {
willSet {
print("myglobal.willSet")
}
didSet {
print("myglobal.didSet")
}
}