Skip to content

Commit

Permalink
Make default initialization of low and high bounded ranges unstable (c…
Browse files Browse the repository at this point in the history
…hapel-lang#23299)

Per the discussion
[here](chapel-lang#21474), make default
initialization of low and high bounded ranges unstable.

The following will produce ranges with the values `0..` and `..1`
respectively; however, we may want to change the default values in the
future or make them implementation dependant, so an unstable warning
will be emitted for each.

```chapel
var rl: range(int, boundKind.low),
    rh: range(int, boundKind.high);
```

- [x] local paratest
- [x] gasnet paratest

[ Reviewed by @jabraham17 ] - Thanks!
  • Loading branch information
jeremiah-corrado authored Sep 11, 2023
2 parents 0dc30dc + 7ec2beb commit 799f39d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
22 changes: 20 additions & 2 deletions modules/internal/ChapelRange.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,24 @@ module ChapelRange {
proc range.init(type idxType,
param bounds: boundKind,
param strides: strideKind) {

if chpl_warnUnstable && (bounds == boundKind.low || bounds == boundKind.high)
then warning("Default initialization of a range with 'boundKind.low' or 'boundKind.high' is unstable");

this.init(idxType, bounds, strides,
_low = chpl__defaultLowBound(idxType, bounds),
_high = chpl__defaultHighBound(idxType, bounds),
_stride = strides.defaultStride():chpl__rangeStrideType(idxType),
alignmentValue = 0:chpl__rangeStrideType(idxType));
}

// this overload can be removed when the unstable warning in the above overload is removed
@chpldoc.nodoc
proc range.init(type idxType,
param bounds: boundKind,
param strides: strideKind,
param internal: bool) {

this.init(idxType, bounds, strides,
_low = chpl__defaultLowBound(idxType, bounds),
_high = chpl__defaultHighBound(idxType, bounds),
Expand Down Expand Up @@ -1760,7 +1778,7 @@ operator :(r: range(?), type t: range(?)) where chpl_castIsSafe(r, t) {
checkBounds(t, r);
checkEnumIdx(t, r);

var tmp: t;
var tmp = new range(t.idxType, t.bounds, t.strides, true);
type srcType = r.idxType,
dstType = t.idxType,
dstIntType = tmp.chpl_integralIdxType;
Expand Down Expand Up @@ -1792,7 +1810,7 @@ operator :(r: range(?), type t: range(?)) throws where !chpl_castIsSafe(r, t) {
checkBounds(t, r);
checkEnumIdx(t, r);

var tmp: t;
var tmp = new range(t.idxType, t.bounds, t.strides, true);
type srcType = r.idxType,
dstType = t.idxType,
dstIntType = tmp.chpl_integralIdxType;
Expand Down
15 changes: 15 additions & 0 deletions test/unstable/defaultUnboundedRange.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

// only low and high default initialization should be unstable
var drlb: range(int, boundKind.low),
drub: range(int, boundKind.high),
drnb: range(int, boundKind.neither),
drbb: range(int, boundKind.both);

// none of these should produce an unstable warning
var rlb = 1..,
rub = ..0,
rnb = ..,
rbb = 1..0;

writeln(drlb);
writeln(drub);
4 changes: 4 additions & 0 deletions test/unstable/defaultUnboundedRange.good
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
1..
..0
defaultUnboundedRange.chpl:3: warning: Default initialization of a range with 'boundKind.low' or 'boundKind.high' is unstable
defaultUnboundedRange.chpl:4: warning: Default initialization of a range with 'boundKind.low' or 'boundKind.high' is unstable

0 comments on commit 799f39d

Please sign in to comment.