Yeah yeah, I agree on that. I just wanted to tell that both are true:
- begin_access/end_access should not prevent optimization.
- begin_access/end_access are not required around initialization of a field.
Just checked SIL. There are no begin_access/end_access around assignment in the let version.
sil hidden @$s6output3FooCyACyxGxcfc : $@convention(method) <T> (@in T, @owned Foo<T>) -> @owned Foo<T> {
[%0: read v**]
[%1: escape => %r, escape c*.v** -> %r.c*.v**, write c0.v**]
[global: ]
bb0(%0 : $*T, %1 : $Foo<T>):
debug_value %0 : $*T, let, name "v", argno 1, expr op_deref, loc "/app/example.swift":5:12, scope 4 // id: %2
debug_value %1 : $Foo<T>, let, name "self", argno 2, implicit, loc "/app/example.swift":5:5, scope 4 // id: %3
%4 = ref_element_addr %1 : $Foo<T>, #Foo.v, loc "/app/example.swift":6:16, scope 4 // user: %5
copy_addr [take] %0 to [init] %4 : $*T, loc "/app/example.swift":6:16, scope 4 // id: %5
return %1 : $Foo<T>, loc "/app/example.swift":7:5, scope 4 // id: %6
} // end sil function '$s6output3FooCyACyxGxcfc'
sil hidden @$s6output3BarCyACyxGxcfc : $@convention(method) <T> (@in T, @owned Bar<T>) -> @owned Bar<T> {
[%0: read v**]
[%1: escape => %r, escape c*.v** -> %r.c*.v**, write c0.v**]
[global: ]
bb0(%0 : $*T, %1 : $Bar<T>):
debug_value %0 : $*T, let, name "v", argno 1, expr op_deref, loc "/app/example.swift":13:12, scope 11 // id: %2
debug_value %1 : $Bar<T>, let, name "self", argno 2, implicit, loc "/app/example.swift":13:5, scope 11 // id: %3
%4 = ref_element_addr %1 : $Bar<T>, #Bar.v, loc "/app/example.swift":14:16, scope 11 // user: %5
%5 = begin_access [modify] [dynamic] [no_nested_conflict] %4 : $*T, loc "/app/example.swift":14:16, scope 11 // users: %7, %6
copy_addr [take] %0 to [init] %5 : $*T, loc "/app/example.swift":14:16, scope 11 // id: %6
end_access %5 : $*T, loc * "/app/example.swift":14:16, scope 11 // id: %7
return %1 : $Bar<T>, loc "/app/example.swift":15:5, scope 11 // id: %8
} // end sil function '$s6output3BarCyACyxGxcfc'