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

Tall style formatter hangs on this code snippet #1521

Closed
renggli opened this issue Aug 12, 2024 · 2 comments · Fixed by #1619
Closed

Tall style formatter hangs on this code snippet #1521

renggli opened this issue Aug 12, 2024 · 2 comments · Fixed by #1619

Comments

@renggli
Copy link

renggli commented Aug 12, 2024

The tall style formatter does not halt when trying to format this code snippet:

typedef Map1<T1, R> = R Function(T1 arg1);

typedef Map8<T1, T2, T3, T4, T5, T6, T7, T8, R> = R Function(
    T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8);

extension Curry8<T1, T2, T3, T4, T5, T6, T7, T8, R>
    on Map8<T1, T2, T3, T4, T5, T6, T7, T8, R> {
  Map1<
          T1,
          Map1<T2,
              Map1<T3, Map1<T4, Map1<T5, Map1<T6, Map1<T7, Map1<T8, R>>>>>>>>
      get curry => (T1 arg1) => (T2 arg2) => (T3 arg3) => (T4 arg4) =>
          (T5 arg5) => (T6 arg6) => (T7 arg7) =>
              (T8 arg8) => this(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
}

The above snippet is quick minimal extraction that reproduces the problem I had formatting this code:
https://github.com/renggli/dart-more/blob/0a6238928da483da55273c61b9807f51946e79d4/lib/src/functional/types/curry.dart#L61-L72.

@munificent
Copy link
Member

Thanks, I'll take a look.

munificent added a commit that referenced this issue Dec 9, 2024
The new style formats this about 200x faster than the old one. It's still kind of slow, but tolerable.

Fix #1521.
@munificent
Copy link
Member

I looked into this. You're right, the old formatter is very slow on deeply nested function expressions like this. Fortunately, on my machine, the new tall style formatter is about 200x faster on this example.

I'm going to go ahead and close this out because we're trying to not put much time into maintaining the old style.

If you want a workaround before you move to the new style (which should ship in 3.7), if you replace those => ... functions with { return ...; }, you'll get much better performance.

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

Successfully merging a pull request may close this issue.

2 participants