petdance/scratch — Issue #1146: [RFC] zero length FxA behaviour
Author: petdance
Created: 2011-11-01 05:39:21+00:00
State: open
Labels: Pri-normal, rfc, Sev-medium

FixedBooleanArray, FixedStringArray, FixedIntegerArray, and FixedFloatArray do not allow specifying a length of 0, giving a misleading error of "Fixed${type}Array: can't resize".
FixedPMCArray ignores being set to zero length, remaining uninitialized.

Allowing for zero lengthed arrays allows code that handles "0 or more elements" cases to avoid checking against the zero case. For example:

{{{

.sub 'fixed_ints_upto'
.param int i
.local pmc retv
retv = new ['FixedIntegerArray']
retv = i
$I0 = 0
loop:
if $I0 >= i goto end_loop:
retv[$I0] = $I0
inc $I0
goto loop
end_loop:

.return (retv)
.end

}}}

This will currently fail. To avoid failures, we would have to check for a zero valued argument and handle that case separately.

Zero is a valid length for an array, so I propose that we allow FxAs to be set to zero length (and not be subsequently resizable).

Alternatively, the behaviour could be to ignore setting the length to zero (as is done now in FPA). However, this can be seen as violating the set once property of FxA length.

Originally http://trac.parrot.org/parrot/ticket/1421