[Swift-devel] Changes to array closing semantics?
Mihael Hategan
hategan at mcs.anl.gov
Thu Nov 22 13:37:06 CST 2012
On Thu, 2012-11-22 at 11:02 -0700, Justin M Wozniak wrote:
> On 11/22/2012 09:44 AM, Tim Armstrong wrote:
> >
> > Currently we do the dumb thing of incrementing once per loop
> > iteration, but I'm going to make a change soon where, if we know how
> > many loop iterations there are at the time the loop is started, we'll
> > just increment the count by that amount at the start and decrement as
> > each iteration finishes (or actually, since we chunk loops up and
> > distribute them, as each chunk of the loop finishes). This works well
> > enough.
>
> Just for clarity: In general, we support conditional insertion: if (c >
> 0) { A[i] = c; }. The conditional code block executes some time in the
> future when the condition is set (possibly somewhere else). We handle
> this by allocating array "slots" before entering subordinate code and
> dropping slots in all cases in the subordinate code. When the array
> runs out of slots, it closes itself.
I'm sticking that in using basic reference counting. Both branches of a
condition must have the same (writing) reference count, and if not, the
compiler inserts partial close statements to make them match. That's in
order to support things like:
if (c) {
a[0] = 1;
a[1] = 1;
}
else {
a[0] = 1;
}
More information about the Swift-devel
mailing list