Commit e96fa34
authored
Fold constant chains within a sweep instead of one fixpoint round per layer (#361)
* test(ir): pin the constant-chain fold against per-round layering (#328)
A chain of let-bound constructors nested one in another -- the shape a
folded monadic bind chain reaches -- collapses one layer per bottom-up
sweep, so the whole chain needs as many optimize+dce rounds as it has
layers. This pins the intended behaviour instead: eight nested layers
fold to their final constant in a single optimizedExpression sweep.
Red at this commit: the sweep folds the innermost layer only, leaving
Let ($field0 = 0) (Just 1) where the enclosing layer's fold wants a bare
constructor.
* feat(optimizer): drop unread let bindings in the sweep that folds them (#328)
Every fold that eliminates a let-bound constructor leaves the payload
behind in a spent field-binder Let that nothing reads: propagating the
constructor binds each read field to a fresh $field binder, the trivial
ones then paste into their reads, and the binding is left unreferenced.
Only the separate dce pass dropped that residue, one pass later in the
round -- and until it did, the enclosing layer's right-hand side was a
Let rather than the constructor it wraps, so the fold there declined and
a chain advanced by exactly one layer per whole-module round.
Dropping an unread binding is now a rewrite too (removeUnusedLetBindings),
on the licence dce already took: an effect run stays because dropping it
would discard the effect, anything else is evaluated for a value nothing
wants. Bindings are decided right to left, so one kept alive only by a
binding itself dropped goes with it, and sequential scoping puts a binder
in scope for the groupings after it and the body, never the ones before.
Recursive groups are left to dce, which can see a dead group as a whole.
Convergence no longer scales with chain depth: Golden.LongBindFlipped's
specialize+dce fixpoint goes from 301 rounds to 3, the same count the
three-deep Golden.MaybeChain takes, and the deepest fixpoint over all 348
goldens takes 4. maxFixpointIterations therefore returns to 100, close
enough to real work that a pass which over-reports changes is caught in
100 sweeps rather than 1000. Compiling Golden.LongApplyChain drops from
42.6s to 1.2s, Golden.LongBindFlipped from 8.2s to 1.2s, and the golden
suite from 81.9s to 30.2s.
346 of the 348 goldens are byte-identical. Golden.LongWriterBind moves,
and in the direction the collapse intends: its 200-deep Writer chain
compiled to a nest of closures over tell/discard plus the Data.Identity
dictionary tables, and now compiles to straight-line code -- the result's
first component is the literal 42, the log a flat concatArray spine, the
dictionaries gone, 847 lines of Lua down to 234. Its eval oracle (42) is
unchanged, so the collapse is semantics-preserving where it is checked
by execution.1 parent 734e65c commit e96fa34
7 files changed
Lines changed: 2072 additions & 4615 deletions
File tree
- changelog.d
- lib/Language/PureScript/Backend/IR
- test
- Language/PureScript/Backend/IR/Optimizer
- ps/output/Golden.LongWriterBind.Test
Lines changed: 0 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
Lines changed: 40 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1457 | 1457 | | |
1458 | 1458 | | |
1459 | 1459 | | |
| 1460 | + | |
1460 | 1461 | | |
1461 | 1462 | | |
1462 | 1463 | | |
| |||
3424 | 3425 | | |
3425 | 3426 | | |
3426 | 3427 | | |
| 3428 | + | |
| 3429 | + | |
| 3430 | + | |
| 3431 | + | |
| 3432 | + | |
| 3433 | + | |
| 3434 | + | |
| 3435 | + | |
| 3436 | + | |
| 3437 | + | |
| 3438 | + | |
| 3439 | + | |
| 3440 | + | |
| 3441 | + | |
| 3442 | + | |
| 3443 | + | |
| 3444 | + | |
| 3445 | + | |
| 3446 | + | |
| 3447 | + | |
| 3448 | + | |
| 3449 | + | |
| 3450 | + | |
| 3451 | + | |
| 3452 | + | |
| 3453 | + | |
| 3454 | + | |
| 3455 | + | |
| 3456 | + | |
| 3457 | + | |
| 3458 | + | |
| 3459 | + | |
| 3460 | + | |
| 3461 | + | |
| 3462 | + | |
| 3463 | + | |
| 3464 | + | |
| 3465 | + | |
| 3466 | + | |
| 3467 | + | |
| 3468 | + | |
| 3469 | + | |
| 3470 | + | |
| 3471 | + | |
| 3472 | + | |
| 3473 | + | |
| 3474 | + | |
| 3475 | + | |
| 3476 | + | |
| 3477 | + | |
| 3478 | + | |
| 3479 | + | |
| 3480 | + | |
| 3481 | + | |
| 3482 | + | |
| 3483 | + | |
| 3484 | + | |
| 3485 | + | |
3427 | 3486 | | |
3428 | 3487 | | |
3429 | 3488 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
162 | 162 | | |
163 | 163 | | |
164 | 164 | | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
171 | 172 | | |
172 | 173 | | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
173 | 179 | | |
174 | 180 | | |
175 | | - | |
| 181 | + | |
176 | 182 | | |
177 | 183 | | |
178 | 184 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
861 | 861 | | |
862 | 862 | | |
863 | 863 | | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
864 | 888 | | |
865 | 889 | | |
866 | 890 | | |
| |||
2123 | 2147 | | |
2124 | 2148 | | |
2125 | 2149 | | |
| 2150 | + | |
| 2151 | + | |
| 2152 | + | |
| 2153 | + | |
2126 | 2154 | | |
2127 | 2155 | | |
2128 | 2156 | | |
2129 | | - | |
2130 | | - | |
2131 | | - | |
| 2157 | + | |
2132 | 2158 | | |
2133 | 2159 | | |
2134 | 2160 | | |
2135 | 2161 | | |
2136 | 2162 | | |
2137 | 2163 | | |
2138 | 2164 | | |
2139 | | - | |
2140 | | - | |
2141 | | - | |
| 2165 | + | |
2142 | 2166 | | |
2143 | 2167 | | |
2144 | 2168 | | |
| |||
2164 | 2188 | | |
2165 | 2189 | | |
2166 | 2190 | | |
2167 | | - | |
2168 | | - | |
2169 | | - | |
2170 | | - | |
| 2191 | + | |
| 2192 | + | |
2171 | 2193 | | |
2172 | 2194 | | |
2173 | | - | |
| 2195 | + | |
2174 | 2196 | | |
2175 | 2197 | | |
2176 | 2198 | | |
| |||
2383 | 2405 | | |
2384 | 2406 | | |
2385 | 2407 | | |
2386 | | - | |
2387 | | - | |
| 2408 | + | |
| 2409 | + | |
| 2410 | + | |
2388 | 2411 | | |
2389 | 2412 | | |
2390 | 2413 | | |
| |||
0 commit comments