Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sequence Tuple trouble (StackOverflow) #702

Open
jvasileff opened this issue May 29, 2015 · 4 comments
Open

Sequence Tuple trouble (StackOverflow) #702

jvasileff opened this issue May 29, 2015 · 4 comments

Comments

@jvasileff
Copy link
Member

(copied verbatim from ceylon/ceylon-compiler#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)
    */
}
@gavinking
Copy link
Member

@jvasileff what happens on JS?

@jvasileff
Copy link
Member Author

Ha, you're going to make me work for this one!

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

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.

@gavinking
Copy link
Member

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.

@jvasileff
Copy link
Member Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants