vla-lang 0.9.0

The VLA language with nothing around it: forms, their expansion, the grid, the view record, and the machine that steps a grid
Documentation
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
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
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
//! A shape evaluated at many of its cells at once (KERNEL.20, slice 3,
//! 2026-10-10): the vectorized evaluation of a shared formula, the first of
//! the structural advantages `KERNEL.20` names.
//!
//! An engine's machine evaluates a shape at each of its cells
//! ([`super::shape`]), and a cell's evaluation walks the parse: each node
//! matched, each call's function looked up by name, each operand made and
//! dropped, once a cell. Here the walk is once a run. A run is cells of one
//! shape on one sheet, consecutive in the order of evaluation, none reading
//! another, so that any of them may be computed before any other
//! (`Shapes::plan` finds them, in an order that puts a shape's cells of one
//! level together); each node is evaluated at every cell of the run before
//! its parent is, into a lane, one answer a cell.
//!
//! The meaning is the cell by cell evaluation's, and every rule of it is
//! written once. A value is made by [`binary`], over two numbers by its own
//! [`arithmetic`] and [`compares`], or by the library: a strict function
//! called at each cell with the operands it would be called with there, or,
//! for the language's aggregates and `NOT`, the library's own rule and fold
//! (`library::Fold`) driven here over the run's operands, a range of a sheet
//! kept as an array walked by index (KERNEL.26). A reason propagates as it
//! does there, each cell's answer the first its own evaluation meets, and
//! `IF` computes each branch at the cells that take it and at no other. An
//! operand computed at a cell whose answer an earlier operand has already
//! decided is computed for nothing and changes nothing, an evaluation having
//! no effect but its answer. A constant, and a reference every `$` holds, is
//! computed once for the run. What is not computed here is computed at each
//! cell by [`Ctx`] itself: a defined name, a form other than the language's
//! `IF`, a range where one value is wanted, and a call with such an operand.
//!
//! A lane holds each cell's answer as a value, or, while every answer is
//! one, as a number or a truth value (KERNEL.26): what a read of numbers,
//! the arithmetic and the comparisons over them, the aggregates and `IF`
//! make and read with no value's kind to match, a lane of values from the
//! first answer of another kind.
//!
//! A part a formula writes more than once is computed once where its places
//! stand in one branch of every `IF` around them (KERNEL.27), as Life's rule
//! writes `SUM(Screen.last!A1:C3)-Screen.last!B2` twice: computed where it is
//! first written, its lane kept, every later place taking a copy and the
//! last the lane itself. The parts are found once a shape ([`Repeats`]), each
//! place by its path from the parse's root, and every value is the one each
//! place would compute, an evaluation having no effect but its answer.
//!
//! Its buffers are its caller's, kept from one frame to the next ([`Lanes`])
//! and made in the first frame a run is evaluated in, as many as its parse
//! can hold at once whatever branch its cells take ([`holds`]), with a lane
//! for each repeated part, so that a later frame makes none; a value the
//! same at every cell is copied as often as alone, and so is a repeated
//! part's. It recurses once a level of nesting as [`Ctx`] does, a level's
//! frame holding no array, since `VLA.1`'s limits are pinned on a stack of
//! 1 MiB. Bit for bit with the cell by cell evaluation, which the machine's
//! tests hold it to over generated grids of every kind of node, and with
//! `Calc`, which plans and parses on its own.

use std::cell::{Cell, RefCell};
use std::cmp::Ordering;
use std::convert::Infallible;
use std::hash::Hasher;

use crate::refers::Shape as Part;

use super::dense::Dense;
use super::eval::{
    arithmetic, binary, compare_numbers, compares, finite, Arg, Computed, Ctx, Env, Known, Library,
    Reason, Strict,
};
use super::formula::{BinOp, Expr, RefExpr};
use super::graph::{Area, CellId};
use super::library::{self, Fold, Ranged, Rule};
use super::value::{ErrorKind, Value};

/// The most cells evaluated at once: a lane of them is a few kilobytes, so
/// that the lanes a formula holds at once stay in the processor's cache.
pub(crate) const CHUNK: usize = 256;

/// What an expression answers at one cell, as [`Ctx::scalar`] answers it.
type Got = Result<Value, Reason>;

/// What an expression answers at each cell of a selection.
#[derive(Debug)]
enum Lane {
    /// The same at every cell, computed once: a constant, or a reference
    /// every `$` holds.
    Same(Got),
    /// Each cell's own, in the selection's order.
    Each(Vec<Got>),
    /// Each cell's own, every one a number, held as one (KERNEL.26): what a
    /// read of numbers, the arithmetic over them and `SUM`, `MIN` and `MAX`
    /// answer, until a value of another kind turns the lane into
    /// [`Lane::Each`].
    Numbers(Vec<f64>),
    /// Each cell's own, every one a truth value (KERNEL.26): what a
    /// comparison of numbers, `AND`, `OR` and `NOT` answer.
    Truths(Vec<bool>),
}

impl Lane {
    /// What `f` makes of the answer at the selection's `k`th cell, the
    /// answer lent where it stands, a number or a truth value made a value
    /// for the while.
    #[inline]
    fn with<R>(&self, k: usize, f: impl FnOnce(Result<&Value, &Reason>) -> R) -> R {
        match self {
            Lane::Same(got) => f(got.as_ref()),
            Lane::Each(each) => f(each[k].as_ref()),
            Lane::Numbers(ns) => f(Ok(&Value::Number(ns[k]))),
            Lane::Truths(ts) => f(Ok(&Value::Bool(ts[k]))),
        }
    }

    /// The answer at the selection's `k`th cell, moved out of the lane,
    /// which nothing reads there again, or copied when it is the same at
    /// every cell; the copy at the `last` cell moved, so that the copies are
    /// as many as alone.
    fn take_at(&mut self, k: usize, last: bool) -> Got {
        match self {
            Lane::Same(got) if last => std::mem::replace(got, Ok(Value::Empty)),
            Lane::Same(got) => got.clone(),
            Lane::Each(each) => std::mem::replace(&mut each[k], Ok(Value::Empty)),
            Lane::Numbers(ns) => Ok(Value::Number(ns[k])),
            Lane::Truths(ts) => Ok(Value::Bool(ts[k])),
        }
    }
}

/// A lane as a lane of values holds it (KERNEL.26): what every node but
/// those over numbers and truth values reads, a lane of numbers or of truth
/// values made one first.
enum Values {
    Same(Got),
    Each(Vec<Got>),
}

/// Whether an operator is arithmetic, whose answer over two numbers is a
/// number or an error; the others but `&` compare.
fn is_arithmetic(op: BinOp) -> bool {
    matches!(
        op,
        BinOp::Add | BinOp::Sub | BinOp::Mul | BinOp::Div | BinOp::Pow
    )
}

/// The buffers an evaluation of many cells holds, kept by its caller from
/// one run to the next so that they are made once (KERNEL.20): of values,
/// of numbers and of truth values (KERNEL.26), each as many as the parse
/// holds lanes at once, and of positions; and the places of the parse's
/// repeated parts and the lanes kept for them (KERNEL.27).
#[derive(Debug, Default)]
pub(crate) struct Lanes {
    values: Vec<Vec<Got>>,
    numbers: Vec<Vec<f64>>,
    truths: Vec<Vec<bool>>,
    positions: Vec<Vec<u32>>,
    found: Vec<Key>,
    kept: Vec<Option<Lane>>,
}

impl Lanes {
    /// As many buffers made as a run's expression holds at once
    /// ([`holds`]), before the run begins: a lane of values, of numbers or
    /// of truth values each, whichever its cells' answers come to be.
    fn reserve(&mut self, (values, positions): (usize, usize)) {
        while self.values.len() < values {
            self.values.push(Vec::with_capacity(CHUNK));
        }
        while self.numbers.len() < values {
            self.numbers.push(Vec::with_capacity(CHUNK));
        }
        while self.truths.len() < values {
            self.truths.push(Vec::with_capacity(CHUNK));
        }
        while self.positions.len() < positions {
            self.positions.push(Vec::with_capacity(CHUNK));
        }
    }

    /// How many buffers of each kind are made, values, numbers, truth values
    /// and positions, and the most any holds.
    #[cfg(test)]
    pub(crate) fn made(&self) -> (usize, usize, usize, usize, usize) {
        let most = self.values.iter().map(Vec::capacity);
        let most = most
            .chain(self.numbers.iter().map(Vec::capacity))
            .chain(self.truths.iter().map(Vec::capacity))
            .chain(self.positions.iter().map(Vec::capacity))
            .max();
        (
            self.values.len(),
            self.numbers.len(),
            self.truths.len(),
            self.positions.len(),
            most.unwrap_or(0),
        )
    }
}

/// The most buffers an evaluation of the expression at many cells holds at
/// once, of values and of positions, whichever branches its cells take. A
/// run makes them before it begins, so that the first frame it is evaluated
/// in makes every buffer a later frame holds, and a later frame, whose cells
/// may take a branch no cell took before, makes none. An upper bound,
/// walked as the evaluation recurses and round a loop along a chain.
pub(crate) fn holds(lib: &Library, e: &Expr) -> (usize, usize) {
    match e {
        Expr::Number(_) | Expr::Text(_) | Expr::Bool(_) | Expr::Error(_) | Expr::Empty => (0, 0),
        Expr::Ref(_) | Expr::Name { .. } => (1, 0),
        Expr::Neg(x) | Expr::Pos(x) | Expr::Percent(x) => holds(lib, x),
        Expr::Binary(..) => {
            // The accumulated lane held while each right operand is evaluated.
            let (mut values, mut positions) = (0, 0);
            let mut left = e;
            while let Expr::Binary(_, l, r) = left {
                let (v, p) = holds(lib, r);
                values = values.max(1 + v);
                positions = positions.max(p);
                left = l;
            }
            let (v, p) = holds(lib, left);
            (values.max(v), positions.max(p))
        }
        Expr::Call(name, args) => {
            if lib.form(name).is_some() {
                if lib.known(name) != Some(Known::If) || !(2..=3).contains(&args.len()) {
                    return (1, 0);
                }
                // The condition's lane, and the answers' beside it while the
                // condition is a lane of numbers or truth values (KERNEL.26),
                // then each branch beside the answers and the three lists of
                // positions that place its answers.
                let (mut values, mut positions) = holds(lib, &args[0]);
                values = values.max(2);
                for a in &args[1..] {
                    let (v, p) = holds(lib, a);
                    values = values.max(1 + v);
                    positions = positions.max(3 + p);
                }
                (values, positions)
            } else if lib.strict(name).is_none() {
                (0, 0)
            } else if !args.iter().all(|a| is_operand(lib, a)) {
                (1, 0)
            } else {
                // Each operand beside those before it, then the answers.
                let (mut values, mut positions) = (args.len() + 1, 0);
                for (j, a) in args.iter().enumerate() {
                    let (v, p) = holds(lib, a);
                    values = values.max(j + v);
                    positions = positions.max(p);
                }
                (values, positions)
            }
        }
    }
}

/// Whether an argument can be a strict call's operand in an evaluation of
/// many cells: a reference written as one, or anything whose evaluation is a
/// value at every cell, never an area.
fn is_operand(lib: &Library, a: &Expr) -> bool {
    match a {
        Expr::Ref(_) => true,
        Expr::Pos(x) => is_operand(lib, x),
        _ => yields_value(lib, a),
    }
}

/// The reference an operand is made from at every cell, when it is one: a
/// reference written as one, under any unary plus, which returns its operand
/// as it is.
fn ref_operand<'e>(lib: &Library, a: &'e Expr) -> Option<&'e RefExpr> {
    match a {
        Expr::Ref(r) => Some(r),
        Expr::Pos(x) if !yields_value(lib, a) => ref_operand(lib, x),
        _ => None,
    }
}

/// Whether [`Ctx::eval`] of an expression is a value at every cell: anything
/// but a reference, a name, or a form whose answer may be one.
fn yields_value(lib: &Library, e: &Expr) -> bool {
    match e {
        Expr::Ref(_) | Expr::Name { .. } => false,
        Expr::Pos(x) => yields_value(lib, x),
        Expr::Call(name, args) => match lib.known(name) {
            Some(Known::If) => args.iter().skip(1).all(|a| yields_value(lib, a)),
            _ => lib.form(name).is_none(),
        },
        _ => true,
    }
}

/// The parts written more than once in a shape's parse that a run computes
/// once (KERNEL.27). A part is a node of the parse the run evaluates over its
/// cells, not a literal, nor a reference a strict call takes as one, nor
/// anything inside a call [`Ctx`] computes at each cell; two places are the
/// same part when their parses are the same to the bit and they stand in the
/// same branch of every `IF` around them, so that the run reaches both over
/// the same cells. The run computes a part where it is first written and
/// keeps its lane, every later place taking a copy and the last the lane
/// itself, so that the copies are as many as alone; a place inside a later
/// place of a larger part is never reached and is left out, the larger part
/// taken first. Each place is held by its path from the parse's root, a
/// child's index a step, so that a copy of the parse is found the same way.
/// Found once a shape, as [`holds`] is; most parses have none, and hold
/// nothing.
#[derive(Clone, Debug, Default, PartialEq)]
pub(crate) struct Repeats {
    /// Each place in the parse's preorder: its part, whether it is the
    /// part's last place, and where its path ends in `steps`.
    places: Vec<(u16, bool, u32)>,
    /// The places' paths, one after another.
    steps: Vec<u16>,
    parts: usize,
}

impl Repeats {
    /// The repeated parts of a parse.
    pub(crate) fn of(lib: &Library, e: &Expr) -> Repeats {
        // The parse in preorder, each node with its parent, the branch it
        // stands in (0 for none, else an `IF`'s place and which branch), and
        // whether a run reaches it, round a stack, since a chain of operators
        // nests as deep as it is long.
        struct Node<'e> {
            e: &'e Expr,
            parent: u32,
            branch: u32,
            reached: bool,
            size: u32,
            hash: u64,
        }
        let mut nodes: Vec<Node> = Vec::new();
        let mut stack: Vec<(&Expr, u32, u32, bool)> = vec![(e, u32::MAX, 0, true)];
        let mut candidates = 0;
        while let Some((x, parent, branch, reached)) = stack.pop() {
            let at = nodes.len() as u32;
            candidates += usize::from(reached && !literal(x));
            nodes.push(Node {
                e: x,
                parent,
                branch,
                reached,
                size: 1,
                hash: 0,
            });
            match x {
                Expr::Neg(y) | Expr::Pos(y) | Expr::Percent(y) => {
                    stack.push((y, at, branch, reached));
                }
                // The left operand a link of a chain, which the run reaches
                // as one when it is a part.
                Expr::Binary(_, l, r) => {
                    stack.push((r, at, branch, reached));
                    stack.push((l, at, branch, reached));
                }
                Expr::Call(name, args) => {
                    let how = reaches(lib, name, args);
                    for (j, a) in args.iter().enumerate().rev() {
                        let (b, r) = match how {
                            Reaches::If if j > 0 => (at * 4 + j as u32, reached),
                            Reaches::If => (branch, reached),
                            Reaches::Operands => (branch, reached && ref_operand(lib, a).is_none()),
                            Reaches::None => (branch, false),
                        };
                        stack.push((a, at, b, r));
                    }
                }
                _ => {}
            }
        }
        if candidates < 2 {
            return Repeats::default();
        }
        // Each node's size and its parse's hash, children before parents.
        for i in (1..nodes.len()).rev() {
            let p = nodes[i].parent as usize;
            nodes[p].size += nodes[i].size;
        }
        for i in (0..nodes.len()).rev() {
            let mut h = crate::fx::FxHasher::default();
            node_hash(nodes[i].e, &mut h);
            let mut c = i + 1;
            for _ in 0..arity(nodes[i].e) {
                h.write_u64(nodes[c].hash);
                c += nodes[c].size as usize;
            }
            nodes[i].hash = h.finish();
        }
        // The places a run reaches, by hash, branch and place, each place
        // once, so that the order is the parse's whatever a sort keeps.
        let mut reached: Vec<Key> = (1..nodes.len() as u32)
            .filter(|&i| nodes[i as usize].reached && !literal(nodes[i as usize].e))
            .map(|i| (nodes[i as usize].hash as usize, nodes[i as usize].branch, i))
            .collect();
        reached.sort_unstable();
        // Among the places of one hash and branch, those the same to the
        // bit, each part's places one after another in `members`, each part
        // by its size, the largest first, and where its places begin.
        let mut members: Vec<u32> = Vec::new();
        let mut groups: Vec<Key> = Vec::new();
        let mut taken = vec![false; reached.len()];
        for a in 0..reached.len() {
            if taken[a] {
                continue;
            }
            let (hash, branch, first) = reached[a];
            let start = members.len();
            for (b, &(h, br, i)) in reached.iter().enumerate().skip(a) {
                if (h, br) != (hash, branch) {
                    break;
                }
                if !taken[b] && same_part(nodes[first as usize].e, nodes[i as usize].e) {
                    taken[b] = true;
                    members.push(i);
                }
            }
            match members.len() - start {
                0 | 1 => members.truncate(start),
                n => {
                    let size = nodes[first as usize].size as usize;
                    groups.push((usize::MAX - size, start as u32, n as u32));
                }
            }
        }
        groups.sort_unstable();
        // Each part kept while two of its places are still reached, the
        // places inside a later place of a part kept before it never being.
        let mut hidden = vec![false; nodes.len()];
        let mut kept: Vec<Key> = Vec::new();
        let mut parts = 0;
        for &(_, start, n) in &groups {
            let at = start as usize;
            let places: Vec<u32> = members[at..at + n as usize]
                .iter()
                .copied()
                .filter(|&i| !hidden[i as usize])
                .collect();
            if places.len() < 2 || parts == usize::from(u16::MAX) {
                continue;
            }
            for (k, &i) in places.iter().enumerate() {
                kept.push((i as usize, parts as u32, u32::from(k + 1 == places.len())));
                if k > 0 {
                    let end = i + nodes[i as usize].size;
                    for h in &mut hidden[i as usize + 1..end as usize] {
                        *h = true;
                    }
                }
            }
            parts += 1;
        }
        if parts == 0 {
            return Repeats::default();
        }
        kept.sort_unstable();
        // Each place's path: the child's index at each step from the root.
        let mut out = Repeats {
            parts,
            ..Repeats::default()
        };
        let mut path: Vec<u16> = Vec::new();
        for (i, part, last) in kept {
            let (i, part, last) = (i as u32, part as u16, last == 1);
            path.clear();
            let mut c = i as usize;
            while nodes[c].parent != u32::MAX {
                let p = nodes[c].parent as usize;
                // Which child of its parent: the children before it in
                // preorder, each a whole subtree.
                let (mut child, mut s) = (0u16, p + 1);
                while s != c {
                    s += nodes[s].size as usize;
                    child += 1;
                }
                path.push(child);
                c = p;
            }
            out.steps.extend(path.iter().rev());
            out.places.push((part, last, out.steps.len() as u32));
        }
        out
    }

    /// How many lanes a run keeps for them at once: one a part.
    pub(crate) fn parts(&self) -> usize {
        self.parts
    }

    /// How many places the parts are written at that a run reaches.
    #[cfg(test)]
    pub(crate) fn places(&self) -> usize {
        self.places.len()
    }

    /// Each place's node in a parse of the same shape, by its address, with
    /// its part and whether it is the part's last place (`part << 1 | last`),
    /// sorted by address.
    fn found(&self, root: &Expr, out: &mut Vec<Key>) {
        out.clear();
        let mut from = 0;
        for &(part, last, to) in &self.places {
            let path = &self.steps[from..to as usize];
            from = to as usize;
            let mut e = Some(root);
            for &k in path {
                e = match (e, usize::from(k)) {
                    (Some(Expr::Neg(x) | Expr::Pos(x) | Expr::Percent(x)), 0) => Some(&**x),
                    (Some(Expr::Binary(_, l, _)), 0) => Some(&**l),
                    (Some(Expr::Binary(_, _, r)), 1) => Some(&**r),
                    (Some(Expr::Call(_, args)), j) => args.get(j),
                    _ => None,
                };
            }
            // A path is its own parse's, found on a parse of the same shape;
            // were one not, its place would be computed where it stands.
            debug_assert!(e.is_some(), "a place's path leaves its parse");
            if let Some(e) = e {
                let at = e as *const Expr as usize;
                out.push((at, u32::from(part) << 1 | u32::from(last), 0));
            }
        }
        out.sort_unstable();
    }
}

/// What [`Repeats`] sorts, the places by hash, branch and place, the parts by
/// size, and the places' addresses, each a key the shape of a [`CellId`], so
/// that the build's one sort of cells sorts them all (KERNEL.27): each sort's
/// own kind of key cost the language's module some kilobytes. On a 32-bit
/// target a hash keeps its low half, which only puts more places side by
/// side for [`same_part`] to tell apart.
type Key = (usize, u32, u32);

/// How a run reaches a call's arguments: each branch of the language's `IF`
/// in a branch of its own, a strict call's operands where the call stands,
/// or none, the call computed at each cell or answering without them.
enum Reaches {
    If,
    Operands,
    None,
}

/// [`Reaches`] for a call, as [`Many::call`] dispatches it.
fn reaches(lib: &Library, name: &str, args: &[Expr]) -> Reaches {
    if lib.form(name).is_some() {
        if lib.known(name) == Some(Known::If) && (2..=3).contains(&args.len()) {
            Reaches::If
        } else {
            Reaches::None
        }
    } else if lib.strict(name).is_none() || !args.iter().all(|a| is_operand(lib, a)) {
        Reaches::None
    } else {
        Reaches::Operands
    }
}

/// Whether a node is a literal, which a run makes the same at every cell as
/// cheaply as it would copy it, and is never a repeated part (KERNEL.27).
fn literal(e: &Expr) -> bool {
    matches!(
        e,
        Expr::Number(_) | Expr::Text(_) | Expr::Bool(_) | Expr::Error(_) | Expr::Empty
    )
}

/// How many children a node has, in the order [`Repeats::of`] walks them.
fn arity(e: &Expr) -> usize {
    match e {
        Expr::Neg(_) | Expr::Pos(_) | Expr::Percent(_) => 1,
        Expr::Binary(..) => 2,
        Expr::Call(_, args) => args.len(),
        _ => 0,
    }
}

/// A node's own part of its parse's hash: its kind and what it holds but its
/// children.
fn node_hash(e: &Expr, h: &mut crate::fx::FxHasher) {
    use std::hash::Hash;
    std::mem::discriminant(e).hash(h);
    match e {
        Expr::Number(v) => h.write_u64(v.to_bits()),
        Expr::Text(t) => t.hash(h),
        Expr::Bool(b) => b.hash(h),
        Expr::Error(k) => k.hash(h),
        Expr::Ref(r) => {
            r.written.hash(h);
            r.sheet.hash(h);
            (r.top, r.left, r.bottom, r.right).hash(h);
        }
        Expr::Name { name, sheet } => {
            name.hash(h);
            sheet.hash(h);
        }
        Expr::Call(name, args) => {
            name.hash(h);
            args.len().hash(h);
        }
        Expr::Binary(op, ..) => std::mem::discriminant(op).hash(h),
        Expr::Empty | Expr::Neg(_) | Expr::Pos(_) | Expr::Percent(_) => {}
    }
}

/// Whether two parses are the same to the bit, a number's sign of zero
/// included: round a stack, as [`Repeats::of`] walks.
fn same_part(a: &Expr, b: &Expr) -> bool {
    let mut stack = vec![(a, b)];
    while let Some(pair) = stack.pop() {
        match pair {
            (Expr::Number(x), Expr::Number(y)) if x.to_bits() == y.to_bits() => {}
            (Expr::Text(x), Expr::Text(y)) if x == y => {}
            (Expr::Bool(x), Expr::Bool(y)) if x == y => {}
            (Expr::Error(x), Expr::Error(y)) if x == y => {}
            (Expr::Empty, Expr::Empty) => {}
            (Expr::Ref(x), Expr::Ref(y)) if x == y => {}
            (Expr::Name { name, sheet }, Expr::Name { name: n, sheet: s })
                if name == n && sheet == s => {}
            (Expr::Call(f, xs), Expr::Call(g, ys)) if f == g && xs.len() == ys.len() => {
                stack.extend(xs.iter().zip(ys));
            }
            (Expr::Neg(x), Expr::Neg(y))
            | (Expr::Pos(x), Expr::Pos(y))
            | (Expr::Percent(x), Expr::Percent(y)) => stack.push((x, y)),
            (Expr::Binary(o, l, r), Expr::Binary(p, m, s)) if o == p => {
                stack.push((r, s));
                stack.push((l, m));
            }
            _ => return false,
        }
    }
    true
}

/// The cells of the run a lane is for: every one, or some, by position.
#[derive(Clone, Copy)]
enum Sel<'s> {
    All(usize),
    Some(&'s [u32]),
}

impl Sel<'_> {
    fn len(self) -> usize {
        match self {
            Sel::All(n) => n,
            Sel::Some(at) => at.len(),
        }
    }

    /// The position in the run of the selection's `k`th cell.
    fn at(self, k: usize) -> usize {
        match self {
            Sel::All(_) => k,
            Sel::Some(at) => at[k] as usize,
        }
    }
}

/// An operand of a strict call at every cell: a reference written as one,
/// made at each cell as [`Ctx::eval`] makes it, or a value.
enum Operand<'e> {
    Ref(&'e RefExpr),
    Value(Lane),
}

/// The most operands of an aggregate the run computes itself (KERNEL.26);
/// a call of more is left to the library's function at each cell.
const COUNTED: usize = 8;

/// How `IF`'s conditions part the cells of a selection.
enum Parted {
    /// Every cell takes the one branch.
    All(bool),
    /// The answer at every cell, the condition a reason or an error.
    Answer(Lane),
    /// Each cell's own: the answers' lane, a place held for each, and the
    /// cells that take each branch, by place in the selection.
    Cells(Lane, Vec<u32>, Vec<u32>),
}

/// One run's evaluation.
struct Many<'a> {
    env: &'a dyn Env,
    lib: &'a Library,
    /// The run's cells, in the order of evaluation, all on one sheet.
    cells: &'a [CellId],
    /// The cell the shape was read at, from which each cell's offset is.
    anchor: CellId,
    lanes: RefCell<&'a mut Lanes>,
    /// The places of the parse's repeated parts (KERNEL.27), each by its
    /// node's address in this parse, its part and whether it is the last;
    /// sorted by address.
    found: Vec<Key>,
    /// By part, the lane its first place computed, while a later place has
    /// yet to take it.
    kept: RefCell<Vec<Option<Lane>>>,
    /// The address of the place [`Many::again`] has just asked
    /// [`Many::scalars`] to compute, 0 for none, so that the node's own
    /// frame computes it, the question of whether it is a place asked of
    /// this marker alone.
    computing: Cell<usize>,
}

/// A shape's parse evaluated at each of a run's cells, the cells read at
/// `anchor`'s offset from each, each cell's answer pushed to `out` in the
/// run's order as the shape's evaluation at the cell alone answers it
/// (`Shapes::evaluate`); `held` is what [`holds`] says of the parse, with a
/// lane for each of its repeated parts, `repeats` (KERNEL.27).
#[allow(clippy::too_many_arguments)]
pub(crate) fn evaluate(
    env: &dyn Env,
    lib: &Library,
    expr: &Expr,
    held: (usize, usize),
    repeats: &Repeats,
    anchor: CellId,
    cells: &[CellId],
    lanes: &mut Lanes,
    out: &mut Vec<Computed>,
) {
    lanes.reserve(held);
    let mut found = std::mem::take(&mut lanes.found);
    repeats.found(expr, &mut found);
    let mut kept = std::mem::take(&mut lanes.kept);
    kept.clear();
    kept.resize_with(repeats.parts(), || None);
    let many = Many {
        env,
        lib,
        cells,
        anchor,
        lanes: RefCell::new(lanes),
        found,
        kept: RefCell::new(kept),
        computing: Cell::new(0),
    };
    match many.scalars(expr, Sel::All(cells.len())) {
        Lane::Same(got) => {
            // The last cell takes the answer itself, the others a copy, as
            // many as alone.
            if let Some((_, rest)) = cells.split_last() {
                for _ in rest {
                    out.push(computed(got.clone()));
                }
                out.push(computed(got));
            }
        }
        Lane::Each(mut each) => {
            out.extend(each.drain(..).map(computed));
            many.give(each);
        }
        Lane::Numbers(numbers) => {
            out.extend(numbers.iter().map(|&n| Computed::Value(Value::Number(n))));
            many.give_numbers(numbers);
        }
        Lane::Truths(truths) => {
            out.extend(truths.iter().map(|&b| Computed::Value(Value::Bool(b))));
            many.give_truths(truths);
        }
    }
    // A lane kept for a part whose last place was not reached given back,
    // and the buffers of the places to the caller (KERNEL.27).
    for k in 0..repeats.parts() {
        let lane = many.kept.borrow_mut()[k].take();
        if let Some(lane) = lane {
            many.give_lane(lane);
        }
    }
    let Many {
        lanes, found, kept, ..
    } = many;
    let lanes = lanes.into_inner();
    lanes.found = found;
    lanes.kept = kept.into_inner();
}

/// A cell's answer as its formula holds it.
fn computed(got: Got) -> Computed {
    match got {
        Ok(v) => Computed::Value(v.settled()),
        Err(r) => Computed::NotComputed(r),
    }
}

impl<'a> Many<'a> {
    /// A cell's offset from the cell the shape was read at.
    fn offset(&self, pos: usize) -> (i64, i64) {
        let (_, row, col) = self.cells[pos];
        (
            i64::from(row) - i64::from(self.anchor.1),
            i64::from(col) - i64::from(self.anchor.2),
        )
    }

    /// The evaluation at one cell of the run, the environment told it is
    /// the cell being computed.
    fn ctx(&self, pos: usize) -> Ctx<'a> {
        self.env.enter(self.cells[pos]);
        let (d_row, d_col) = self.offset(pos);
        Ctx::at(self.env, self.lib, d_row, d_col)
    }

    fn take(&self) -> Vec<Got> {
        let kept = self.lanes.borrow_mut().values.pop();
        kept.unwrap_or_else(|| Vec::with_capacity(CHUNK))
    }

    fn give(&self, mut lane: Vec<Got>) {
        lane.clear();
        self.lanes.borrow_mut().values.push(lane);
    }

    fn take_numbers(&self) -> Vec<f64> {
        let kept = self.lanes.borrow_mut().numbers.pop();
        kept.unwrap_or_else(|| Vec::with_capacity(CHUNK))
    }

    fn give_numbers(&self, mut lane: Vec<f64>) {
        lane.clear();
        self.lanes.borrow_mut().numbers.push(lane);
    }

    fn take_truths(&self) -> Vec<bool> {
        let kept = self.lanes.borrow_mut().truths.pop();
        kept.unwrap_or_else(|| Vec::with_capacity(CHUNK))
    }

    fn give_truths(&self, mut lane: Vec<bool>) {
        lane.clear();
        self.lanes.borrow_mut().truths.push(lane);
    }

    /// A lane's buffer given back, whatever it holds.
    fn give_lane(&self, lane: Lane) {
        match lane {
            Lane::Same(_) => {}
            Lane::Each(each) => self.give(each),
            Lane::Numbers(numbers) => self.give_numbers(numbers),
            Lane::Truths(truths) => self.give_truths(truths),
        }
    }

    /// A lane as values, each cell's answer as the lane of values holds it
    /// (KERNEL.26).
    fn values(&self, lane: Lane) -> Values {
        match lane {
            Lane::Same(got) => Values::Same(got),
            Lane::Each(each) => Values::Each(each),
            Lane::Numbers(numbers) => {
                let mut each = self.take();
                each.extend(numbers.iter().map(|&n| Ok(Value::Number(n))));
                self.give_numbers(numbers);
                Values::Each(each)
            }
            Lane::Truths(truths) => {
                let mut each = self.take();
                each.extend(truths.iter().map(|&b| Ok(Value::Bool(b))));
                self.give_truths(truths);
                Values::Each(each)
            }
        }
    }

    /// [`Many::values`], as a lane.
    fn valued(&self, lane: Lane) -> Lane {
        match self.values(lane) {
            Values::Same(got) => Lane::Same(got),
            Values::Each(each) => Lane::Each(each),
        }
    }

    /// An arithmetic operator at each cell of a lane of numbers, its left
    /// operand or its right, `f` the operator's answer at the `k`th cell over
    /// the number there: each answer written where its operand stood, a lane
    /// of numbers while each is a number (KERNEL.26).
    fn arithmetic_in_place(&self, mut numbers: Vec<f64>, f: impl Fn(usize, f64) -> Value) -> Lane {
        for k in 0..numbers.len() {
            match f(k, numbers[k]) {
                Value::Number(n) => numbers[k] = n,
                other => {
                    let mut each = self.take();
                    each.extend(numbers[..k].iter().map(|&n| Ok(Value::Number(n))));
                    each.push(Ok(other));
                    each.extend((k + 1..numbers.len()).map(|j| Ok(f(j, numbers[j]))));
                    self.give_numbers(numbers);
                    return Lane::Each(each);
                }
            }
        }
        Lane::Numbers(numbers)
    }

    /// A comparison at each of `n` cells, `ordering` how its operands compare
    /// at the `k`th: a lane of truth values (KERNEL.26).
    fn compared(&self, op: BinOp, n: usize, ordering: impl Fn(usize) -> Ordering) -> Lane {
        let mut truths = self.take_truths();
        truths.extend((0..n).map(|k| compares(op, ordering(k))));
        Lane::Truths(truths)
    }

    /// One more cell's answer pushed to a lane being made, which stays a
    /// lane of numbers or of truth values while every answer is one, and
    /// becomes a lane of values at the first that is not (KERNEL.26).
    fn push(&self, lane: &mut Lane, got: Got) {
        match (&mut *lane, got) {
            (Lane::Each(each), got) => each.push(got),
            (Lane::Numbers(numbers), Ok(Value::Number(n))) => numbers.push(n),
            (Lane::Truths(truths), Ok(Value::Bool(b))) => truths.push(b),
            (_, got) => {
                let made = std::mem::replace(lane, Lane::Same(Ok(Value::Empty)));
                *lane = self.valued(made);
                if let Lane::Each(each) = lane {
                    each.push(got);
                }
            }
        }
    }

    fn positions(&self) -> Vec<u32> {
        let kept = self.lanes.borrow_mut().positions.pop();
        kept.unwrap_or_else(|| Vec::with_capacity(CHUNK))
    }

    fn give_positions(&self, mut at: Vec<u32>) {
        at.clear();
        self.lanes.borrow_mut().positions.push(at);
    }

    /// [`Ctx::scalar`] at every cell of the selection; a place of a repeated
    /// part from its part's lane (KERNEL.27).
    fn scalars(&self, e: &Expr, sel: Sel) -> Lane {
        if self.repeated(e) {
            return self.again(e, &sel);
        }
        match e {
            Expr::Number(v) => Lane::Same(Ok(Value::Number(*v))),
            Expr::Text(t) => Lane::Same(Ok(Value::Text(t.clone()))),
            Expr::Bool(b) => Lane::Same(Ok(Value::Bool(*b))),
            Expr::Error(k) => Lane::Same(Ok(Value::Error(*k))),
            Expr::Empty => Lane::Same(Ok(Value::Empty)),
            Expr::Ref(r) if matches!(r.shape, Part::Cell) && r.last_sheet.is_none() => {
                self.reads(r, sel)
            }
            Expr::Neg(x) => self.unary(x, sel, |n| -n),
            // Unary plus is its operand, which a scalar reads as one value.
            Expr::Pos(x) => self.scalars(x, sel),
            Expr::Percent(x) => self.unary(x, sel, |n| n / 100.0),
            Expr::Binary(..) => self.chain(e, sel),
            Expr::Call(name, args) => self.call(e, name, args, sel),
            // A range where one value is wanted, a defined name: each cell's.
            Expr::Ref(_) | Expr::Name { .. } => self.each_cell(e, sel),
        }
    }

    /// Whether an expression is a place of a repeated part (KERNEL.27), by
    /// its node's address; never the place [`Many::again`] is computing,
    /// which it asks [`Many::scalars`] for once. A question of a `bool`, so
    /// that the frame a level of nesting stacks holds nothing more for it.
    fn repeated(&self, e: &Expr) -> bool {
        let at = e as *const Expr as usize;
        !self.found.is_empty() && self.computing.replace(0) != at && self.part_at(at).is_some()
    }

    /// A place's part, and whether it is the part's last place, by its
    /// node's address.
    fn part_at(&self, at: usize) -> Option<(u16, bool)> {
        let i = self.found.binary_search_by_key(&at, |&(a, _, _)| a).ok()?;
        let (_, place, _) = self.found[i];
        Some(((place >> 1) as u16, place & 1 == 1))
    }

    /// A place of a repeated part, in a frame of its own (KERNEL.27): the
    /// lane its part's first place computed and kept, copied, or taken at
    /// the last place; at the first, the part computed by [`Many::scalars`]
    /// and a copy kept.
    #[inline(never)]
    fn again(&self, e: &Expr, sel: &Sel) -> Lane {
        let at = e as *const Expr as usize;
        let Some((part, last)) = self.part_at(at) else {
            // Never: the node was found a place. Computed where it stands.
            self.computing.set(at);
            return self.scalars(e, *sel);
        };
        let k = usize::from(part);
        let held = self.kept.borrow_mut()[k].take();
        match held {
            Some(lane) if last => lane,
            Some(lane) => {
                let copy = self.copied(&lane);
                self.kept.borrow_mut()[k] = Some(lane);
                copy
            }
            None => {
                self.computing.set(at);
                let lane = self.scalars(e, *sel);
                if !last {
                    let copy = self.copied(&lane);
                    self.kept.borrow_mut()[k] = Some(copy);
                }
                lane
            }
        }
    }

    /// A lane copied into a buffer of its own kind (KERNEL.27).
    fn copied(&self, lane: &Lane) -> Lane {
        match lane {
            Lane::Same(got) => Lane::Same(got.clone()),
            Lane::Each(each) => {
                let mut copy = self.take();
                copy.extend(each.iter().cloned());
                Lane::Each(copy)
            }
            Lane::Numbers(numbers) => {
                let mut copy = self.take_numbers();
                copy.extend_from_slice(numbers);
                Lane::Numbers(copy)
            }
            Lane::Truths(truths) => {
                let mut copy = self.take_truths();
                copy.extend_from_slice(truths);
                Lane::Truths(copy)
            }
        }
    }

    /// A reference to one cell as written, read at every cell: its sheet
    /// found as `graph::areas_at` finds it, the same at every cell of the
    /// run; read once when every `$` holds it; a sheet the environment keeps
    /// as an array read by index, an empty slot through the environment,
    /// where a reason may stand beside it. The values read are a lane of
    /// numbers while every one is a number (KERNEL.26).
    fn reads(&self, r: &RefExpr, sel: Sel) -> Lane {
        if sel.len() == 0 {
            return Lane::Each(self.take());
        }
        let sheet = match (r.found, &r.sheet) {
            (Some((first, _)), _) => usize::from(first),
            (None, None) => self.cells[sel.at(0)].0,
            (None, Some(name)) => match self.env.model().find_sheet(name) {
                Some(s) => s,
                None => return Lane::Same(Ok(Value::Error(ErrorKind::Ref))),
            },
        };
        let dense = self.env.dense(sheet);
        // A number read where it stands, or the answer of any other kind.
        let at = |k: usize| -> Result<f64, Got> {
            let (d_row, d_col) = self.offset(sel.at(k));
            let Some((row, col, _, _)) = r.moved(d_row, d_col) else {
                return Err(Ok(Value::Error(ErrorKind::Ref)));
            };
            match dense.and_then(|d| d.get(row, col)) {
                Some(Value::Number(n)) => Ok(*n),
                Some(v) if !matches!(v, Value::Empty) => Err(Ok(v.clone())),
                _ => match self.env.read((sheet, row, col)) {
                    Ok(Value::Number(n)) => Ok(n),
                    got => Err(got),
                },
            }
        };
        let got = |k: usize| -> Got {
            match at(k) {
                Ok(n) => Ok(Value::Number(n)),
                Err(other) => other,
            }
        };
        if r.corners.row_abs1 && r.corners.col_abs1 {
            return Lane::Same(got(0));
        }
        let mut numbers = self.take_numbers();
        for k in 0..sel.len() {
            match at(k) {
                Ok(n) => numbers.push(n),
                Err(other) => {
                    let mut out = self.take();
                    out.extend(numbers.iter().map(|&n| Ok(Value::Number(n))));
                    self.give_numbers(numbers);
                    out.push(other);
                    out.extend((k + 1..sel.len()).map(got));
                    return Lane::Each(out);
                }
            }
        }
        Lane::Numbers(numbers)
    }

    /// A sign or a percent at every cell, over the number each value reads as.
    fn unary(&self, x: &Expr, sel: Sel, f: fn(f64) -> f64) -> Lane {
        let lane = self.scalars(x, sel);
        self.signed(lane, f)
    }

    /// [`Many::unary`] over its operand's lane, in a frame of its own, so
    /// that nothing here stands beneath the evaluation of a deeper level.
    #[inline(never)]
    fn signed(&self, lane: Lane, f: fn(f64) -> f64) -> Lane {
        let number = |v: &mut Value| {
            *v = match v.number() {
                Ok(n) => finite(f(n)),
                Err(k) => Value::Error(k),
            }
        };
        match lane {
            // Over numbers, as numbers while each answer is one (KERNEL.26).
            Lane::Numbers(numbers) => self.numbers_mapped(numbers, |n| finite(f(n))),
            lane => match self.values(lane) {
                Values::Same(mut got) => {
                    if let Ok(v) = got.as_mut() {
                        number(v);
                    }
                    Lane::Same(got)
                }
                Values::Each(mut each) => {
                    for v in each.iter_mut().flatten() {
                        number(v);
                    }
                    Lane::Each(each)
                }
            },
        }
    }

    /// A lane of numbers, each made a value by `f`: a lane of numbers while
    /// each answer is a number, a lane of values from the first that is not
    /// (KERNEL.26).
    fn numbers_mapped(&self, mut numbers: Vec<f64>, f: impl Fn(f64) -> Value) -> Lane {
        for k in 0..numbers.len() {
            match f(numbers[k]) {
                Value::Number(n) => numbers[k] = n,
                other => {
                    let mut each = self.take();
                    each.extend(numbers[..k].iter().map(|&n| Ok(Value::Number(n))));
                    each.push(Ok(other));
                    each.extend(numbers[k + 1..].iter().map(|&n| Ok(f(n))));
                    self.give_numbers(numbers);
                    return Lane::Each(each);
                }
            }
        }
        Lane::Numbers(numbers)
    }

    /// A binary operator, or a chain of them, at every cell: the leftmost
    /// operand, then each link in turn, as `Ctx::chain` goes round its left
    /// spine, the right operands on a stack; a link below the first that is
    /// a place of a repeated part the leftmost operand (KERNEL.27), which
    /// computes the same values in the same order.
    fn chain(&self, e: &Expr, sel: Sel) -> Lane {
        const NEAR: usize = 16;
        let mut near: [(BinOp, &Expr); NEAR] = [(BinOp::Add, e); NEAR];
        let mut far: Vec<(BinOp, &Expr)> = Vec::new();
        let mut links = 0;
        let mut left = e;
        while let Expr::Binary(op, l, r) = left {
            if links > 0 && self.repeated(left) {
                break;
            }
            if links < NEAR {
                near[links] = (*op, r);
            } else {
                far.push((*op, r));
            }
            links += 1;
            left = l;
        }
        let mut acc = self.scalars(left, sel);
        for i in (0..links).rev() {
            let (op, r) = if i < NEAR { near[i] } else { far[i - NEAR] };
            let b = self.scalars(r, sel);
            acc = self.combine(op, acc, b);
        }
        acc
    }

    /// [`binary`] at every cell: the left operand's reason first, then the
    /// right's, then the operator over the two values; over two lanes of
    /// numbers, or one and a number the same at every cell, the operator's
    /// rule over numbers, `binary`'s own (KERNEL.26).
    fn combine(&self, op: BinOp, a: Lane, b: Lane) -> Lane {
        let (a, b) = match (op, a, b) {
            (BinOp::Concat, a, b) => (self.values(a), self.values(b)),
            (op, Lane::Numbers(xs), Lane::Numbers(ys)) => {
                let lane = if is_arithmetic(op) {
                    self.arithmetic_in_place(xs, |k, x| arithmetic(op, x, ys[k]))
                } else {
                    let lane = self.compared(op, xs.len(), |k| compare_numbers(xs[k], ys[k]));
                    self.give_numbers(xs);
                    lane
                };
                self.give_numbers(ys);
                return lane;
            }
            (op, Lane::Numbers(xs), Lane::Same(Ok(Value::Number(y)))) => {
                return if is_arithmetic(op) {
                    self.arithmetic_in_place(xs, |_, x| arithmetic(op, x, y))
                } else {
                    let lane = self.compared(op, xs.len(), |k| compare_numbers(xs[k], y));
                    self.give_numbers(xs);
                    lane
                };
            }
            (op, Lane::Same(Ok(Value::Number(x))), Lane::Numbers(ys)) => {
                return if is_arithmetic(op) {
                    self.arithmetic_in_place(ys, |_, y| arithmetic(op, x, y))
                } else {
                    let lane = self.compared(op, ys.len(), |k| compare_numbers(x, ys[k]));
                    self.give_numbers(ys);
                    lane
                };
            }
            (_, a, b) => (self.values(a), self.values(b)),
        };
        match (a, b) {
            (Values::Same(x), Values::Same(y)) => Lane::Same(match (x, &y) {
                (Err(r), _) => Err(r),
                (Ok(_), Err(r)) => Err(r.clone()),
                (Ok(x), Ok(y)) => Ok(binary(op, &x, y)),
            }),
            (Values::Each(mut xs), Values::Same(y)) => {
                for x in xs.iter_mut() {
                    if let Ok(a) = x {
                        match &y {
                            Ok(b) => *a = binary(op, a, b),
                            Err(r) => *x = Err(r.clone()),
                        }
                    }
                }
                Lane::Each(xs)
            }
            (Values::Same(x), Values::Each(mut ys)) => {
                for y in ys.iter_mut() {
                    match &x {
                        Err(r) => *y = Err(r.clone()),
                        Ok(a) => {
                            if let Ok(b) = y {
                                *b = binary(op, a, b);
                            }
                        }
                    }
                }
                Lane::Each(ys)
            }
            (Values::Each(mut xs), Values::Each(mut ys)) => {
                for (x, y) in xs.iter_mut().zip(ys.iter_mut()) {
                    if let Ok(a) = x {
                        match y {
                            Ok(b) => *a = binary(op, a, b),
                            Err(r) => *x = Err(std::mem::replace(r, Reason::Cycle)),
                        }
                    }
                }
                self.give(ys);
                Lane::Each(xs)
            }
        }
    }

    /// A call at every cell: the language's `IF` here, another form at
    /// each cell, one of the language's aggregates or `NOT` here by the
    /// library's own rule and fold, any other strict function over its
    /// operands, a function the library does not hold named, in the order
    /// `Ctx` looks them up.
    fn call(&self, e: &Expr, name: &str, args: &[Expr], sel: Sel) -> Lane {
        if self.lib.form(name).is_some() {
            return match self.lib.known(name) {
                Some(Known::If) => self.if_(args, sel),
                _ => self.each_cell(e, sel),
            };
        }
        let Some(f) = self.lib.strict(name) else {
            return Lane::Same(Err(Reason::Function(name.to_string())));
        };
        if !args.iter().all(|a| is_operand(self.lib, a)) {
            return self.each_cell(e, sel);
        }
        match args {
            [a] => {
                let mut x = self.operand(a, sel);
                let lane = self.apply_one(f, name, &mut x, sel);
                self.drop_operand(x);
                lane
            }
            [a, b] => {
                let mut x = self.operand(a, sel);
                let mut y = self.operand(b, sel);
                let lane = self.apply_two(f, name, &mut x, &mut y, sel);
                self.drop_operand(x);
                self.drop_operand(y);
                lane
            }
            _ => {
                let mut ops: Vec<Operand> = args.iter().map(|a| self.operand(a, sel)).collect();
                let lane = self.apply_many(f, name, &mut ops, sel);
                for x in ops {
                    self.drop_operand(x);
                }
                lane
            }
        }
    }

    /// One of the language's own functions the run knows, over its operands
    /// computed (KERNEL.26), by the run itself when its operands are ones it
    /// walks.
    fn known_call(&self, name: &str, ops: &mut [Operand<'_>], sel: Sel) -> Option<Lane> {
        self.known(self.lib.known(name)?, ops, sel)
    }

    /// An operand at every cell, [`is_operand`] having said it can be one.
    fn operand<'e>(&self, a: &'e Expr, sel: Sel) -> Operand<'e> {
        match ref_operand(self.lib, a) {
            Some(r) => Operand::Ref(r),
            None => Operand::Value(self.scalars(a, sel)),
        }
    }

    /// One of the language's own functions the run computes itself
    /// (KERNEL.26): `SUM`, `MIN` and `MAX`, `AND` and `OR` by the library's
    /// rule and fold (`library::Fold`), over values and over ranges of sheets
    /// the environment keeps as arrays, and `NOT` over a value; `None` for a
    /// call left to the library's function at each cell: an operand naming a
    /// span of sheets or a range of a sheet walked through its cells, `NOT`
    /// of a reference, more operands than [`COUNTED`].
    fn known(&self, known: Known, ops: &mut [Operand<'_>], sel: Sel) -> Option<Lane> {
        if known == Known::Not {
            // The operand's lane taken, its values negated.
            let [Operand::Value(lane)] = ops else {
                return None;
            };
            let lane = std::mem::replace(lane, Lane::Same(Ok(Value::Empty)));
            return Some(self.negated(lane, sel));
        }
        if ops.len() > COUNTED {
            return None;
        }
        // Each reference's sheet, found as `graph::areas_at` finds it, the
        // same at every cell of the run, and its array; `None` for a sheet
        // the grid does not hold, where the reference is `#REF!`.
        let mut kept: [Option<(usize, &Dense)>; COUNTED] = [None; COUNTED];
        for (j, x) in ops.iter().enumerate() {
            let Operand::Ref(r) = x else {
                continue;
            };
            if r.last_sheet.is_some() {
                return None;
            }
            let sheet = match (r.found, &r.sheet) {
                (Some((first, _)), _) => Some(usize::from(first)),
                (None, None) => Some(self.cells[0].0),
                (None, Some(name)) => self.env.model().find_sheet(name),
            };
            if let Some(s) = sheet {
                kept[j] = Some((s, self.env.dense(s)?));
            }
        }
        let kept = &kept[..ops.len()];
        // The answers a lane of numbers, or of truth values, while each is.
        let numbers = || Lane::Numbers(self.take_numbers());
        let truths = || Lane::Truths(self.take_truths());
        Some(match known {
            Known::Sum => self.aggregate::<library::Sum>(ops, kept, sel, numbers()),
            Known::Min => self.aggregate::<library::Least>(ops, kept, sel, numbers()),
            Known::Max => self.aggregate::<library::Most>(ops, kept, sel, numbers()),
            Known::And => self.aggregate::<library::All>(ops, kept, sel, truths()),
            Known::Or => self.aggregate::<library::Some_>(ops, kept, sel, truths()),
            // A form, and `NOT` above.
            Known::If | Known::Not => return None,
        })
    }

    /// `NOT` at every cell, over the value its operand is there, as
    /// `library::negated` answers it: in place over a lane of values, a lane
    /// of truth values made over one of numbers or of truth values.
    fn negated(&self, lane: Lane, sel: Sel) -> Lane {
        match lane {
            Lane::Same(got) => Lane::Same(got.map(|v| library::negated(&v))),
            Lane::Each(mut each) => {
                for v in each.iter_mut().flatten() {
                    *v = library::negated(v);
                }
                Lane::Each(each)
            }
            typed => {
                let mut out = Lane::Truths(self.take_truths());
                for k in 0..sel.len() {
                    let got = typed.with(k, |g| g.map(library::negated).map_err(Reason::clone));
                    self.push(&mut out, got);
                }
                self.give_lane(typed);
                out
            }
        }
    }

    /// An aggregate at every cell, by its rule and its fold, as
    /// `library::folded` computes it at one; `kept` holds each reference's
    /// sheet and array, `out` the lane its answers are pushed to.
    #[inline(never)]
    fn aggregate<F: Fold>(
        &self,
        ops: &[Operand<'_>],
        kept: &[Option<(usize, &Dense)>],
        sel: Sel,
        mut out: Lane,
    ) -> Lane {
        for k in 0..sel.len() {
            let got = self.fold_at::<F>(ops, kept, sel.at(k), k);
            self.push(&mut out, got);
        }
        out
    }

    /// An aggregate at one cell: each operand taken left to right, as
    /// `take_arg` takes it, a reason the answer; then each value counted in
    /// the arguments' order as `library::each_item` counts it, a value given
    /// directly coerced and its error the answer at once, a range moved to the
    /// cell and walked by index to its end, its first error the answer.
    fn fold_at<F: Fold>(
        &self,
        ops: &[Operand<'_>],
        kept: &[Option<(usize, &Dense)>],
        pos: usize,
        k: usize,
    ) -> Got {
        for x in ops {
            if let Operand::Value(lane) = x {
                if let Some(r) = lane.with(k, |g| g.err().cloned()) {
                    return Err(r);
                }
            }
        }
        let (d_row, d_col) = self.offset(pos);
        let mut fold = F::default();
        for (x, kept) in ops.iter().zip(kept) {
            let r = match x {
                Operand::Value(lane) => {
                    match lane.with(k, |g| g.ok().map(F::Rule::given)) {
                        Some(Ok(item)) => fold.add(item),
                        Some(Err(e)) => return Ok(Value::Error(e)),
                        None => {}
                    }
                    continue;
                }
                Operand::Ref(r) => r,
            };
            let area = kept.and_then(|(sheet, array)| {
                let (top, left, bottom, right) = r.moved(d_row, d_col)?;
                let area = Area {
                    sheet,
                    top,
                    left,
                    bottom,
                    right,
                };
                Some((area, array))
            });
            // A reference that names no cell is `#REF!`, a value given.
            let Some((area, array)) = area else {
                match F::Rule::given(&Value::Error(ErrorKind::Ref)) {
                    Ok(item) => fold.add(item),
                    Err(e) => return Ok(Value::Error(e)),
                }
                continue;
            };
            let mut err: Option<ErrorKind> = None;
            let walked = array.each_ref::<Infallible, _>(&area, |v| {
                match F::Rule::ranged(v) {
                    Ranged::Counts(item) => fold.add(item),
                    Ranged::Error(e) => {
                        err.get_or_insert(e);
                    }
                    Ranged::Skipped => {}
                }
                Ok(())
            });
            let Ok(()) = walked;
            if let Some(e) = err {
                return Ok(Value::Error(e));
            }
        }
        Ok(fold.answer())
    }

    fn drop_operand(&self, x: Operand<'_>) {
        if let Operand::Value(lane) = x {
            self.give_lane(lane);
        }
    }

    /// A strict function of one operand at every cell, the operand on the
    /// stack in a frame of its own (as `Ctx::strict_one`'s): computed by the
    /// run itself when it is one of the language's that the run knows and
    /// its operand is one it walks (KERNEL.26), else by the function at each
    /// cell, its answers a lane of numbers while each is one.
    #[inline(never)]
    fn apply_one(&self, f: Strict, name: &str, x: &mut Operand<'_>, sel: Sel) -> Lane {
        if let Some(lane) = self.known_call(name, std::slice::from_mut(x), sel) {
            return lane;
        }
        let (mut out, n) = (Lane::Numbers(self.take_numbers()), sel.len());
        for k in 0..n {
            let ctx = self.ctx(sel.at(k));
            let got = match take_arg(x, k, k + 1 == n, &ctx) {
                Ok(a) => f(&ctx, std::slice::from_ref(&a)),
                Err(r) => Err(r),
            };
            self.push(&mut out, got);
        }
        out
    }

    /// Two operands, left to right, the first not computed the answer; the
    /// pair held side by side while the run asks whether it computes the call
    /// itself (KERNEL.26), each given back to its place after.
    #[inline(never)]
    fn apply_two<'e>(
        &self,
        f: Strict,
        name: &str,
        x: &mut Operand<'e>,
        y: &mut Operand<'e>,
        sel: Sel,
    ) -> Lane {
        let held = || Operand::Value(Lane::Same(Ok(Value::Empty)));
        let mut pair = [std::mem::replace(x, held()), std::mem::replace(y, held())];
        let known = self.known_call(name, &mut pair, sel);
        let [a, b] = pair;
        (*x, *y) = (a, b);
        if let Some(lane) = known {
            return lane;
        }
        let (mut out, n) = (Lane::Numbers(self.take_numbers()), sel.len());
        for k in 0..n {
            let ctx = self.ctx(sel.at(k));
            let got = match take_arg(x, k, k + 1 == n, &ctx) {
                Err(r) => Err(r),
                Ok(a) => match take_arg(y, k, k + 1 == n, &ctx) {
                    Err(r) => Err(r),
                    Ok(b) => f(&ctx, &[a, b]),
                },
            };
            self.push(&mut out, got);
        }
        out
    }

    /// Any other count, in a vector made once for the run.
    #[inline(never)]
    fn apply_many(&self, f: Strict, name: &str, ops: &mut [Operand<'_>], sel: Sel) -> Lane {
        if let Some(lane) = self.known_call(name, ops, sel) {
            return lane;
        }
        let (mut out, n) = (Lane::Numbers(self.take_numbers()), sel.len());
        let mut args = Vec::with_capacity(ops.len());
        for k in 0..n {
            let ctx = self.ctx(sel.at(k));
            args.clear();
            let mut stopped = None;
            for x in ops.iter_mut() {
                match take_arg(x, k, k + 1 == n, &ctx) {
                    Ok(a) => args.push(a),
                    Err(r) => {
                        stopped = Some(r);
                        break;
                    }
                }
            }
            let got = match stopped {
                Some(r) => Err(r),
                None => f(&ctx, &args),
            };
            self.push(&mut out, got);
        }
        out
    }

    /// The language's `IF` at every cell, as `library::if_` computes it at
    /// one: the condition at each, a reason or an error the cell's answer,
    /// then each branch at the cells that take it and at no other.
    fn if_(&self, args: &[Expr], sel: Sel) -> Lane {
        if args.len() < 2 || args.len() > 3 {
            return Lane::Same(Ok(Value::Error(ErrorKind::Value)));
        }
        let conditions = self.scalars(&args[0], sel);
        let (mut out, yes, no) = match self.parted(conditions, sel) {
            Parted::All(taken) => return self.branch(args, taken, sel),
            Parted::Answer(lane) => return lane,
            Parted::Cells(out, yes, no) => (out, yes, no),
        };
        self.fill(&mut out, args, true, sel, &yes);
        self.fill(&mut out, args, false, sel, &no);
        self.give_positions(yes);
        self.give_positions(no);
        out
    }

    /// How `IF`'s conditions at every cell of the selection part its cells,
    /// in a frame of its own, so that nothing here stands beneath the
    /// evaluation of a deeper level.
    #[inline(never)]
    fn parted(&self, conditions: Lane, sel: Sel) -> Parted {
        let (mut yes, mut no) = match conditions {
            Lane::Same(Err(r)) => return Parted::Answer(Lane::Same(Err(r))),
            Lane::Same(Ok(v)) => {
                return match v.truth() {
                    Ok(taken) => Parted::All(taken),
                    Err(k) => Parted::Answer(Lane::Same(Ok(Value::Error(k)))),
                }
            }
            _ => (self.positions(), self.positions()),
        };
        let out = match conditions {
            // The conditions' own lane holds the answers, a cell whose
            // condition is a reason or an error keeping it.
            Lane::Each(mut out) => {
                for (k, got) in out.iter_mut().enumerate() {
                    if let Ok(v) = got {
                        match v.truth() {
                            Ok(true) => yes.push(k as u32),
                            Ok(false) => no.push(k as u32),
                            Err(kind) => *v = Value::Error(kind),
                        }
                    }
                }
                Lane::Each(out)
            }
            // Over numbers or truth values, the answers a lane of numbers
            // while each branch's are (KERNEL.26), a place held for each.
            typed => {
                let mut out = Lane::Numbers(self.take_numbers());
                for k in 0..sel.len() {
                    match typed.with(k, |g| g.map(Value::truth).map_err(Reason::clone)) {
                        Ok(Ok(taken)) => {
                            if taken { &mut yes } else { &mut no }.push(k as u32);
                            self.push(&mut out, Ok(Value::Number(0.0)));
                        }
                        Ok(Err(kind)) => self.push(&mut out, Ok(Value::Error(kind))),
                        Err(r) => self.push(&mut out, Err(r)),
                    }
                }
                self.give_lane(typed);
                out
            }
        };
        Parted::Cells(out, yes, no)
    }

    /// One branch at the cells that take it, `ks` their places in the
    /// selection, each answer placed in `out`.
    fn fill(&self, out: &mut Lane, args: &[Expr], taken: bool, sel: Sel, ks: &[u32]) {
        if ks.is_empty() {
            return;
        }
        let lane = if ks.len() == sel.len() {
            self.branch(args, taken, sel)
        } else {
            let mut at = self.positions();
            at.extend(ks.iter().map(|&k| sel.at(k as usize) as u32));
            let lane = self.branch(args, taken, Sel::Some(&at));
            self.give_positions(at);
            lane
        };
        self.place(out, lane, sel, ks);
    }

    /// A branch's answers placed in `out` at the cells that take it, in a
    /// frame of its own as [`Many::parted`] is: a lane of numbers while the
    /// branch's answers are numbers (KERNEL.26), else a lane of values.
    #[inline(never)]
    fn place(&self, out: &mut Lane, lane: Lane, sel: Sel, ks: &[u32]) {
        if let Lane::Numbers(numbers) = out {
            match &lane {
                Lane::Same(Ok(Value::Number(n))) => {
                    for &k in ks {
                        numbers[k as usize] = *n;
                    }
                    return;
                }
                Lane::Numbers(answers) => {
                    for (j, &k) in ks.iter().enumerate() {
                        numbers[k as usize] = answers[j];
                    }
                    self.give_lane(lane);
                    return;
                }
                _ => {}
            }
        }
        let made = std::mem::replace(out, Lane::Same(Ok(Value::Empty)));
        let mut each = match self.values(made) {
            Values::Each(each) => each,
            Values::Same(got) => {
                let mut each = self.take();
                each.resize(sel.len(), got);
                each
            }
        };
        match lane {
            Lane::Same(got) => {
                if let Some((&last, rest)) = ks.split_last() {
                    for &k in rest {
                        each[k as usize] = got.clone();
                    }
                    each[last as usize] = got;
                }
            }
            mut lane => {
                for (j, &k) in ks.iter().enumerate() {
                    each[k as usize] = lane.take_at(j, false);
                }
                self.give_lane(lane);
            }
        }
        *out = Lane::Each(each);
    }

    /// The branch `IF` takes on a truth value, at the cells selected: a
    /// branch left out reads as 0 when taken, a missing else as FALSE.
    fn branch(&self, args: &[Expr], taken: bool, sel: Sel) -> Lane {
        match (taken, args.get(1), args.get(2)) {
            (true, Some(Expr::Empty), _) | (false, _, Some(Expr::Empty)) => {
                Lane::Same(Ok(Value::Number(0.0)))
            }
            (true, Some(then), _) => self.scalars(then, sel),
            (false, _, Some(otherwise)) => self.scalars(otherwise, sel),
            (false, _, None) => Lane::Same(Ok(Value::Bool(false))),
            (true, None, _) => Lane::Same(Ok(Value::Error(ErrorKind::Value))),
        }
    }

    /// An expression evaluated at each cell by [`Ctx`] itself.
    #[inline(never)]
    fn each_cell(&self, e: &Expr, sel: Sel) -> Lane {
        let mut out = self.take();
        for k in 0..sel.len() {
            out.push(self.ctx(sel.at(k)).scalar(e));
        }
        Lane::Each(out)
    }
}

/// A strict call's operand at the selection's `k`th cell: a reference made
/// there, a value moved out of its lane, which nothing reads again; a value
/// the same at every cell copied, and moved at the `last` cell, so that the
/// copies are as many as alone.
fn take_arg<'e>(
    x: &mut Operand<'e>,
    k: usize,
    last: bool,
    ctx: &Ctx<'_>,
) -> Result<Arg<'e>, Reason> {
    match x {
        Operand::Ref(r) => ctx.reference(r),
        Operand::Value(lane) => lane.take_at(k, last).map(Arg::Scalar),
    }
}