eclipse-archived / ceylon

The Ceylon compiler, language module, and command line tools
http://ceylon-lang.org
Apache License 2.0
395 stars 62 forks source link

Sequence Tuple trouble (StackOverflow) #5580

Open CeylonMigrationBot opened 9 years ago

CeylonMigrationBot commented 9 years ago

[@jvasileff](copied verbatim from #2174)

With the recent Tuple work, I thought I'd finally submit this one that I've had for a while. AFAICT, the first issue below (2k iterations) has already been fixed.

shared void stackOverflowIsSequence() {
    variable [Integer*] seq = [];
    for (i in 0:5k) {
        seq = seq.withTrailing(i);
    }
    // seq is a giant tuple
    if (is [Integer*] s = (seq of Anything)) {}

    /*
        With 2k iterations:

        java.lang.RuntimeException: undecidable canonicalization
        at com.redhat.ceylon.compiler.typechecker.model.ProducedType.resolveAliases(ProducedType.java:2170)
        at com.redhat.ceylon.compiler.typechecker.model.ProducedType.curriedResolveAliases(ProducedType.java:2220)
        at com.redhat.ceylon.compiler.typechecker.model.ProducedType.resolveAliases(ProducedType.java:2174)
        at com.redhat.ceylon.compiler.typechecker.model.ProducedType.curriedResolveAliases(ProducedType.java:2220)
        at com.redhat.ceylon.compiler.typechecker.model.ProducedType.resolveAliases(ProducedType.java:2174)

        With 5k iterations:

        Caused by: java.lang.StackOverflowError
        at com.redhat.ceylon.compiler.java.runtime.model.TypeDescriptor$Nothing.hashCode(TypeDescriptor.java:458)
        at com.redhat.ceylon.compiler.java.runtime.model.TypeDescriptor.unorderedHashCode(TypeDescriptor.java:75)
        at com.redhat.ceylon.compiler.java.runtime.model.TypeDescriptor$Union.hashCode(TypeDescriptor.java:556)
        at java.util.Arrays.hashCode(Arrays.java:3140)
        at com.redhat.ceylon.compiler.java.runtime.model.TypeDescriptor$Class.hashCode(TypeDescriptor.java:182)
        at java.util.Arrays.hashCode(Arrays.java:3140)
        at com.redhat.ceylon.compiler.java.runtime.model.TypeDescriptor$Class.hashCode(TypeDescriptor.java:182)
        at java.util.Arrays.hashCode(Arrays.java:3140)
        at com.redhat.ceylon.compiler.java.runtime.model.TypeDescriptor$Class.hashCode(TypeDescriptor.java:182)
        at java.util.Arrays.hashCode(Arrays.java:3140)
    */
}

[Migrated from ceylon/ceylon.language#702]

CeylonMigrationBot commented 9 years ago

[@gavinking] @jvasileff what happens on JS?

CeylonMigrationBot commented 9 years ago

[@jvasileff] Ha, you're going to make me work for this one!

It works on JS, but then I found #5581.

However, it is painfully slow to use (112 seconds to create 50k 1s with withTrailing, another 112 seconds to sum them with reduce). But I don't think I want to get in the habit of filing performance bugs.

CeylonMigrationBot commented 9 years ago

[@gavinking] Yeah our tuples aren't actually linked lists, even though they look like they are. Building big tuples with withTrailing() or withLeading() is very inefficient.

CeylonMigrationBot commented 9 years ago

[@jvasileff] IIRC, at least on the JVM, the penalty was especially bad though using Tuples, which you get when starting out with empty.

But yeah, you're right, best just not to write code like this.