-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Typechecker] Fix _modify for wrapped properties with observers #29931
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
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
216ae87
[Typechecker] Wrapped properties with observers should not have ReadW…
theblixguy ba481f3
[Typechecker] Supress _modify synthesis if the wrapped property has o…
theblixguy 82a163e
[Test] Add an executable test
theblixguy 84f8e41
[Typechecker] Add an hasObservers() convenience method and simplify s…
theblixguy 2fbd89d
[Typechecker] Simplify StorageImplInfo code in finishPropertyWrapperI…
theblixguy 4688f4d
[Test] Add a SILGen test to make sure the observers are correctly called
theblixguy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// RUN: %target-swift-emit-silgen %s | %FileCheck %s | ||
|
||
// 1. Make sure the wrapped property setter calls the observers | ||
// 2. Make sure the synthesized _modify coroutine calls the wrapped property setter | ||
|
||
@propertyWrapper | ||
struct Foo { | ||
private var _storage: [Int] = [] | ||
|
||
init(wrappedValue value: [Int]) { | ||
self._storage = value | ||
} | ||
|
||
var wrappedValue: [Int] { | ||
get { _storage } | ||
set { _storage = newValue } | ||
} | ||
} | ||
|
||
class Bar { | ||
@Foo var someArray = [1, 2, 3] { | ||
willSet {} | ||
didSet {} | ||
} | ||
} | ||
|
||
// Bar.someArray.setter | ||
|
||
// CHECK-LABEL: sil hidden [ossa] @$s26property_wrapper_observers3BarC9someArraySaySiGvs : $@convention(method) (@owned Array<Int>, @guaranteed Bar) -> () { | ||
// CHECK: bb0([[VALUE:%.*]] : @owned $Array<Int>, [[BAR:%.*]] : @guaranteed $Bar): | ||
|
||
// CHECK: [[WILLSET:%.*]] = function_ref @$s26property_wrapper_observers3BarC9someArraySaySiGvw : $@convention(method) (@guaranteed Array<Int>, @guaranteed Bar) -> () | ||
// CHECK-NEXT: [[RESULT_WS:%.*]] = apply [[WILLSET]](%{{[0-9]+}}, [[BAR]]) : $@convention(method) (@guaranteed Array<Int>, @guaranteed Bar) -> () | ||
|
||
// CHECK: [[WRAPPED_VALUE_SETTER:%.*]] = function_ref @$s26property_wrapper_observers3FooV12wrappedValueSaySiGvs : $@convention(method) (@owned Array<Int>, @inout Foo) -> () | ||
// CHECK-NEXT: [[RESULT_WVS:%.*]] = apply [[WRAPPED_VALUE_SETTER]](%{{[0-9]+}}, %{{[0-9]+}}) : $@convention(method) (@owned Array<Int>, @inout Foo) -> () | ||
|
||
// CHECK: [[DIDSET:%.*]] = function_ref @$s26property_wrapper_observers3BarC9someArraySaySiGvW : $@convention(method) (@guaranteed Bar) -> () | ||
// CHECK-NEXT: [[RESULT_DS:%.*]] = apply [[DIDSET]]([[BAR]]) : $@convention(method) (@guaranteed Bar) -> () | ||
// CHECK: } | ||
|
||
// Bar.someArray.modify | ||
|
||
// CHECK-LABEL: sil hidden [ossa] @$s26property_wrapper_observers3BarC9someArraySaySiGvM : $@yield_once @convention(method) (@guaranteed Bar) -> @yields @inout Array<Int> { | ||
// CHECK: bb0([[BAR:%.*]] : @guaranteed $Bar): | ||
// CHECK-NEXT: debug_value [[BAR]] : $Bar, let, name "self", argno 1 | ||
// CHECK-NEXT: [[ALLOC_STACK:%.*]] = alloc_stack $Array<Int> | ||
// CHECK-NEXT: // function_ref Bar.someArray.getter | ||
// CHECK-NEXT: [[GETTER:%.*]] = function_ref @$s26property_wrapper_observers3BarC9someArraySaySiGvg : $@convention(method) (@guaranteed Bar) -> @owned Array<Int> | ||
// CHECK-NEXT: [[RESULT:%.*]] = apply [[GETTER]]([[BAR]]) : $@convention(method) (@guaranteed Bar) -> @owned Array<Int> | ||
// CHECK-NEXT: store [[RESULT]] to [init] [[ALLOC_STACK]] : $*Array<Int> | ||
// CHECK-NEXT: yield [[ALLOC_STACK]] : $*Array<Int>, resume bb1, unwind bb2 | ||
|
||
// CHECK: bb1: | ||
// CHECK-NEXT: [[VALUE:%.*]] = load [take] [[ALLOC_STACK]] : $*Array<Int> | ||
// CHECK-NEXT: // function_ref Bar.someArray.setter | ||
// CHECK-NEXT: [[SETTER:%.*]] = function_ref @$s26property_wrapper_observers3BarC9someArraySaySiGvs : $@convention(method) (@owned Array<Int>, @guaranteed Bar) -> () | ||
// CHECK-NEXT: [[RESULT:%.*]] = apply [[SETTER]]([[VALUE]], [[BAR]]) : $@convention(method) (@owned Array<Int>, @guaranteed Bar) -> () | ||
// CHECK-NEXT: dealloc_stack [[ALLOC_STACK]] : $*Array<Int> | ||
// CHECK-NEXT: [[TUPLE:%.*]] = tuple () | ||
// CHECK-NEXT: return [[TUPLE]] : $() | ||
|
||
// CHECK: bb2: | ||
// CHECK-NEXT: [[NEWVALUE:%.*]] = load [copy] [[ALLOC_STACK]] : $*Array<Int> | ||
// CHECK-NEXT: // function_ref Bar.someArray.setter | ||
// CHECK-NEXT: [[SETTER:%.*]] = function_ref @$s26property_wrapper_observers3BarC9someArraySaySiGvs : $@convention(method) (@owned Array<Int>, @guaranteed Bar) -> () | ||
// CHECK-NEXT: [[RESULT:%.*]] = apply [[SETTER]]([[NEWVALUE]], [[BAR]]) : $@convention(method) (@owned Array<Int>, @guaranteed Bar) -> () | ||
// CHECK-NEXT: destroy_addr [[ALLOC_STACK]] : $*Array<Int> | ||
// CHECK-NEXT: dealloc_stack [[ALLOC_STACK]] : $*Array<Int> | ||
// CHECK-NEXT: unwind | ||
// CHECK-END: } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// RUN: %target-run-simple-swift | ||
|
||
// REQUIRES: executable_test | ||
|
||
@propertyWrapper | ||
struct Foo { | ||
private var _storage: [Int] = [] | ||
|
||
init(wrappedValue value: [Int]) { | ||
self._storage = value | ||
} | ||
|
||
var wrappedValue: [Int] { | ||
get { _storage } | ||
set { _storage = newValue } | ||
} | ||
} | ||
|
||
class Bar { | ||
@Foo var someArray = [1, 2, 3] { | ||
willSet { | ||
print(newValue) | ||
} | ||
|
||
didSet { | ||
print(oldValue) | ||
} | ||
} | ||
} | ||
|
||
let bar = Bar() | ||
// CHECK: [4, 2, 3] | ||
// CHECK: [1, 2, 3] | ||
bar.someArray[0] = 4 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.