| | @@ -859,6 +859,8 @@ |
| 859 | 859 | |
| 860 | 860 | Met in tery's `aligned`, `(a + 7) & -8`. |
| 861 | 861 | |
| 862 | +**Status.** Deferred by the owner on 2026-10-22: not soon, if at all. |
| 863 | + |
| 862 | 864 | ## Dividing 128 bits by 64 |
| 863 | 865 | |
| 864 | 866 | `Math.mul` gives the 128-bit product of two `U64`s; there is nothing |
| | @@ -1304,3 +1306,206 @@ |
| 1304 | 1306 | |
| 1305 | 1307 | Met in rnet, whose `Smtp` copied `Ws`'s (2026-10-22); listed in |
| 1306 | 1308 | `~/r/RAZ-GAPS.md` before that, from rnet and flojo. |
| 1309 | + |
| 1310 | +## A library that says which raz it was written for |
| 1311 | + |
| 1312 | +0.19 moved the library from pointers to `var` and `const` parameters, |
| 1313 | +and every library pinned to an older raz stopped building: rnet, rjson, |
| 1314 | +rfetch, rj and arno needed fixes, and alba, clima and linia carried |
| 1315 | +their own JSON reader meanwhile. The errors were loud but far from the |
| 1316 | +cause: "can't use ^Buf as Buf" inside rjson, read by someone building |
| 1317 | +clima. The report says the library "grows only by what breaks no |
| 1318 | +program", and the move broke all of them. Three small pieces, none of |
| 1319 | +them syntax. |
| 1320 | + |
| 1321 | +**A deprecation step.** A change to the standard library that breaks |
| 1322 | +programs keeps the old form for one minor version beside the new, the |
| 1323 | +old one marked so that a call to it is a warning naming the new one: |
| 1324 | + |
| 1325 | + (* deprecated: Buf.add(var b, ...) *) |
| 1326 | + proc addOld*(b: ^Buf; s: []U8); |
| 1327 | + |
| 1328 | +How the mark is written is the open question: a comment the compiler |
| 1329 | +reads is a pragma in disguise; a word like `obsolete` before `proc` is |
| 1330 | +a reserved word for a rare case. The step could also be policy alone, |
| 1331 | +with no mark: the release notes list the old forms and the next |
| 1332 | +version removes them. |
| 1333 | + |
| 1334 | +**An error says whose module it is in.** An error in a module found |
| 1335 | +through `-I` or `RAZ_PATH` names the directory it came from and, if |
| 1336 | +that directory holds a file `RAZ-VERSION` (one line, `0.21`), the raz |
| 1337 | +it was written for: |
| 1338 | + |
| 1339 | + /home/luis/.raz/lib/Json.raz:41: can't use ^Buf as Buf |
| 1340 | + (a library written for raz 0.18; this is raz 0.21) |
| 1341 | + |
| 1342 | +The compiler only reads the file; it never refuses to build. A library |
| 1343 | +that has none is no worse off than today. |
| 1344 | + |
| 1345 | +**`raz --version` says its commit** when `git describe` finds no tag, |
| 1346 | +as from a shallow fetch, instead of "unknown" (rcrypto pins a commit |
| 1347 | +and always sees "unknown"). |
| 1348 | + |
| 1349 | +Met in rnet, rjson, rfetch, rj, arno, alba, clima and linia (0.19), |
| 1350 | +and rcrypto (`--version`). |
| 1351 | + |
| 1352 | +## Sys for a server |
| 1353 | + |
| 1354 | +Library growth that breaks no program. Programs that serve sockets |
| 1355 | +(rabble's relay and daemon, dwa's broker, rdbus, awizo, arno's te |
| 1356 | +protocol) each declare a few C procedures or make system calls with |
| 1357 | +`SYSCALL` in a `.linux.raz` file, for what any server needs. Each piece |
| 1358 | +below stands alone; together they are about a dozen procedures in |
| 1359 | +`Sys.raz` and `Sys.linux-x86_64.raz`. |
| 1360 | + |
| 1361 | +- **`shutdown`.** `proc closeWrite*(fd: INT): INT;` ends this side's |
| 1362 | + writing, `SHUT_WR`, so the peer reads an end and can still answer |
| 1363 | + on the same socket (te's protocol; rabble wakes a thread waiting in |
| 1364 | + a handshake with it). Met in dwa, rabble, arno. |
| 1365 | +- **Who is at the other end.** `proc peer*(fd: INT): (Peer, INT);` |
| 1366 | + with `Peer` the address of a TCP peer (family, address bytes, port) |
| 1367 | + and, for a Unix socket, the peer's uid and pid (`SO_PEERCRED`). A |
| 1368 | + server can log who connected and a broker can check that its client |
| 1369 | + is the same user, instead of trusting a 0700 directory. Met in |
| 1370 | + rabble, dwa. |
| 1371 | +- **A pair of sockets.** `proc socketPair*(): (INT, INT, INT);` the two |
| 1372 | + ends and 0, or minus an errno. Met in rdbus's tests and rabble's |
| 1373 | + relay. |
| 1374 | +- **A send that doesn't wait.** `proc sendNow*(fd: INT; s: []U8): INT;` |
| 1375 | + (`MSG_DONTWAIT`): -11 where `send` would wait, without making reads |
| 1376 | + non-blocking too. Met in rdbus. |
| 1377 | +- **Opening without waiting.** `nonblocking` and `closeOnExec` among |
| 1378 | + `Access`. Opening a fifo to write waits for a reader, and a fifo |
| 1379 | + given where a file was expected waits for a writer. Met in mosaico, |
| 1380 | + awizo, surco, raudio. |
| 1381 | +- **A fifo.** `proc makeFifo*(path: []U8; mode: INT): INT;`. Met in |
| 1382 | + awizo. |
| 1383 | +- **An owner.** `Info.uid`, `Info.gid` and `proc chown*(path: []U8; |
| 1384 | + uid, gid: INT): INT;`, so a save through rename keeps the owner and a |
| 1385 | + daemon can check that its directory is the user's. Met in dwa, |
| 1386 | + rabble. |
| 1387 | +- **Keepalive.** `proc keepAlive*(fd: INT; idle, interval, count: |
| 1388 | + INT): INT;` rather than a general `setsockopt`, whose value is a |
| 1389 | + pointer and a length of any type. Met in rabble. |
| 1390 | +- **An abstract Unix socket.** `connect` passes `2 + LEN(path)` as the |
| 1391 | + address's length when the path starts with a zero byte, so Linux's |
| 1392 | + abstract names (D-Bus's `unix:abstract=`) are reached. A fix, not a |
| 1393 | + procedure. Met in rdbus. |
| 1394 | +- **`errConnAborted`** (-103), which `accept` gives for a client gone |
| 1395 | + before it was taken. Met in rabble. |
| 1396 | + |
| 1397 | +**Waiting**, the one piece that changes a procedure's answer, and so |
| 1398 | +better as a new procedure than a change to `readyFor`: |
| 1399 | + |
| 1400 | + (* Waits up to ms milliseconds (ms < 0: as long as it takes) until |
| 1401 | + one of fds may be read or written as each of its wants says, and |
| 1402 | + sets each one's ready. The number ready, 0 on a timeout, or minus |
| 1403 | + an errno. *) |
| 1404 | + proc poll*(var fds: []Poll; ms: INT): INT; |
| 1405 | + |
| 1406 | +with `Poll = record fd: INT; read, write: BOOL; ready: BOOL; end`. |
| 1407 | +It takes as many as it is given (`readyFor` stops at 64, so dwa's |
| 1408 | +broker serves 31 editors), answers every ready descriptor in one call |
| 1409 | +(`readyOf` gives only the first, so awizo takes two rounds and rabble |
| 1410 | +rotates its clients so that the first doesn't starve the rest), gives |
| 1411 | +the place in the list, not the fd, and tells a timeout from an error |
| 1412 | +(both are -1 today). `readyFor` and `readyOf` stay, written over it. |
| 1413 | +Whole milliseconds stay too: surco rounds up, and a wait in |
| 1414 | +nanoseconds is `ppoll`, Linux's, for one program. |
| 1415 | + |
| 1416 | +Each item is listed in `~/r/RAZ-GAPS.md` under "Standard library: Sys, |
| 1417 | +files, processes". |
| 1418 | + |
| 1419 | +## Sys for running a program |
| 1420 | + |
| 1421 | +Library growth, but two of the four change what `spawn` and `wait` |
| 1422 | +do, so they need the owner's word on whether a change of behaviour |
| 1423 | +counts as breaking. |
| 1424 | + |
| 1425 | +- **`spawn` says a program isn't there.** Today a missing program |
| 1426 | + still gives a pid, and the child exits 127, which a caller can't tell |
| 1427 | + from the program's own 127; clima, alba, sauce and raztest search |
| 1428 | + `PATH` first, about 20 lines each, and sauce still reads curl's 127 |
| 1429 | + as "cannot run curl". `spawn` searches `PATH` in the parent, as |
| 1430 | + `exec` already does, and gives -2 (ENOENT) before it forks. A |
| 1431 | + program found but failing in `execve` (not executable, a bad |
| 1432 | + interpreter) still exits 127, since only the child sees that; a |
| 1433 | + close-on-exec pipe would carry its errno back, at the cost of a pipe |
| 1434 | + per spawn. |
| 1435 | +- **Ignored signals stay ignored.** `spawn` and `exec` give the child |
| 1436 | + every signal as at first, SIG_IGN included, where `execve` keeps an |
| 1437 | + ignored one ignored: a robbie under `nohup` runs its recipes without |
| 1438 | + it, and ssh run by fdn doesn't keep SIGPIPE ignored. A |
| 1439 | + `Program.keepIgnored: BOOL`, false as today, keeps them. |
| 1440 | +- **`fds` with `tty`.** With `tty`, the pseudo-terminal is all three |
| 1441 | + files and `fds` is ignored, so dwa's background job that should read |
| 1442 | + `/dev/null` waits on a terminal nobody types to. A non-zero `fds[i]` |
| 1443 | + replaces the terminal for that file; zero keeps it. |
| 1444 | +- **`wait` without the stopped.** `wait` always asks for stopped |
| 1445 | + children (WUNTRACED), so a program waiting for `$EDITOR` loops past |
| 1446 | + Ctrl-Z (notis, fdn). `proc waitExit*(pid: INT): (INT, Status, INT);` |
| 1447 | + waits only for an end, or `wait` takes `stopped: BOOL`, which |
| 1448 | + changes its signature. |
| 1449 | + |
| 1450 | +`PATH` read empty as unset (pict) stays: the library volume says so, |
| 1451 | +and it is `execvp`'s choice. |
| 1452 | + |
| 1453 | +## An investigation: where a hot loop's time goes |
| 1454 | + |
| 1455 | +Not a change: a measurement, whose report would say whether register |
| 1456 | +allocation, inlining (see "Inlining a procedure that only returns"), |
| 1457 | +or neither is worth its weight in the compiler. |
| 1458 | + |
| 1459 | +What is known, from rcrypto, rat and sauce: |
| 1460 | + |
| 1461 | +| Code | MB/s | Against | |
| 1462 | +|---|---|---| |
| 1463 | +| ChaCha20, `quarter` on a `var x: [16]U32` | 40 | 78 written out on sixteen locals; OpenSSL scalar 589 | |
| 1464 | +| Poly1305, arithmetic on locals, no calls | 491 | | |
| 1465 | +| AES-128 bitsliced, 115 gates on 130 local `U64`s | 23 | GHASH 180 | |
| 1466 | +| SHA-256 with `ROR` | 76 | 40 before `ROR` | |
| 1467 | + |
| 1468 | +and rat's parser, which inlines `Utf8.take` by hand because the call |
| 1469 | +costs 7 to 10 per cent. |
| 1470 | + |
| 1471 | +The steps: a `bench/` of these few kernels, each in its plain form and |
| 1472 | +its hand-tuned one; their `raz -S` read side by side, counting loads |
| 1473 | +and stores of locals, spills and calls; then the same kernel with the |
| 1474 | +generator changed by hand (a local kept in a register across a loop, a |
| 1475 | +small procedure inlined) to put a number on each. The outcome is a |
| 1476 | +page here saying which change buys what, and none is made before it. |
| 1477 | + |
| 1478 | +Listed in `~/r/RAZ-GAPS.md` as "A state in an array or behind a `var` |
| 1479 | +is slow" and "No procedure is inlined". |
| 1480 | + |
| 1481 | +## A width in `Fmt` |
| 1482 | + |
| 1483 | +Library growth that breaks no program. `Fmt` has only `{}`, so seven |
| 1484 | +programs pad by hand: arno, rat, notis and poczta each have a |
| 1485 | +two-digit helper for times, surco writes `m:ss` and its cover files' |
| 1486 | +lower-case hashes with loops of its own, rttf writes `U+00E9` and raz's |
| 1487 | +own `Prop` a fixed-width hex name. |
| 1488 | + |
| 1489 | +The proposal: a width between the braces, and a zero before it to pad |
| 1490 | +with zeros, right-aligned: |
| 1491 | + |
| 1492 | + Fmt.print("{2}:{02}", [Fmt.int(m), Fmt.int(s)]); (* " 3:07" *) |
| 1493 | + Fmt.print("U+{04}", [Fmt.hex(0E9H)]); (* "U+00E9" *) |
| 1494 | + |
| 1495 | +A value wider than the width is written whole. A minus pads on the |
| 1496 | +right (`{-10}`), for columns of names. Zeros go after a sign: `{04}` of |
| 1497 | +-7 is `-007`. Nothing else: no precision (`Fmt.real` has `places`), no |
| 1498 | +other fill, no named or numbered arguments. |
| 1499 | + |
| 1500 | +And a lower-case hexadecimal: a case `lowHex(h: U64)` beside `hex`, or |
| 1501 | +`{x}` against `{X}`, which is a second letter in the format for a thing |
| 1502 | +an argument could say. The argument is the plainer. |
| 1503 | + |
| 1504 | +`{` followed by anything but `}` or a width is printed as it stands |
| 1505 | +today, so no format changes meaning unless it already had `{2}` in it, |
| 1506 | +which printed `{2}`. |
| 1507 | + |
| 1508 | +Open: `Fmt.real` writes its exponent `e`, the language reads only `E`, |
| 1509 | +so a printed value can't be pasted into code (rayo). Writing `E` would |
| 1510 | +change output a test may compare; reading `e` too would change the |
| 1511 | +report. |