Uncoupling Movable
from sink
#1545
kyouko-taiga
started this conversation in
Language design
Replies: 1 comment
-
To fill out the picture, part of the motivation is to close the cognitive gap that occurs when you realize sinking a object doesn't require moving it, but that we are requiring I think this feature, with a conditional conformance for |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
We currently require that values passed to
sink
parameters be of types that conform toMovable
. The justification is that, often, asink
parameter serves to take values that will be stored or returned. Constructors are typical example:As @dabrahams and I have discussed while reviewing the specification, however, we should note that
sink
doesn't actually require any move. We're only transferring ownership, which is a notional property that is erased at run-time. For example, there would be nothing wrong with this program if the above-mentioned requirement was lifted:Another role currently served by
Movable
is to prevent capturing objects from escaping, as we require a conformance toMovable
to return or assign a value. For example, a lambda with alet
orinout
capture is notMovable
and therefore it cannot be returned.We could distinguish escapability from movability by using two different traits.
Escapable
would describe types whose instances can be freely returned whileMovable
would relate strictly to a change of storage. Capturing lambdas (and other types containing remoteparts) would not be escapable. For example,foo
would be illegal butbar
wouldn't in the following:Returning without a conformance to
Movable
would add a couple of restrictions so that the compiler can guarantee that it knows how to build the returned value "in-place". For instance,ham
would (most likely) be illegal butmuk
wouldn't in the following:Beta Was this translation helpful? Give feedback.
All reactions