| @@ -18,8 +18,8 @@ A `tl_value` is one machine word: |
| 18 | 18 | | `0` | Pointer to an 8-byte aligned heap block. | |
| 19 | 19 | |
| 20 | 20 | **Int arithmetic:** |
| 21 | | −- `Int` is exactly the 63-bit range. Arithmetic is checked and **overflow panics** (`tl_int_add`, `tl_int_sub`). |
| 22 | | −- Bigint promotion is deferred, and would be an ABI change. |
| 21 | +- In ABI v0 and 1, `Int` was exactly the 63-bit range, and overflow panicked. |
| 22 | +- Since ABI version 2, overflow promotes to a big integer block (`TL_TAG_BIGINT`): see [Big integers](#big-integers-abi-version-2-issue-47-proposed-needs-engineering-review). |
| 23 | 23 | |
| 24 | 24 | ## Heap blocks |
| 25 | 25 | |
| @@ -48,6 +48,7 @@ A `tl_value` is one machine word: |
| 48 | 48 | | `REF` | 1 (the cell) | — | |
| 49 | 49 | | `CAP` | a handler's clauses, then its marker | — | |
| 50 | 50 | | `ARRAY` | `TL_SCAN_LARGE`: the count, then the elements | `i64 spare`, then `spare` unused slots ([ADR 0014](adr/0014-arrays-and-bigint.md)) | |
| 51 | +| `BIGINT` | 0 | `i64 len` (`\|len\|` limbs, the sign of the number), then `uint64` limbs, least significant first | |
| 51 | 52 | |
| 52 | 53 | **`scan_fsize`:** |
| 53 | 54 | - The number of scanned fields. |
| @@ -118,7 +119,7 @@ Three things abort part of an actor's stack. All three use **yield-bubbling**: |
| 118 | 119 | | `yielding` | Cause | Stopped by | |
| 119 | 120 | |---|---|---| |
| 120 | 121 | | `FINAL` | a `final ctl` op (`tl_yield_final`) | the handler frame whose marker matches (`tl_catch_final`) | |
| 121 | | −| `PANIC` | overflow, a failed match, or `panic` (`tl_panic`) | the actor root, where the actor crashes | |
| 122 | +| `PANIC` | a division by zero (overflow before ABI 2), a failed match, or `panic` (`tl_panic`) | the actor root, where the actor crashes | |
| 122 | 123 | | `KILL` | an exit signal delivered at a safe point | the actor root | |
| 123 | 124 | |
| 124 | 125 | **Protocol:** |
| @@ -166,7 +167,8 @@ A loop that makes no calls is therefore still preemptible and killable. |
| 166 | 167 | - 1M-element lists are summed, consumed and dropped on a fiber stack (iterative drop). |
| 167 | 168 | - FBIP: a unique list is updated fully in place; a shared one is copied. |
| 168 | 169 | - A `final ctl` op unwinds 500 frames, each owning a list. The handler catches it, and live blocks return to 0. |
| 169 | | −- 1000 actors are preempted round-robin. One actor panics on overflow and crashes alone. 500 are killed mid-loop and release their lists. |
| 170 | +- 1000 actors are preempted round-robin. One actor panics (on overflow in ABI v0; on a division by zero since ABI 2) and crashes alone. 500 are killed mid-loop and release their lists. |
| 171 | +- (ABI 2) An overflow promotes to a big integer block, and subtracting back gives the small int. |
| 170 | 172 | - The root exits, the remaining actors are killed, and the process ends with 0 live blocks and 0 actors. |
| 171 | 173 | |
| 172 | 174 | ## Known limitations (v0) |
| @@ -296,6 +298,15 @@ Rationale: [ADR 0014](adr/0014-arrays-and-bigint.md). |
| 296 | 298 | - **`TL_TAG_ARRAY` blocks** have `scan_fsize = TL_SCAN_LARGE`: `fields[0]` is `tl_int(n)`, `fields[1..=n]` the elements. The raw area is the spare capacity: an `i64` count, then that many zeroed slots, so a block of capacity `cap` is `2 + cap` words and still describes itself. Drop and `send` need nothing specific. `send` promotes (shares) an array over 4 KiB that the sender keeps, like strings. The functions of `std/array` live in `tilrt/src/array.rs`. |
| 297 | 299 | - **Owned externs.** An extern declared `@extern(c, "sym", owned)` takes its arguments *owned*: it must consume each (store, return or drop it), like a closure. Perceus moves a variable's last use into the call and `dup`s other uses. With an owned argument, `rc == 1` means the caller kept no reference, so the runtime may update the block in place: `tl_array_set` and `tl_array_push` do, and copy a block whose count is not 1. An owned extern that panics drops its arguments first. Every other extern still borrows. |
| 298 | 300 | |
| 301 | +### Big integers (ABI version 2, issue #47; proposed, needs engineering review) |
| 302 | +Rationale: [ADR 0014](adr/0014-arrays-and-bigint.md). |
| 303 | +- **`TL_ABI_VERSION` is 2.** Generated `main` calls `tl_abi_check(TL_ABI_VERSION)` first; a runtime built for another version stops with a message. |
| 304 | +- **An `Int` is a small int or a `TL_TAG_BIGINT` block.** A value in the 63-bit range is always small (canonical form), so word equality decides every comparison with a small int, and a `switch` on an integer literal is unchanged. |
| 305 | +- **Fast paths:** `tl_int_add`, `tl_int_sub`, `tl_int_mul`, `tl_int_div`, `tl_int_rem`, `tl_int_eq` and `tl_int_compare` are inline. When both arguments are small and the result is small, they compute it inline (with a test that both are small); otherwise they call the `_slow` function of the same name (`tilrt/src/int.rs`), which returns a canonical result. Addition, subtraction and multiplication never unwind, so generated code has no yield check after them; division and remainder still panic on zero. `tl_int_overflow` is gone. |
| 306 | +- `tl_int_show` and `tl_hash_int` take big integers too. |
| 307 | +- **Runtime functions that take an `Int` as an index, a count, a size or a duration** read a big integer as the nearest `i64` (saturating). |
| 308 | +- **C bindings:** `tl_int_get` reads small ints only. `tl_int_to_i64` reads any `Int` that fits in 64 bits, and `tl_int_from_i64` makes one (`tilcayo-ffi`: `int_i64`, `int_from_i64`). |
| 309 | + |
| 299 | 310 | **Not yet implemented:** |
| 300 | 311 | - accessors for `Bytes` in C bindings (`tl_bytes_ptr`, `tl_bytes_len`, `tl_bytes_from`). |
| 301 | 312 | |