Skip to content

Commit

Permalink
Add benchmark and regression test for #1521. (#1619)
Browse files Browse the repository at this point in the history
The new style formats this about 200x faster than the old one. It's still kind of slow, but tolerable.

Fix #1521.
  • Loading branch information
munificent authored Dec 10, 2024
1 parent e12c007 commit 47bcc07
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 0 deletions.
39 changes: 39 additions & 0 deletions benchmark/case/curry_2.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
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,
);
}
15 changes: 15 additions & 0 deletions benchmark/case/curry_2.expect_short
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
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);
}
15 changes: 15 additions & 0 deletions benchmark/case/curry_2.unit
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
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);
}
56 changes: 56 additions & 0 deletions test/tall/regression/1500/1521.unit
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
>>>
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);
}
<<<
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,
);
}

0 comments on commit 47bcc07

Please sign in to comment.