Skip to content

Commit 20089b4

Browse files
authored
Iterator type string - add details (#27161)
The compiler messages now report the type of an iterable expression as `iterator yielding TYPE` or `promoted expression yielding TYPE`, with an appropriate TYPE. Previously it reported these types simply as `iterator`. De-futurizes `test/expressions/bradc/reduceVsMathPrec2.chpl` Changes the article to be used in one of the error messages before the type name from `a` to `an` in some common cases like "from an 'iterator'" or "from an 'owned'". r: @DanilaFe
2 parents e8c4cc6 + 02e53a2 commit 20089b4

30 files changed

+56
-40
lines changed

compiler/AST/type.cpp

+12-1
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,17 @@ void Type::setSubstitutionWithName(const char* name, Symbol* value) {
183183
INT_FATAL("substitution not found");
184184
}
185185

186+
// "iterator|promoted expression yielding ..."
187+
// result may be non-astr()
188+
static const char* toIteratorString(AggregateType* at, bool decorateAllClasses) {
189+
const char* kind = at->symbol->hasFlag(FLAG_PROMOTION_ITERATOR_RECORD)
190+
? "promoted expression" : "iterator";
191+
if (IteratorInfo* ii = at->iteratorInfo)
192+
if (Type* yt = ii->yieldedType)
193+
return astr(kind, " yielding ", toString(yt, decorateAllClasses));
194+
return kind;
195+
}
196+
186197
const char* toString(Type* type, bool decorateAllClasses) {
187198
const char* retval = NULL;
188199

@@ -238,7 +249,7 @@ const char* toString(Type* type, bool decorateAllClasses) {
238249
}
239250
} else if (vt->symbol->hasFlag(FLAG_ITERATOR_RECORD)) {
240251
if (developer == false)
241-
retval = "iterator";
252+
retval = toIteratorString(at, decorateAllClasses);
242253
} else if (at->symbol->hasFlag(FLAG_ATOMIC_TYPE) &&
243254
(strcmp(at->symbol->name, "AtomicBool") == 0 ||
244255
strcmp(at->symbol->name, "RAtomicBool") == 0)) {

compiler/resolution/resolveFunction.cpp

+13-1
Original file line numberDiff line numberDiff line change
@@ -2696,6 +2696,18 @@ Type* arrayElementType(Type* arrayType) {
26962696
return eltType;
26972697
}
26982698

2699+
// some simple cases, not exhaustive
2700+
static const char* chooseSeparatorForType(const char* type) {
2701+
if (startsWith(type, "i") ||
2702+
startsWith(type, "a") ||
2703+
startsWith(type, "own") ||
2704+
startsWith(type, "[") )
2705+
return "an ";
2706+
else
2707+
// todo: perhaps switch this to "a(n) "; need to update many .good files
2708+
return "a ";
2709+
}
2710+
26992711
static void issueInitConversionError(Symbol* to, Symbol* toType, Symbol* from,
27002712
Expr* where) {
27012713

@@ -2733,8 +2745,8 @@ static void issueInitConversionError(Symbol* to, Symbol* toType, Symbol* from,
27332745
sep = "";
27342746
fromStr = "nil";
27352747
} else {
2736-
sep = "a ";
27372748
fromStr = toString(fromValType);
2749+
sep = chooseSeparatorForType(fromStr);
27382750
}
27392751

27402752
USR_FATAL_CONT(where,
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
return-array-as-int.chpl:7: In method 'setRowNames':
2-
return-array-as-int.chpl:8: error: cannot initialize return value of type 'int(64)' from a '[domain(1,int(64),one)] int(64)'
2+
return-array-as-int.chpl:8: error: cannot initialize return value of type 'int(64)' from an '[domain(1,int(64),one)] int(64)'
33
return-array-as-int.chpl:12: called as NamedMatrix.setRowNames(rn: [domain(1,int(64),one)] string)
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
promotedExprAsArrayActual.chpl:3: error: unresolved call 'doSomething(promoted expression)'
22
promotedExprAsArrayActual.chpl:1: note: this candidate did not match: doSomething(arg: [] int)
3-
promotedExprAsArrayActual.chpl:3: note: because actual argument #1 with type 'iterator'
3+
promotedExprAsArrayActual.chpl:3: note: because actual argument #1 with type 'promoted expression yielding int(64)'
44
promotedExprAsArrayActual.chpl:1: note: is passed to formal 'arg: []'
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
test_arrayops.chpl:10: error: unresolved call 'maxIndex(promoted expression)'
22
test_arrayops.chpl:12: note: this candidate did not match: maxIndex(A: [?D])
3-
test_arrayops.chpl:10: note: because actual argument #1 with type 'iterator'
3+
test_arrayops.chpl:10: note: because actual argument #1 with type 'promoted expression yielding real(64)'
44
test_arrayops.chpl:12: note: is passed to formal 'A: []'
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
promotedArgToArrayFormal.chpl:9: error: unresolved call 'bar(promoted expression)'
22
promotedArgToArrayFormal.chpl:11: note: this candidate did not match: bar(arrayArg: [] int)
3-
promotedArgToArrayFormal.chpl:9: note: because actual argument #1 with type 'iterator'
3+
promotedArgToArrayFormal.chpl:9: note: because actual argument #1 with type 'promoted expression yielding int(64)'
44
promotedArgToArrayFormal.chpl:11: note: is passed to formal 'arrayArg: []'

test/arrays/shapes/tmacd-promotion.good

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
[ArrayViewRankChangeDom(2,int(64),one,3*bool,3*int(64),int(64),unmanaged ArrayViewRankChangeDist(unmanaged DefaultDist,3*bool,3*int(64)))] int(64)
1313
====== const ref NN =====
1414
0 0 0 0
15-
iterator
15+
promoted expression yielding int(64)

test/classes/casts/to-unmanaged-no-init.good

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ to-unmanaged-no-init.chpl:7: error: cannot initialize variable 'myUnmanaged' of
22
to-unmanaged-no-init.chpl:9: error: cannot initialize variable 'myUnmanaged' of type 'unmanaged A?' from a 'borrowed A'
33
to-unmanaged-no-init.chpl:17: error: cannot initialize variable 'myUnmanaged' of type 'unmanaged A?' from a 'shared A?'
44
to-unmanaged-no-init.chpl:19: error: cannot initialize variable 'myUnmanaged' of type 'unmanaged A?' from a 'borrowed A'
5-
to-unmanaged-no-init.chpl:7: error: cannot initialize 'myUnmanaged' of type 'unmanaged A?' from a 'owned A?'
5+
to-unmanaged-no-init.chpl:7: error: cannot initialize 'myUnmanaged' of type 'unmanaged A?' from an 'owned A?'
66
to-unmanaged-no-init.chpl:9: error: cannot initialize 'myUnmanaged' of type 'unmanaged A?' from a 'borrowed A'
77
to-unmanaged-no-init.chpl:17: error: cannot initialize 'myUnmanaged' of type 'unmanaged A?' from a 'shared A?'
88
to-unmanaged-no-init.chpl:19: error: cannot initialize 'myUnmanaged' of type 'unmanaged A?' from a 'borrowed A'
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
init-field-dflt-nonnil-borrowed-from-oknil-owned.chpl:8: error: cannot initialize 'lhs' of type 'borrowed MyClass' from a 'owned MyClass?'
1+
init-field-dflt-nonnil-borrowed-from-oknil-owned.chpl:8: error: cannot initialize 'lhs' of type 'borrowed MyClass' from an 'owned MyClass?'
22
init-field-dflt-nonnil-borrowed-from-oknil-owned.chpl:13: error: done
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
init-field-dflt-nonnil-unmanaged-from-nonnil-owned.chpl:8: error: cannot initialize 'lhs' of type 'unmanaged MyClass' from a 'owned MyClass'
1+
init-field-dflt-nonnil-unmanaged-from-nonnil-owned.chpl:8: error: cannot initialize 'lhs' of type 'unmanaged MyClass' from an 'owned MyClass'
22
init-field-dflt-nonnil-unmanaged-from-nonnil-owned.chpl:13: error: done
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
init-field-dflt-nonnil-unmanaged-from-oknil-owned.chpl:8: error: cannot initialize 'lhs' of type 'unmanaged MyClass' from a 'owned MyClass?'
1+
init-field-dflt-nonnil-unmanaged-from-oknil-owned.chpl:8: error: cannot initialize 'lhs' of type 'unmanaged MyClass' from an 'owned MyClass?'
22
init-field-dflt-nonnil-unmanaged-from-oknil-owned.chpl:13: error: done
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
init-field-dflt-oknil-unmanaged-from-nonnil-owned.chpl:8: error: cannot initialize 'lhs' of type 'unmanaged MyClass?' from a 'owned MyClass'
1+
init-field-dflt-oknil-unmanaged-from-nonnil-owned.chpl:8: error: cannot initialize 'lhs' of type 'unmanaged MyClass?' from an 'owned MyClass'
22
init-field-dflt-oknil-unmanaged-from-nonnil-owned.chpl:13: error: done
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
init-field-dflt-oknil-unmanaged-from-oknil-owned.chpl:8: error: cannot initialize 'lhs' of type 'unmanaged MyClass?' from a 'owned MyClass?'
1+
init-field-dflt-oknil-unmanaged-from-oknil-owned.chpl:8: error: cannot initialize 'lhs' of type 'unmanaged MyClass?' from an 'owned MyClass?'
22
init-field-dflt-oknil-unmanaged-from-oknil-owned.chpl:13: error: done

test/classes/fields/default-expression-2.good

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
default-expression-2.chpl:7: In initializer:
2-
default-expression-2.chpl:9: error: cannot initialize field 'a' of type 'bool' from a 'int(64)'
2+
default-expression-2.chpl:9: error: cannot initialize field 'a' of type 'bool' from an 'int(64)'
33
default-expression-2.chpl:15: called as SymEntry.init(a: int(64))
44
default-expression-2.chpl:16: warning: SymEntry(nothing)
55
default-expression-2.chpl:17: warning: bool
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
bang-array.chpl:9: error: unresolved call 'foo(promoted expression)'
22
bang-array.chpl:11: note: this candidate did not match: foo(arrayArg: [] C)
3-
bang-array.chpl:9: note: because actual argument #1 with type 'iterator'
3+
bang-array.chpl:9: note: because actual argument #1 with type 'promoted expression yielding borrowed C'
44
bang-array.chpl:11: note: is passed to formal 'arrayArg: []'

test/expressions/bradc/reduceVsMathPrec2.bad

-1
This file was deleted.

test/expressions/bradc/reduceVsMathPrec2.future

-6
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
reduceVsMathPrec2.chpl:12: error: Cannot assign to int(64) from array
1+
reduceVsMathPrec2.chpl:12: error: cannot initialize 'total' of type 'int(64)' from a 'promoted expression yielding int(64)'
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
incorrectYieldTypes.chpl:4: In iterator 'IT':
2-
incorrectYieldTypes.chpl:6: error: cannot initialize yield value of type 'int(64)' from a '[domain(1,int(64),one)] locale'
2+
incorrectYieldTypes.chpl:6: error: cannot initialize yield value of type 'int(64)' from an '[domain(1,int(64),one)] locale'
33
incorrectYieldTypes.chpl:8: error: cannot initialize yield value of type 'int(64)' from a 'domain(1,int(64),one)'
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
forall-over-iteratorRecord-arg.chpl:21: In function 'myTestProc':
22
forall-over-iteratorRecord-arg.chpl:23: error: a forall loop over a formal argument corresponding to a for/forall/promoted expression or an iterator call is not implemented
33
forall-over-iteratorRecord-arg.chpl:34: note: the actual argument is here
4-
forall-over-iteratorRecord-arg.chpl:34: called as myTestProc(IR: iterator)
4+
forall-over-iteratorRecord-arg.chpl:34: called as myTestProc(IR: promoted expression yielding int(64))

test/functions/resolution/errors/printAdditionalErrors-1.all.good

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ printAdditionalErrors-1.chpl:9: warning: postponed error: fatal error in f1()
44
printAdditionalErrors-1.chpl:17: called as canResolve(param fname = "f1", args(0): int(64)) from module 'printAdditionalErrors-1'
55
printAdditionalErrors-1.chpl:19: warning: NOOOO, f1() does not resolve
66
printAdditionalErrors-1.chpl:11: In function 'f2':
7-
printAdditionalErrors-1.chpl:12: error: cannot initialize 'y' of type 'int(8)' from a 'int(64)'
7+
printAdditionalErrors-1.chpl:12: error: cannot initialize 'y' of type 'int(8)' from an 'int(64)'
88
printAdditionalErrors-1.chpl:22: warning: YESSS, f2() resolves
99
printAdditionalErrors-1.chpl:14: In function 'f3':
1010
printAdditionalErrors-1.chpl:15: error: unresolved call 'f1(3, 4)'

test/functions/resolution/errors/printAdditionalErrors-1.dflt.good

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
printAdditionalErrors-1.chpl:19: warning: NOOOO, f1() does not resolve
22
printAdditionalErrors-1.chpl:11: In function 'f2':
3-
printAdditionalErrors-1.chpl:12: error: cannot initialize 'y' of type 'int(8)' from a 'int(64)'
3+
printAdditionalErrors-1.chpl:12: error: cannot initialize 'y' of type 'int(8)' from an 'int(64)'
44
printAdditionalErrors-1.chpl:22: warning: YESSS, f2() resolves
55
printAdditionalErrors-1.chpl:14: In function 'f3':
66
printAdditionalErrors-1.chpl:15: error: unresolved call 'f1(3, 4)'

test/functions/resolution/errors/printAdditionalErrors-1.pae.good

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ printAdditionalErrors-1.chpl:8: In function 'f1':
22
printAdditionalErrors-1.chpl:9: warning: postponed error: fatal error in f1()
33
printAdditionalErrors-1.chpl:19: warning: NOOOO, f1() does not resolve
44
printAdditionalErrors-1.chpl:11: In function 'f2':
5-
printAdditionalErrors-1.chpl:12: error: cannot initialize 'y' of type 'int(8)' from a 'int(64)'
5+
printAdditionalErrors-1.chpl:12: error: cannot initialize 'y' of type 'int(8)' from an 'int(64)'
66
printAdditionalErrors-1.chpl:22: warning: YESSS, f2() resolves
77
printAdditionalErrors-1.chpl:14: In function 'f3':
88
printAdditionalErrors-1.chpl:15: error: unresolved call 'f1(3, 4)'

test/io/serializers/unstableWriting.good

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ $CHPL_HOME/modules/standard/JSON.chpl:nnnn: warning: Serialization of rectangula
1414
unstableWriting.chpl:12: called as helper(thing: domain(1,int(64),one))
1515
$CHPL_HOME/modules/standard/JSON.chpl:nnnn: In method 'serializeValue':
1616
$CHPL_HOME/modules/standard/JSON.chpl:nnnn: warning: Serialization of iterators with non-default Serializer is unstable, and may change in the future
17-
$CHPL_HOME/modules/standard/IO.chpl:nnnn: called as jsonSerializer.serializeValue(writer: fileWriter(false,jsonSerializer), val: iterator) from method '_serializeOne'
18-
$CHPL_HOME/modules/standard/IO.chpl:nnnn: called as (fileWriter(true,jsonSerializer))._serializeOne(x: iterator, loc: locale) from method 'writeHelper'
19-
$CHPL_HOME/modules/standard/IO.chpl:nnnn: called as (fileWriter(true,jsonSerializer)).writeHelper(endl: chpl_ioNewline, sep: nothing, args(0): iterator) from method 'writeln'
20-
unstableWriting.chpl:7: called as (fileWriter(true,jsonSerializer)).writeln(args(0): iterator) from function 'helper'
21-
unstableWriting.chpl:13: called as helper(thing: iterator)
17+
$CHPL_HOME/modules/standard/IO.chpl:nnnn: called as jsonSerializer.serializeValue(writer: fileWriter(false,jsonSerializer), val: iterator yielding int(64)) from method '_serializeOne'
18+
$CHPL_HOME/modules/standard/IO.chpl:nnnn: called as (fileWriter(true,jsonSerializer))._serializeOne(x: iterator yielding int(64), loc: locale) from method 'writeHelper'
19+
$CHPL_HOME/modules/standard/IO.chpl:nnnn: called as (fileWriter(true,jsonSerializer)).writeHelper(endl: chpl_ioNewline, sep: nothing, args(0): iterator yielding int(64)) from method 'writeln'
20+
unstableWriting.chpl:7: called as (fileWriter(true,jsonSerializer)).writeln(args(0): iterator yielding int(64)) from function 'helper'
21+
unstableWriting.chpl:13: called as helper(thing: iterator yielding int(64))
2222
"1..10"
2323
["1..10"]
2424
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
buffer2.chpl:1: In function 'main':
2-
buffer2.chpl:5: error: cannot initialize a value of type 'uint(8)' from a 'int(64)'
2+
buffer2.chpl:5: error: cannot initialize a value of type 'uint(8)' from an 'int(64)'

test/library/standard/Reflection/canResolvePromoReturn.good

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
true
22
true true true
3-
iterator
3+
promoted expression yielding bool
44
bool
55
true
66
true
77
true
88
false false false
9-
iterator
9+
promoted expression yielding bool
1010
bool
1111
false
1212
false
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
splitInitIteratorExpressions.chpl:6: error: Split initialization uses multiple types; another initialization has type [domain(1,int(64),one)] string but this initialization has type iterator
1+
splitInitIteratorExpressions.chpl:6: error: Split initialization uses multiple types; another initialization has type [domain(1,int(64),one)] string but this initialization has type iterator yielding string
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
arrArgBlank-promote.chpl:10: error: unresolved call 'writeArr(promoted expression)'
22
arrArgBlank-promote.chpl:3: note: this candidate did not match: writeArr(X: [] real)
3-
arrArgBlank-promote.chpl:10: note: because actual argument #1 with type 'iterator'
3+
arrArgBlank-promote.chpl:10: note: because actual argument #1 with type 'promoted expression yielding real(64)'
44
arrArgBlank-promote.chpl:3: note: is passed to formal 'X: []'
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
arrArgConst-promote.chpl:10: error: unresolved call 'writeArr(promoted expression)'
22
arrArgConst-promote.chpl:3: note: this candidate did not match: writeArr(const X: [] real)
3-
arrArgConst-promote.chpl:10: note: because actual argument #1 with type 'iterator'
3+
arrArgConst-promote.chpl:10: note: because actual argument #1 with type 'promoted expression yielding real(64)'
44
arrArgConst-promote.chpl:3: note: is passed to formal 'const X: []'
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
arrArgRef-promote.chpl:10: error: unresolved call 'writeArr(promoted expression)'
22
arrArgRef-promote.chpl:3: note: this candidate did not match: writeArr(ref X: [] real)
3-
arrArgRef-promote.chpl:10: note: because actual argument #1 with type 'iterator'
3+
arrArgRef-promote.chpl:10: note: because actual argument #1 with type 'promoted expression yielding real(64)'
44
arrArgRef-promote.chpl:3: note: is passed to formal 'ref X: []'

0 commit comments

Comments
 (0)