ceylon promise fails with 50 or more Conjunctions
This program:
shared void promiseTest() {
variable Completion<Integer, Integer[]>? completion = null;
for (i in 0:51) {
value deferred = Deferred<Integer>();
completion = if (exists c = completion)
then c.and(deferred.promise)
else deferred.promise;
//completion?.completed((Integer *xs) => print("done"));
deferred.fulfill(0);
}
completion?.completed((Integer *xs) => print("done"));
}
produces no output.
Lowering the iteration count to 50 causes done to be printed immediately. (The program doesn't exit for a while though. Is that normal?)
Uncommenting the commented line results in a runtime type error (with 51):
...
done
done
done
ceylon run: possible undecidability: typechecker detected possible
nontermination and aborted algorithm
com.redhat.ceylon.model.typechecker.model.DecidabilityException: possible undecidability: typechecker detected possible nontermination and aborted algorithm
at com.redhat.ceylon.model.typechecker.model.Type.checkDepth(Type.java:1653)
at com.redhat.ceylon.model.typechecker.model.Type.isExactlyInternal(Type.java:178)
at com.redhat.ceylon.model.typechecker.model.Type.isExactlyTuple(Type.java:452)
at com.redhat.ceylon.model.typechecker.model.Type.isExactlyInternal(Type.java:337)
at com.redhat.ceylon.model.typechecker.model.Type.isExactlyInternal(Type.java:208)
at com.redhat.ceylon.model.typechecker.model.Type.isExactlyTuple(Type.java:462)
at com.redhat.ceylon.model.typechecker.model.Type.isExactlyInternal(Type.java:337)
...
This sounds like @vietj is using tuples of size proportional to the number of promises? Surely that's wrong.
nobody's going to write such code in real life :-)
it could be resolved by adding an and() function that takes an arbitrary number of promise and returns a single promise. typesafety would be lost though.
Well I would say that this is probably a bug in ceylon-model. We're supposed to have hardened our algorithms to handle long tuple types.
nobody's going to write such code in real life :-)
Why not? What's the maximum reasonable number of parallelizable tasks per processing stage? No doubt, it does seem awkward to do this with and(), but this came up in real code.
A secondary problem is the this fails silently without an attempt to call completion?.completed() on exactly the fiftieth iteration. Or, at least I wasn't able to coax an error out if it.
@jvasileff please open an issue against ceylon-model, with as much of a stack trace as you can get hold of.
OK, I've investigated this, and I think it should slip to 1.3.