Open hyp opened 2 years ago
TempRValueOpt pass can optimize a similar Swift copy but not a C++ copy
At first glance, I would expect this to be handled by
commit 13b9915c6fed5c1aefe1c93d89a8b69cad736205 Date: Tue Mar 10 12:23:02 2020 -0700
Use in_guaranteed for let captures (#29812)
@meg-gupta if you have time you may want to take a quick look at this case
TempRValueOpt says that the apply may write to memory, as this can return true:
-> 361 aa->mayWriteToMemory(inst, copySrc)) {
and that prevents the optimization
If we can infer @_effects(readonly)
on the C++ subscript this would be fixed.
Potential fix - https://github.com/apple/swift/pull/61502
Swift has a redundant copy of the
self
parameter when a C++ subscript getter is invoked. This is causing signification slowdown for thestd.vector
subscript (as seen in https://github.com/apple/swift/pull/61456).Steps To Reproduce test.h:
module.modulemap:
test.swift:
$ bin/swiftc -Xfrontend -enable-experimental-cxx-interop -I . -O test.swift -sdk $(xcrun --show-sdk-path) -o swift_test_bin -emit-sil -o sil.ir
=> sil.ir has copy_addr for the call to subscript, but not
subscr
:Expected behavior
MySubscriptable
is not copied on subscript.