Follow up to discussion at https://forums.swift.org/t/property-wrapper-causing-excessive-array-copying/.
Just had a quick look and it seems like we are synthesising a _modify
accessor for a @propertyWrapper property, for example, if we have
@propertyWrapper
struct TestWrapper<ValueType> {
var wrappedValue: ValueType
}
struct State {
@TestWrapper var values: [String] = []
}
we generate a _modify
accessor for values
:
(accessor_decl implicit range=[/Users/suyashsrijan/Desktop/test.swift:7:19 - line:7:19] 'anonname=0x7ffe160ae7d8' interface type='(inout State) -> () -> ()' access=internal _modify_for=values
(parameter "self" type='State' interface type='State' inout)
(parameter_list)
(brace_stmt implicit range=[/Users/suyashsrijan/Desktop/test.swift:7:19 - line:7:19]
(yield_stmt implicit range=[/Users/suyashsrijan/Desktop/test.swift:7:19 - line:7:19]
(inout_expr implicit type='inout [String]'
(member_ref_expr implicit type='@lvalue [String]' decl=test.(file).TestWrapper.wrappedValue@/Users/suyashsrijan/Desktop/test.swift:3:6 [with (substitution_map generic_signature=<ValueType> (substitution ValueType -> [String]))]
(member_ref_expr implicit type='@lvalue TestWrapper<[String]>' decl=test.(file).State._values@/Users/suyashsrijan/Desktop/test.swift:7:19 direct_to_storage
(declref_expr implicit type='@lvalue State' decl=test.(file).State.<anonymous>.self@/Users/suyashsrijan/Desktop/test.swift:7:19 function_ref=unapplied))))))))
However, looking at the generated SIL, we only seem to be using the setter and the _modify
is nowhere to be seen (no SIL generated for it). I am going to do more digging to figure out what's going on, but I'm also wondering if I missed something obvious.