-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Stuck in infinite internal loop, using mixins and recursive generic types #51960
Comments
I found a workaround, instead of declaring the Mixins like: mixin MixinA<
A1 extends MixinA<A1, B1, C1, D1>,
B1 extends MixinB<A1, B1, C1, D1>,
C1 extends MixinC<A1, B1, C1, D1>,
D1 extends MixinD<A1, B1, C1, D1>
> on A<
MixinA<A1, B1, C1, D1>,
MixinB<A1, B1, C1, D1>,
MixinC<A1, B1, C1, D1>,
MixinD<A1, B1, C1, D1>
> {} It works if I declare them like: mixin MixinA<
A1 extends MixinA<A1, B1, C1, D1>,
B1 extends MixinB<A1, B1, C1, D1>,
C1 extends MixinC<A1, B1, C1, D1>,
D1 extends MixinD<A1, B1, C1, D1>
> on A<A1, B1, C1, D1> {} But I still don't understand why it works with 3 Mixins but not with 4 Mixins. |
We seem to get into an infinite loop in
|
This example doesn't stuck in the infinite loop, it finishes in about 15m on my machine. However, it hits an edge case in the handling of recursive types in the VM, resulting in a huge number of I'm going to try to get rid of |
…e objects" This reverts commit 1354437. Reason for revert: breaks many targets in G3, see b/278841863 Original change's description: > [vm] Avoid expanding/flattening type arguments vectors in Type objects > > Previously, vectors of type arguments were expanded to include type > arguments corresponding to superclasses both in the instances of > generic classes and in Type objects (after type finalization). > As a result, Type objects after finalization could be recursive and > need to use extra TypeRef objects to break loops. The finalization of > types was very complex and sometimes slow. > > This change simplifies the representation of Type objects: now they > always have short type argument vectors, corresponding only to > the type parameters of their own classes (both before and after > finalization). Vectors of type arguments in the instances of generic > classes are still expanded/flattened. > > This greatly simplifies type finalization, makes Type objects > non-recursive and removes the need to create and handle excessive > TypeRefs for type arguments corresponding to superclasses, > as those type arguments are no longer included into types. > The only remaining use of TypeRefs is for bounds of type parameters. > > In order to expand/flatten type arguments, new methods Type::GetInstanceTypeArguments / Class::GetInstanceTypeArguments > are introduced. They build canonical declaration type arguments > once (for each class), and then instantiate them as needed. > > There are also simple helper methods to shrink type arguments (TypeArguments::FromInstanceTypeArguments) and expand type arguments without filling type arguments corresponding to superclasses (TypeArguments::ToInstantiatorTypeArguments). > > Time of edge case 'regress_51960_test' 15min -> 300ms. > > TEST=ci, runtime/tests/vm/dart/regress_51960_test.dart > > Fixes #52022 > Fixes #51960 > > Change-Id: I75b466b74698a33c0bb5e1dcbd29542e413812a1 > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/295060 > Reviewed-by: Ryan Macnak <rmacnak@google.com> > Commit-Queue: Alexander Markov <alexmarkov@google.com> Change-Id: If0b2077305620593b8f03ebf6c135375c4086b1a No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/296182 Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com> Reviewed-by: Alexander Thomas <athom@google.com> Commit-Queue: Ilya Yanok <yanok@google.com>
…e objects" This is a reland of commit 1354437 Original change's description: > [vm] Avoid expanding/flattening type arguments vectors in Type objects > > Previously, vectors of type arguments were expanded to include type > arguments corresponding to superclasses both in the instances of > generic classes and in Type objects (after type finalization). > As a result, Type objects after finalization could be recursive and > need to use extra TypeRef objects to break loops. The finalization of > types was very complex and sometimes slow. > > This change simplifies the representation of Type objects: now they > always have short type argument vectors, corresponding only to > the type parameters of their own classes (both before and after > finalization). Vectors of type arguments in the instances of generic > classes are still expanded/flattened. > > This greatly simplifies type finalization, makes Type objects > non-recursive and removes the need to create and handle excessive > TypeRefs for type arguments corresponding to superclasses, > as those type arguments are no longer included into types. > The only remaining use of TypeRefs is for bounds of type parameters. > > In order to expand/flatten type arguments, new methods Type::GetInstanceTypeArguments / Class::GetInstanceTypeArguments > are introduced. They build canonical declaration type arguments > once (for each class), and then instantiate them as needed. > > There are also simple helper methods to shrink type arguments (TypeArguments::FromInstanceTypeArguments) and expand type arguments without filling type arguments corresponding to superclasses (TypeArguments::ToInstantiatorTypeArguments). > > Time of edge case 'regress_51960_test' 15min -> 300ms. > > TEST=ci, runtime/tests/vm/dart/regress_51960_test.dart > > Fixes #52022 > Fixes #51960 > > Change-Id: I75b466b74698a33c0bb5e1dcbd29542e413812a1 > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/295060 > Reviewed-by: Ryan Macnak <rmacnak@google.com> > Commit-Queue: Alexander Markov <alexmarkov@google.com> TEST=runtime/tests/vm/dart/regress_b_278841863_test.dart Fixes b/278841863. Change-Id: Ib1e20055bfb26e1df0a077300c69f0bec7152480 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/296300 Reviewed-by: Ryan Macnak <rmacnak@google.com> Commit-Queue: Alexander Markov <alexmarkov@google.com>
I'm running into a problem, when using mixins and recursive generic types. The weird behavior is that it works fine with 3 generic types, but enters an infinite loop with 4 generic types.
Dart doesn't run.
It's difficult to explain, so it's easier to just show the examples.
How to reproduce
Simply import a file with the following code, or try to run it using an empty main function.
✅ Runs fine
Click to view example
❌ Gets stuck
Click to view example
Environment
The text was updated successfully, but these errors were encountered: