@@ -172,9 +172,8 @@ public func basic_loop_trivial_values_fixed(_ t: Triangle, _ xs: [Triangle]) {
172172// FIXME: the only reason for so many copies below is because
173173// `Triangle.nontrivial` only exposes get/set rather than read/modify by default
174174//
175- // We should figure out when the coroutine accessors are generated, and ensure
176- // that when it is available, it is used without copying the result, rather than
177- // calling the get/set
175+ // There's complexity in auto-generating a read accessor for classes, but if it's provided
176+ // we could then allow someone to elide the copy with a `borrow x` expression.
178177
179178@_manualOwnership
180179public func basic_loop_nontrivial_values( _ t: Triangle , _ xs: [ Triangle ] ) {
@@ -185,14 +184,35 @@ public func basic_loop_nontrivial_values(_ t: Triangle, _ xs: [Triangle]) {
185184 t. nontrivial. a = p // expected-error {{accessing 't.nontrivial' produces a copy of it}}
186185}
187186
188- // FIXME: there should be no copies required in the below, other than what's already written.
189187@_manualOwnership
190188public func basic_loop_nontrivial_values_fixed( _ t: Triangle , _ xs: [ Triangle ] ) {
191- var p : Pair = ( copy t. nontrivial) . a // expected-error {{accessing 't.nontrivial' produces a copy of it}}
189+ var p : Pair = ( copy t. nontrivial) . a
192190 for x in copy xs {
193- p = p. midpoint ( ( copy x. nontrivial) . a) // expected-error {{accessing 'x.nontrivial' produces a copy of it}}
191+ p = p. midpoint ( ( copy x. nontrivial) . a)
194192 }
195- ( copy t. nontrivial) . a = p // expected-error {{accessing 't.nontrivial' produces a copy of it}}
193+ ( copy t. nontrivial) . a = p
194+ }
195+
196+ @_manualOwnership
197+ public func basic_loop_nontrivial_values_reduced_copies( _ t: Triangle , _ xs: [ Triangle ] ) {
198+ // FIXME: confusing variable names are chosen
199+ let nt = t. nontrivial // expected-error {{accessing 'nt' produces a copy of it}}
200+ var p : Pair = nt. a
201+ for x in copy xs {
202+ let xnt = x. nontrivial // expected-error {{accessing 'xnt' produces a copy of it}}
203+ p = p. midpoint ( xnt. a)
204+ }
205+ nt. a = p
206+ }
207+ @_manualOwnership
208+ public func basic_loop_nontrivial_values_reduced_copies_fixed( _ t: Triangle , _ xs: [ Triangle ] ) {
209+ let nt = copy t. nontrivial
210+ var p : Pair = nt. a
211+ for x in copy xs {
212+ let xnt = copy x. nontrivial
213+ p = p. midpoint ( xnt. a)
214+ }
215+ nt. a = p
196216}
197217
198218
0 commit comments