-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Typechecker] Fix _modify for properties using a property wrapper #28216
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
7 commits
Select commit
Hold shift + click to select a range
47ba176
[Typechecker] Fix _modify for properties using a property wrapper
theblixguy 42473e3
[Test] Update test to check for _read coroutine as well
theblixguy 7244f6c
[Typechecker] Synthesize _modify for storage wrapper correctly
theblixguy 0cd5906
[Test] Update a few failing tests
theblixguy 33be7a2
[Typechecker] Don't use PropertyWrapperMutability for isSelfLValue check
theblixguy 1264c56
Revert "[Typechecker] Don't use PropertyWrapperMutability for isSelfL…
theblixguy 6d96447
[Typechecker] PropertyWrapperMutabilityRequest should not return None…
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// RUN: %target-swift-emit-silgen %s | %FileCheck %s | ||
|
||
@propertyWrapper | ||
struct TestWrapper<ValueType> { | ||
var wrappedValue: ValueType | ||
} | ||
|
||
struct State { | ||
@TestWrapper var values: [String] = [] | ||
} | ||
|
||
protocol StateProtocol { | ||
@_borrowed var someValues: [String] { get set } | ||
} | ||
|
||
struct State1: StateProtocol { | ||
@TestWrapper var someValues: [String] = [] | ||
} | ||
theblixguy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
var state = State() | ||
state.values = Array(repeating: "", count: 20000) | ||
state.values[1000] = "foo" | ||
|
||
let state1 = State1() | ||
_ = state1.someValues | ||
|
||
// >> Check that the subscript assignment uses the _modify coroutine | ||
|
||
// CHECK: {{%.*}} = begin_access [modify] [dynamic] {{%.*}} : $*State | ||
// CHECK: [[REF_VALUES_MODIFY:%.*]] = function_ref @$s26property_wrapper_coroutine5StateV6valuesSaySSGvM : $@yield_once @convention(method) (@inout State) -> @yields @inout Array<String> | ||
// CHECK: ([[RES1:%.*]], {{%.*}}) = begin_apply [[REF_VALUES_MODIFY]]({{%.*}}) : $@yield_once @convention(method) (@inout State) -> @yields @inout Array<String> | ||
// CHECK: [[REF_ARRAY_SUBSCRIPT:%.*]] = function_ref @$sSayxSiciM : $@yield_once @convention(method) <τ_0_0> (Int, @inout Array<τ_0_0>) -> @yields @inout τ_0_0 | ||
// CHECK: ({{%.*}}, {{%.*}}) = begin_apply [[REF_ARRAY_SUBSCRIPT]]<String>({{%.*}}, [[RES1]]) : $@yield_once @convention(method) <τ_0_0> (Int, @inout Array<τ_0_0>) -> @yields @inout τ_0_0 | ||
|
||
// >> Check that the _modify coroutine is synthesized properly | ||
|
||
// CHECK-LABEL: sil hidden [transparent] [ossa] @$s26property_wrapper_coroutine5StateV6valuesSaySSGvM : $@yield_once @convention(method) (@inout State) -> @yields @inout Array<String> { | ||
// CHECK: bb0([[STATE:%.*]] : $*State): | ||
// CHECK: debug_value_addr [[STATE]] : $*State, var, name "self", argno {{.*}} | ||
// CHECK: [[BEGIN_ACCESS:%.*]] = begin_access [modify] [unknown] [[STATE]] : $*State | ||
// CHECK: [[BACKING_ADDR:%.*]] = struct_element_addr [[BEGIN_ACCESS]] : $*State, #State._values | ||
// CHECK: [[VALUE_ADDR:%.*]] = struct_element_addr [[BACKING_ADDR]] : $*TestWrapper<Array<String>>, #TestWrapper.wrappedValue | ||
// CHECK: yield [[VALUE_ADDR]] : $*Array<String>, resume bb1, unwind bb2 | ||
// | ||
// CHECK: bb1: | ||
// CHECK: end_access [[BEGIN_ACCESS]] : $*State | ||
// CHECK: [[RETURN:%.*]] = tuple () | ||
// CHECK: return [[RETURN]] : $() | ||
// | ||
// CHECK: bb2: | ||
// CHECK: end_access [[BEGIN_ACCESS]] : $*State | ||
// CHECK: unwind | ||
// CHECK-END: } | ||
|
||
// >> Check that the _read coroutine is synthesized properly | ||
|
||
// CHECK-LABEL: sil shared [ossa] @$s26property_wrapper_coroutine6State1V10someValuesSaySSGvr : $@yield_once @convention(method) (@guaranteed State1) -> @yields @guaranteed Array<String> { | ||
// CHECK: bb0([[STATE1:%.*]] : @guaranteed $State1): | ||
// CHECK: debug_value [[SELF:%.*]] : $State1, let, name "self", argno {{.*}} | ||
// CHECK: [[EXTRACT_VALUE:%.*]] = struct_extract %0 : $State1, #State1._someValues | ||
// CHECK: [[COPY_VALUE:%.*]] = copy_value [[EXTRACT_VALUE]] : $TestWrapper<Array<String>> | ||
// CHECK: [[BEGIN_BORROW:%.*]] = begin_borrow [[COPY_VALUE]] : $TestWrapper<Array<String>> | ||
// CHECK: [[EXTRACT_WRAPPEDVALUE:%.*]] = struct_extract [[BEGIN_BORROW]] : $TestWrapper<Array<String>>, #TestWrapper.wrappedValue | ||
// CHECK: yield [[EXTRACT_WRAPPEDVALUE]] : $Array<String>, resume bb1, unwind bb2 | ||
// | ||
// CHECK: bb1: | ||
// CHECK: end_borrow [[BEGIN_BORROW]] : $TestWrapper<Array<String>> | ||
// CHECK: destroy_value [[COPY_VALUE]] : $TestWrapper<Array<String>> | ||
// CHECK: [[RETURN:%.*]] = tuple () | ||
// CHECK: return [[RETURN]] : $() | ||
// | ||
// CHECK: bb2: | ||
// CHECK: end_borrow [[BEGIN_BORROW]] : $TestWrapper<Array<String>> | ||
// CHECK: destroy_value [[COPY_VALUE]] : $TestWrapper<Array<String>> | ||
// CHECK: 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@theblixguy I don't understand why this is required.
Given a property like:
Before this PR, the synthesized modify in SIL looked like:
where the Foo.text.getter calls Wrap.wrappedValue.getter, and Foo.text.setter calls Wrap.wrappvedValue.setter.
After this PR, it looks like:
These are equivalent, but I thought it was cleaner that Foo.bar.modify calls into Foo.bar.getter/setter instead of doing something special for property wrappers. Why is it being done the latter way?