Skip to content

Commit de0de17

Browse files
committed
[Property Wrappers] Never use ReadWriteImplKind::Modify in the storage
impl info for property wrappers applied to local variables. Local property wrappers don't have a modify coroutine.
1 parent 3cbf31c commit de0de17

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/Sema/TypeCheckStorage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2921,7 +2921,7 @@ static void finishPropertyWrapperImplInfo(VarDecl *var,
29212921
return;
29222922
}
29232923

2924-
if (var->hasObservers()) {
2924+
if (var->hasObservers() || var->getDeclContext()->isLocalContext()) {
29252925
info = StorageImplInfo::getMutableComputed();
29262926
} else {
29272927
info = StorageImplInfo(ReadImplKind::Get, WriteImplKind::Set,

test/SILGen/property_wrapper_local.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ func testLocalWrapper() {
3535
// CHECK: mark_function_escape [[P]] : $*Wrapper<Int>
3636
// CHECK-LABEL: function_ref @$s22property_wrapper_local16testLocalWrapperyyF6$valueL_AA0F0VySiGvg : $@convention(thin) (@guaranteed { var Wrapper<Int> }) -> Wrapper<Int>
3737

38+
// Check that the wrapped value is materialized to a temporary when used as `inout`
39+
value += 5
40+
// CHECK: [[TMP:%.*]] = alloc_stack $Int
41+
// CHECK: [[GET:%.*]] = function_ref @$s22property_wrapper_local16testLocalWrapperyyF5valueL_Sivg : $@convention(thin) (@guaranteed { var Wrapper<Int> }) -> Int
42+
// CHECK: [[VAL:%.*]] = apply [[GET]]({{%.*}}) : $@convention(thin) (@guaranteed { var Wrapper<Int> }) -> Int
43+
// CHECK: store [[VAL]] to [trivial] [[TMP]] : $*Int
44+
// CHECK: [[OP:%.*]] = function_ref @$sSi2peoiyySiz_SitFZ : $@convention(method) (@inout Int, Int, @thin Int.Type) -> ()
45+
// CHECK: apply [[OP]]({{%.*}}) : $@convention(method) (@inout Int, Int, @thin Int.Type) -> ()
46+
// CHECK: [[RESULT:%.*]] = load [trivial] [[TMP]] : $*Int
47+
// CHECK: assign_by_wrapper [[RESULT]] : $Int to [[P]]
3848

3949
// Check local property wrapper backing initializer and accessors
4050

@@ -60,6 +70,12 @@ func testInitialValue() {
6070
value = 15
6171
// CHECK: function_ref @$s22property_wrapper_local16testInitialValueyyF5valueL_Sivs : $@convention(thin) (Int, @guaranteed { var Wrapper<Int> }) -> ()
6272
// CHECK-NOT: assign_by_wrapper
73+
74+
value += 5
75+
// CHECK: function_ref @$sSi2peoiyySiz_SitFZ : $@convention(method) (@inout Int, Int, @thin Int.Type) -> ()
76+
// CHECK: function_ref @$s22property_wrapper_local16testInitialValueyyF5valueL_Sivs : $@convention(thin) (Int, @guaranteed { var Wrapper<Int> }) -> ()
77+
// CHECK-NOT: assign_by_wrapper
78+
6379
// CHECK: return
6480

6581
// CHECK-LABEL: sil private [ossa] @$s22property_wrapper_local16testInitialValueyyF5valueL_SivpfP : $@convention(thin) (Int) -> Wrapper<Int> {

0 commit comments

Comments
 (0)