ceylon-sdk icon indicating copy to clipboard operation
ceylon-sdk copied to clipboard

ceylon promise fails with 50 or more Conjunctions

Open jvasileff opened this issue 10 years ago • 8 comments

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)
...

jvasileff avatar Oct 22 '15 06:10 jvasileff

This sounds like @vietj is using tuples of size proportional to the number of promises? Surely that's wrong.

FroMage avatar Oct 22 '15 08:10 FroMage

nobody's going to write such code in real life :-)

vietj avatar Oct 22 '15 08:10 vietj

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.

vietj avatar Oct 22 '15 08:10 vietj

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.

gavinking avatar Oct 22 '15 09:10 gavinking

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.

jvasileff avatar Oct 22 '15 14:10 jvasileff

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 avatar Oct 22 '15 14:10 jvasileff

@jvasileff please open an issue against ceylon-model, with as much of a stack trace as you can get hold of.

gavinking avatar Oct 22 '15 14:10 gavinking

OK, I've investigated this, and I think it should slip to 1.3.

gavinking avatar Oct 23 '15 14:10 gavinking