[swift-evolution] Proposal: Make $0 always refer to a closure’s first argument
cantrell at pobox.com
Wed Jan 27 10:11:42 CST 2016
> On Jan 21, 2016, at 3:05 PM, Paul Cantrell via swift-evolution <swift-evolution at swift.org> wrote:
>> On Jan 20, 2016, at 4:55 PM, Chris Lattner via swift-evolution <swift-evolution at swift.org> wrote:
>>> On Jan 20, 2016, at 9:49 AM, Joe Groff via swift-evolution <swift-evolution at swift.org> wrote:
>>>>> On Jan 19, 2016, at 10:35 PM, John McCall <rjmccall at apple.com> wrote:
>>>>>> On Jan 19, 2016, at 7:20 PM, Paul Cantrell via swift-evolution <swift-evolution at swift.org> wrote:
>>>>>> It appears that the meaning of $0 is overloaded: it can refer either to the tuple of all arguments, or to just the first argument. The presence of another placeholder variable ($1 in the third example) seems to trigger the latter behavior.
>>>>> It’s dumber than that. The type-checker assumes that the closure has a tuple of arguments ($0, $1, …, $N), where $N is the largest N seen in the closure. Thus, a two-argument closure falls down if you ignore the second argument. It’s dumb, and we’ve known about it for a long time; and yet it’s been remarkably annoying to fix, and so we haven’t yet.
>>>>> Anyway, it’s a bug and doesn’t need to go through evolution.
>>>> I wouldn't go as far as to say it's a bug. It's known and occasionally useful for forwarding arguments. (For a while I had it as a fix-it for doing function representation conversions.)
>>>> I agree that having it always be the first argument is less surprising and probably more generally useful, though.
>>> In the spirit of the Great Argument Simplification to distinguish arguments from tuples, we probably ought to introduce a separate '$*'-like sigil to bind "all arguments" distinct from $0.
>> Likewise, on the caller side, we should have a “splat” sigil to splat a tuple into the argument list of a call. We need a similar thing for varargs to enable vararg forwarding as well.
> Where does this leave the discussion, then? I’ve filed it as a bug, though there’s disagreement about whether it is.
> Can we split this into two questions? My wish and dream would to get $0 fixed to match the docs (i.e. only match the first param) in 2.2. That’s an ongoing pain point.
> The $* (or similar) feature would be handy, but seems like it should be accompanied by a larger vararg splatting discussion, and should probably fall to Swift 4+ given the release goals for Swift 3 — which is fine with me, but I’d really hate to have to wait that long to see $0 fixed.
Bumping this. I don’t much care about the $* question, but am eager to see the $0 overloading fixed.
Can the core team make a call on whether I should write a proposal to make that happen, or whether filing the bug is sufficient?
More information about the swift-evolution