Description
So, currently, the sugared closure syntax {||...}
can be used for any kind of closure. @brson and I wanted this so that task spawning looks nice:
task::spawn {||...}
but I've since soured on it (and I think he has too). The basic reason is that it is not explicit whether the closure is a boxed or unique closure: this depends on the definition of the callee function. But this distinction is important to the semantics and cost model. Therefore, I would like to make it so that {||...}
is always a stack closure (fn&
).
With no other changes, this would mean that spawning a task is written task::spawn(fn~() {...})
. To make fn@()
and fn~()
a little more convenient to use, however, we could make any or all of the following changes:
- Do not require variable types (I think this would be relatively straightforward; I also think there's an existing bug for this but can't find it at the moment).
- Allow parentheses to be omitted if there are no arguments (e.g.,
task::spawn(fn~ {...})
) - Allow paren-less calls, similar to a sugared closure like
{||...}
(e.g.,task::spawn fn~ {...}
ortask::spawn fn~() {...}
)
This RFC is truly a "request for comment" because I'm not really sure what's best. Should we just leave things as they are? If not, do we implement the proposals above to lighten the syntax a bit? I think the first point (omitting variable types) is a clear win, but I'm less sure about #2 and #3. The fully explicit form is perhaps not so bad.
p.s. Another option might be to add some sigil to the sugared form, but task::spawn {~|| ...}
just looks like a lot of random characters in a row to me.