[swift-evolution] [Proposal] Adjusting `inout` Declarations for Type Decoration

Austin Zheng austinzheng at gmail.com
Fri Jan 29 18:30:41 CST 2016


As far as I understand it, the Rust Dream™ is one day being able to pass
around classes and certain other types without the overhead of ARC, thanks
to compile-time borrow checking. This would be handy for
resource-constrained platforms and performance critical use cases.

In order to support this sort of feature we'd probably need to be able to
annotate parameters to functions (like 'inout') to indicate e.g. whether
'ownership' of a variable opting into this system is being transferred or
not. Rust's system is described here:
https://doc.rust-lang.org/book/ownership.html

Best,
Austin


On Fri, Jan 29, 2016 at 4:22 PM, Charles Kissinger via swift-evolution <
swift-evolution at swift.org> wrote:

>
> On Jan 29, 2016, at 3:50 PM, Erica Sadun <erica at ericasadun.com> wrote:
>
> The great advantages are:
>
> 1. It removes a potentially confusing overlap with C-style expectations.
> People see & and think "POINTERS!", which is not how things work in Swift
> with copy-back.
>
>
> Yes, I’ve seen the argument. I just don’t have any idea if that leads to
> any bad developer decisions.
>
> (2. It eventually frees up &, so we can have more Rust)
>
>
> I’m just going to go ahead and assume that’s a good thing.
>
> —CK
>
> -- E
>
> On Jan 29, 2016, at 4:42 PM, Charles Kissinger <crk at akkyra.com> wrote:
>
> Sorry, I wasn’t clear at all there. I was thinking of the most common case
> where there is either only one parameter or the inout parameter is the
> first one. Then there will typically be no argument label involved at the
> call site. In that case ‘inout’ will be the first word inside the parens at
> the call site (assuming it replaces ‘&’). If it also is kept in its current
> position in function declarations, it will be in that same leading position
> in declarations and (I’m assuming) people will have an easy time
> remembering where to put it.
>
> When there is a label involved, it is a different story. I was implicitly,
> and probably wrongly, assuming that would be a much less common case in
> practice. A poorly worded, and probably poorly reasoned, argument on my
> part, though I still don’t see any great advantage to replacing ‘&'.
>
> —CK
>
> On Jan 29, 2016, at 2:13 PM, Erica Sadun <erica at ericasadun.com> wrote:
>
>
> On Jan 29, 2016, at 3:04 PM, Charles Kissinger <crk at akkyra.com> wrote:
> The related idea of replacing ‘&’ with ‘inout’ at the call site seems
> completely contradictory to this proposal. Developers would then have to
> remember that the ‘inout’ goes before the argument at the call site but
> after it in the function definition. That seems like a constant source of
> mis-typings and something that would be viewed as an inconsistency in the
> language. Or do people want to put it after the argument name at the call
> site too? It seems a little like change just for the sake of change, IMO.
>
>
> If you have a function
>
> f(x: Int) {}
>
> you call it with f(8), and potentially f(x: 8). Even when labeled, the 8
> value is to the right of the colon.
>
> Now consider
>
> f(x: inout Int) {}
>
> you call it with f(&y) or f(inout y), and with a label, you'd call it f(x:
> &y) or f(x: inout y).
>
> It seems  consistent to me.
>
>
>
>
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160129/c60b638c/attachment.html>


More information about the swift-evolution mailing list