raz / commit b4f39282

commit
b4f39282fa38a884350dfe28a7f2390f90d2a9c8
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
9b4fd42f
PROPOSALS: Vec(T) for the standard library; sauce's cases for inlining

Vec as Buf for any T, not core, stopping when out of memory. Inlining
gains sauce's SHA-256 numbers (52 MB/s with ror and Str.be called,
115 written out, FPC 200), what the narrow rule does and doesn't cover
of them, and a rotate as the thaw's alternative. Nothing built.

patch · log

1 file changed, +48 -0

PROPOSALS.md modified +48 -0

@@ -82,6 +82,19 @@
8282 the budget; and, across modules, the imported module's
8383 text kept to be read again, which is to be checked.
8484
85+More cases, from sauce (`~/r/sauce`, RAZ-NOTES.md). Its SHA-256, with
86+the rotation a procedure, `return (x shr n) | (x shl (32 - n))`, and
87+each word read by `Str.be`, ran at 52 MB/s; with both written out in
88+the loop, 115 MB/s, where FPC `-O2` does about 200 and `check off`
89+adds only 9%. Most of the gap is calls. `ror` is the narrow case
90+above; `Str.be` is not, a loop over its bytes, and would want a
91+`Str.be32` of four bytes that only returns, or the loop unrolled where
92+it is. A rotate of the language's own, an operator or a built-in
93+procedure, would serve SHA, the other hashes and checksums without
94+any inlining, but it is a language change, for a thaw. On 100 MB of
95+new files `sauce commit` takes 1.2 s against the Pascal sauce's 0.7,
96+and `verify` 0.95 s against 0.48: the hashing.
97+
8598 ## A slice that outlives what it points at
8699
87100 ```
@@ -114,3 +127,38 @@
114127 checks the type of `return`'s expression.
115128
116129 Met in sauce's `Ssha.short`, which takes `var h: Hex` now.
130+
131+## `Vec(T)`, a growable array
132+
133+The library has `List`, linked, and `Map`, a hash; nothing that grows
134+in place and can be indexed. A program that keeps what it learns the
135+length of as it reads (lines, entries, changes) writes one: sauce's
136+`Svec`, 90 lines, imported four times. Every program of size will.
137+
138+A generic module of the standard library, not the core: like `List`
139+and `Map` it takes its memory from the allocator `init` gives it, and
140+a target with no heap to speak of may leave it out. It is `Buf` for
141+any `T`, and works as `Buf` does:
142+
143+```
144+module Vec(T);
145+type Vec* = record len*: INT; ... end;
146+proc init*(v: ^Vec; a: ^Mem.Allocator);
147+proc room*(v: ^Vec; n: INT): BOOL; (* room for n more; false if the allocator has none *)
148+proc push*(v: ^Vec; x: T); (* x added at the end *)
149+proc add*(v: ^Vec): ^T; (* a new element at the end, zero, to fill in place *)
150+proc resize*(v: ^Vec; n: INT); (* n elements, the new ones zero *)
151+proc all*(v: ^Vec): []T; (* the elements, until it next grows *)
152+proc reset*(v: ^Vec); (* emptied, its memory kept *)
153+proc done*(v: ^Vec); (* its memory given back *)
154+```
155+
156+`all` gives a slice, so that indexing is checked; `v.len` is its
157+length. `push`, `add` and `resize` stop the program when the
158+allocator has no room, as `Buf.add` does, rather than returning a
159+`BOOL` as `List.push` does: a `push` whose result is dropped loses an
160+element silently, and an array is pushed to far more often than a
161+list. `room` asks first. No `pop`, `insert` or `remove` until a
162+program needs one: `v.len := v.len - 1` and `Sort` cover most.
163+
164+A new module breaks no program, so it can come with any release.