Skip to content

Commit ca58b3a

Browse files
authored
More precise language about future ownership modifiers (#1731)
A callee receives a `shared` parameter by borrow, but whether it's really passed by borrow in the caller is currently ambiguous, since we will normally copy arguments in order to minimize access durations on the original storage. Receiving by borrow is the more interesting interaction with `move` so focus on that.
1 parent 30fbdae commit ca58b3a

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

proposals/0366-move-function.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -435,20 +435,21 @@ definitely has its place, but requires a higher investment than we expect
435435
### `shared` and `owned` argument modifiers
436436

437437
The ownership convention used when passing arguments by value is usually
438-
indefinite; the compiler initially tries passing arguments by borrow, so
439-
that the caller is made to keep the value alive on the callee's behalf for
440-
the duration of the call, with the exception of setters and initializers, where
441-
it defaults to transferring ownership of arguments from the caller to the callee.
442-
The optimizer may subsequently adjust these decisions if it sees opportunities
443-
to reduce overall ARC traffic. Using `move` on an argument that ends up
444-
passed by borrow can syntactically shorten the lifetime of the argument binding,
445-
but can't actually shorten the lifetime of the argument at runtime, since the
446-
borrowed value remains owned by the caller.
438+
indefinite; the compiler initially tries having the function receive
439+
parameters by borrow, so that the caller is made to keep the value alive on the
440+
callee's behalf for the duration of the call (The exceptions are setters and
441+
initializers, where the compiler defaults to transferring ownership of arguments from the
442+
caller to the callee). Optimization may subsequently adjust the compiler's
443+
initial decisions if it sees opportunities to reduce overall ARC traffic. Using
444+
`move` on a parameter that was received as a borrow can syntactically shorten
445+
the lifetime of the argument binding, but can't actually shorten the lifetime
446+
of the argument at runtime, since the borrowed value remains owned by the
447+
caller.
447448

448449
In order to guarantee the forwarding of a value's ownership across function
449450
calls, `move` is therefore not sufficient on its own. We would also need to
450451
guarantee the calling convention for the enclosing function transfers ownership
451-
to the callee. We could add annotations which behave similar to `inout`. These
452+
to the callee, using annotations which behave similar to `inout`. These
452453
are currently implemented internally in the compiler as `__shared` and `__owned`,
453454
and we could expose these as official language features:
454455

0 commit comments

Comments
 (0)