@ac-kit/test-util 0.3.1 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/CHANGELOG.md +109 -0
  2. package/README.md +159 -1
  3. package/dist/exact-dot.d.ts +87 -0
  4. package/dist/exact-dot.d.ts.map +1 -0
  5. package/dist/exact-dot.js +237 -0
  6. package/dist/exact-dot.js.map +1 -0
  7. package/dist/expect-alias-safe.d.ts +31 -0
  8. package/dist/expect-alias-safe.d.ts.map +1 -0
  9. package/dist/expect-alias-safe.js +80 -0
  10. package/dist/expect-alias-safe.js.map +1 -0
  11. package/dist/fake-wall-clock.d.ts.map +1 -1
  12. package/dist/fake-wall-clock.js +2 -2
  13. package/dist/fake-wall-clock.js.map +1 -1
  14. package/dist/index.d.ts +3 -0
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +3 -0
  17. package/dist/index.js.map +1 -1
  18. package/dist/out-first-case.d.ts +116 -0
  19. package/dist/out-first-case.d.ts.map +1 -0
  20. package/dist/out-first-case.js +113 -0
  21. package/dist/out-first-case.js.map +1 -0
  22. package/dist/v8/_collect.d.ts +25 -0
  23. package/dist/v8/_collect.d.ts.map +1 -0
  24. package/dist/v8/_collect.js +94 -0
  25. package/dist/v8/_collect.js.map +1 -0
  26. package/dist/v8/allocated-bytes.d.ts +97 -0
  27. package/dist/v8/allocated-bytes.d.ts.map +1 -0
  28. package/dist/v8/allocated-bytes.js +148 -0
  29. package/dist/v8/allocated-bytes.js.map +1 -0
  30. package/dist/v8/allocation-sites.d.ts +92 -0
  31. package/dist/v8/allocation-sites.d.ts.map +1 -0
  32. package/dist/v8/allocation-sites.js +131 -0
  33. package/dist/v8/allocation-sites.js.map +1 -0
  34. package/dist/v8/elements-kind.d.ts +50 -0
  35. package/dist/v8/elements-kind.d.ts.map +1 -0
  36. package/dist/v8/elements-kind.js +81 -0
  37. package/dist/v8/elements-kind.js.map +1 -0
  38. package/dist/v8/index.d.ts +4 -0
  39. package/dist/v8/index.d.ts.map +1 -0
  40. package/dist/v8/index.js +4 -0
  41. package/dist/v8/index.js.map +1 -0
  42. package/package.json +17 -6
@@ -0,0 +1,80 @@
1
+ import { expect } from "vitest";
2
+ function describePlacement_(placement) {
3
+ const where = placement.out === "fresh"
4
+ ? "a fresh out"
5
+ : `out aliased to argument ${placement.out}`;
6
+ return placement.share ? `${where}, every aliasable input one array` : where;
7
+ }
8
+ function show_(value) {
9
+ return Object.is(value, -0) ? "-0" : String(value);
10
+ }
11
+ function expectSameNumbers_(label, actual, expected) {
12
+ expect(actual).toHaveLength(expected.length);
13
+ for (let index = 0; index < expected.length; index++) {
14
+ if (!Object.is(actual[index], expected[index])) {
15
+ expect.fail(`${label}: out[${index}] is ${show_(actual[index])}, a separate out gives ${show_(expected[index])}`);
16
+ }
17
+ }
18
+ }
19
+ function expectReturn_(testCase, label, run, separate) {
20
+ if (testCase.returns === "out") {
21
+ expect(run.returned === run.out, `${label}: must return out itself`).toBe(true);
22
+ }
23
+ else {
24
+ expect(Object.is(run.returned, separate.returned), `${label}: returned ${show_(run.returned)}, a separate out gives ${show_(separate.returned)}`).toBe(true);
25
+ }
26
+ }
27
+ /**
28
+ * Asserts the alias rule of a function that writes into a first `out`:
29
+ * whichever input `out` is, and even when every input of its type is the same
30
+ * array, the result is the one a separate `out` gives, bit for bit, and the
31
+ * function returns `out` (or, for a case declared `returns: "value"`, the same
32
+ * value as with a separate `out`).
33
+ *
34
+ * It runs the case (see {@link defineOutFirstCase}) with:
35
+ *
36
+ * 1. A fresh `out`;
37
+ * 2. `out` set to each aliasable argument in turn;
38
+ * 3. When two or more arguments are aliasable, every one of them set to the same
39
+ * array, with `out` that array, against the same inputs with a fresh `out`.
40
+ *
41
+ * Every comparison uses `Object.is` per element, so `NaN` and `-0` count. A
42
+ * failure names the case, the placement and the first element that differs.
43
+ *
44
+ * Time complexity: 1 + k calls of the function, plus 2 more when k ≥ 2, each
45
+ * with an O(length) comparison, where k is the number of aliasable arguments.
46
+ *
47
+ * @example
48
+ * expectAliasSafe(vec2AddCase, samplerOf([1, 2, 3, 4]));
49
+ *
50
+ * @param testCase - The function's case.
51
+ * @param sampler - The numbers its arguments are built from; every run starts
52
+ * it again.
53
+ * @throws {AssertionError} On the first placement that differs.
54
+ */
55
+ export function expectAliasSafe(testCase, sampler) {
56
+ const fresh = { out: "fresh", share: false };
57
+ const separate = testCase.run(fresh, sampler);
58
+ expectReturn_(testCase, `${testCase.name}, ${describePlacement_(fresh)}`, separate, separate);
59
+ for (const index of testCase.aliasable) {
60
+ const placement = { out: index, share: false };
61
+ const label = `${testCase.name}, ${describePlacement_(placement)}`;
62
+ const aliased = testCase.run(placement, sampler);
63
+ expectReturn_(testCase, label, aliased, separate);
64
+ expectSameNumbers_(label, aliased.out, separate.out);
65
+ }
66
+ if (testCase.aliasable.length >= 2) {
67
+ const sharedFresh = { out: "fresh", share: true };
68
+ const sharedInPlace = {
69
+ out: testCase.aliasable[0],
70
+ share: true,
71
+ };
72
+ const label = `${testCase.name}, ${describePlacement_(sharedInPlace)}`;
73
+ const expected = testCase.run(sharedFresh, sampler);
74
+ const inPlace = testCase.run(sharedInPlace, sampler);
75
+ expectReturn_(testCase, `${testCase.name}, ${describePlacement_(sharedFresh)}`, expected, expected);
76
+ expectReturn_(testCase, label, inPlace, expected);
77
+ expectSameNumbers_(label, inPlace.out, expected.out);
78
+ }
79
+ }
80
+ //# sourceMappingURL=expect-alias-safe.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"expect-alias-safe.js","sourceRoot":"","sources":["../src/expect-alias-safe.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAShC,SAAS,kBAAkB,CAAC,SAAuB;IAClD,MAAM,KAAK,GACV,SAAS,CAAC,GAAG,KAAK,OAAO;QACxB,CAAC,CAAC,aAAa;QACf,CAAC,CAAC,2BAA2B,SAAS,CAAC,GAAG,EAAE,CAA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wall-clock.d.ts","sourceRoot":"","sources":["../src/fake-wall-clock.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,KAAK,aAAa,EAGlB,MAAM,cAAc,CAAC;AAgBtB;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,aAAa;IACzB,OAAO,CAAC,YAAY,CAAS;IAE7B;;;OAGG;IACH,QAAQ,CAAC,OAAO,EAAE,aAAa,CAC4B;IAE3D;;;;;OAKG;IACH,YAAY,KAAK,SAAI,EAIpB;IAED,6DAA6D;IAC7D,IAAI,iBAAiB,IAAI,MAAM,CAE9B;IAED;;;;;OAKG;IACH,GAAG,CAAC,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAInC;IAED;;;;;;OAMG;IACH,OAAO,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,CAQlC;CACD"}
@@ -1,7 +1,7 @@
1
- import { isIntegerInRange, MAX_INSTANT_EPOCH_MILLISECONDS, } from "@ac-kit/core";
1
+ import { describeValue, isIntegerInRange, MAX_INSTANT_EPOCH_MILLISECONDS, } from "@ac-kit/core";
2
2
  function assertEpochMilliseconds_(name, milliseconds) {
3
3
  if (!isIntegerInRange(milliseconds, -MAX_INSTANT_EPOCH_MILLISECONDS, MAX_INSTANT_EPOCH_MILLISECONDS + 1)) {
4
- throw new RangeError(`FakeWallClock: ${name} ${String(milliseconds)} is not an integer number of milliseconds a Temporal.Instant can hold`);
4
+ throw new RangeError(`FakeWallClock: ${name} ${describeValue(milliseconds)} is not an integer number of milliseconds a Temporal.Instant can hold`);
5
5
  }
6
6
  }
7
7
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"fake-wall-clock.js","sourceRoot":"","sources":["../src/fake-wall-clock.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,gBAAgB,EAChB,8BAA8B,GAC9B,MAAM,cAAc,CAAC;AAEtB,SAAS,wBAAwB,CAAC,IAAY,EAAE,YAAoB;IACnE,IACC,CAAC,gBAAgB,CAChB,YAAY,EACZ,CAAC,8BAA8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C,gBAAgB,CAChB,YAAY,EACZ,CAAC,8BAA8B,EAC/B,8BAA8B,GAAG,CAAC,CAClC,EACA,CAAC;QACF,MAAM,IAAI,UAAU,CACnB,kBAAkB,IAAI,IAAI,aAAa,CAAC,YAAY,CAAC,uEAAuE,CAC5H,CAAC;IACH,CAAC;AACF,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,OAAO,aAAa;IACjB,YAAY,CAAS;IAE7B;;;OAGG;IACM,OAAO,GAAkB,GAAG,EAAE,CACtC,QAAQ,CAAC,OAAO,CAAC,qBAAqB,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IAE3D;;;;;OAKG;IACH,YAAY,KAAK,GAAG,CAAC;QACpB,wBAAwB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QAEzC,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC;IAC3B,CAAC;IAED,6DAA6D;IAC7D,IAAI,iBAAiB;QACpB,OAAO,IAAI,CAAC,YAAY,CAAC;IAC1B,CAAC;IAED;;;;;OAKG;IACH,GAAG,CAAC,iBAAyB;QAC5B,wBAAwB,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;QAEpD,IAAI,CAAC,YAAY,GAAG,iBAAiB,CAAC;IACvC,CAAC;IAED;;;;;;OAMG;IACH,OAAO,CAAC,YAAoB;QAC3B,wBAAwB,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;QAE/C,MAAM,MAAM,GAAG,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QAEhD,wBAAwB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAEzC,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC;IAC5B,CAAC;CACD"}
package/dist/index.d.ts CHANGED
@@ -1,6 +1,9 @@
1
1
  export * from "./busy-wait.js";
2
+ export * from "./exact-dot.js";
3
+ export * from "./expect-alias-safe.js";
2
4
  export * from "./expect-close-relative.js";
3
5
  export * from "./expect-compare-agrees-with-equals.js";
4
6
  export * from "./fake-clock.js";
5
7
  export * from "./fake-wall-clock.js";
8
+ export * from "./out-first-case.js";
6
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,wCAAwC,CAAC;AACvD,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,wCAAwC,CAAC;AACvD,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC"}
package/dist/index.js CHANGED
@@ -1,6 +1,9 @@
1
1
  export * from "./busy-wait.js";
2
+ export * from "./exact-dot.js";
3
+ export * from "./expect-alias-safe.js";
2
4
  export * from "./expect-close-relative.js";
3
5
  export * from "./expect-compare-agrees-with-equals.js";
4
6
  export * from "./fake-clock.js";
5
7
  export * from "./fake-wall-clock.js";
8
+ export * from "./out-first-case.js";
6
9
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,wCAAwC,CAAC;AACvD,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,wCAAwC,CAAC;AACvD,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC"}
@@ -0,0 +1,116 @@
1
+ import { type Callable, type CallableNoArgs } from "@ac-kit/core";
2
+ /**
3
+ * A source of numbers that starts again: each call returns a fresh `next`
4
+ * yielding the same sequence, so every run of a case builds the same inputs.
5
+ */
6
+ export type NumberSampler = CallableNoArgs<CallableNoArgs<number>>;
7
+ /**
8
+ * A sampler that replays `values` in order on every pass. A pass asking for
9
+ * more numbers than `values` holds throws a `RangeError`: the case needs more
10
+ * inputs than it was given.
11
+ *
12
+ * Time complexity: O(1) per number.
13
+ *
14
+ * @example
15
+ * const sampler = samplerOf([1, 2, 3]);
16
+ * const next = sampler();
17
+ * next(); // 1
18
+ * sampler()(); // 1 again, from a fresh pass
19
+ *
20
+ * @param values - The numbers of one pass.
21
+ * @returns A sampler whose every pass yields `values`.
22
+ */
23
+ export declare function samplerOf(values: readonly number[]): NumberSampler;
24
+ /** What a function with an `out` first argument is run with. */
25
+ export interface OutFirstCaseDefinition<TOut extends ArrayLike<number>, TArgs extends readonly unknown[]> {
26
+ readonly name: string;
27
+ /**
28
+ * A fresh `out`, made by the value's own creator (never a literal or another
29
+ * container).
30
+ */
31
+ readonly create: CallableNoArgs<TOut>;
32
+ /**
33
+ * Indexes into the arguments of the inputs of `out`'s type: those `out` may
34
+ * be.
35
+ */
36
+ readonly aliasable: readonly number[];
37
+ /**
38
+ * The arguments after `out`, built from `next`; the same numbers must give
39
+ * equal arguments.
40
+ */
41
+ readonly makeArguments: Callable<[next: CallableNoArgs<number>], TArgs>;
42
+ readonly call: Callable<[out: TOut, args: TArgs], unknown>;
43
+ /**
44
+ * `"out"` (the default): the call returns `out`. `"value"`: it returns
45
+ * something else — a success flag, nothing — which must not depend on where
46
+ * `out` is.
47
+ */
48
+ readonly returns?: "out" | "value";
49
+ }
50
+ /** Where the `out` of a run comes from, and whether the inputs are one array. */
51
+ export interface OutPlacement {
52
+ /** `"fresh"`, or the index of the argument used as `out`. */
53
+ readonly out: "fresh" | number;
54
+ /** Every aliasable argument is the same array, the first one's. */
55
+ readonly share: boolean;
56
+ }
57
+ /** What one run of a case produced. */
58
+ export interface OutFirstRun {
59
+ readonly out: ArrayLike<number>;
60
+ readonly returned: unknown;
61
+ }
62
+ /** One out-first function with a generator of inputs, ready to be run. */
63
+ export interface OutFirstCase {
64
+ readonly name: string;
65
+ readonly aliasable: readonly number[];
66
+ readonly returns: "out" | "value";
67
+ /**
68
+ * Builds the arguments from `sampler`, places `out` and calls the function.
69
+ *
70
+ * @throws {RangeError} When an aliasable index is past the arguments, or
71
+ * `placement.out` is neither `"fresh"` nor an aliasable index.
72
+ * @throws {TypeError} When the argument at an aliasable index has a `length`
73
+ * different from `out`'s.
74
+ */
75
+ readonly run: Callable<[
76
+ placement: OutPlacement,
77
+ sampler: NumberSampler
78
+ ], OutFirstRun>;
79
+ }
80
+ /**
81
+ * Describes a function that writes its result into a first `out` argument, for
82
+ * {@link expectAliasSafe}: how to build an `out`, which of the other arguments
83
+ * are of the same type (so `out` may be one of them), how to build the
84
+ * arguments from numbers and how to call it.
85
+ *
86
+ * A package keeps the table of its own functions — which take `out` first and
87
+ * which positions may alias — and hands each case to {@link expectAliasSafe}.
88
+ * Cases also serve other checks over the same table: `run` is the building
89
+ * block, and `aliasable` lists the positions.
90
+ *
91
+ * The harness never builds a value it passes to the function under test:
92
+ * `create` and `makeArguments` do, so a branded vector is always made by its
93
+ * own creator. It covers bulk kernels too — a `Float64Array` `out`, in place.
94
+ *
95
+ * Time complexity: O(1) to define; each `run` costs one call plus building the
96
+ * arguments.
97
+ *
98
+ * @example
99
+ * const testCase = defineOutFirstCase({
100
+ * name: "vec2Add",
101
+ * create: () => vec2Create(),
102
+ * aliasable: [0, 1],
103
+ * makeArguments: (next) => [
104
+ * vec2Of(next(), next()),
105
+ * vec2Of(next(), next()),
106
+ * ],
107
+ * call: (out, [a, b]) => vec2Add(out, a, b),
108
+ * });
109
+ *
110
+ * @param definition - The function's table entry.
111
+ * @returns The case.
112
+ * @throws {RangeError} When an aliasable index is negative, fractional or
113
+ * repeated.
114
+ */
115
+ export declare function defineOutFirstCase<TOut extends ArrayLike<number>, const TArgs extends readonly unknown[]>(definition: OutFirstCaseDefinition<TOut, TArgs>): OutFirstCase;
116
+ //# sourceMappingURL=out-first-case.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"out-first-case.d.ts","sourceRoot":"","sources":["../src/out-first-case.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,KAAK,QAAQ,EACb,KAAK,cAAc,EACnB,MAAM,cAAc,CAAC;AAEtB;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG,cAAc,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC;AAEnE;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,aAAa,CAiBlE;AAED,gEAAgE;AAChE,MAAM,WAAW,sBAAsB,CACtC,IAAI,SAAS,SAAS,CAAC,MAAM,CAAC,EAC9B,KAAK,SAAS,SAAS,OAAO,EAAE;IAEhC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC,IAAI,CAAC,CAAC;IACtC;;;OAGG;IACH,QAAQ,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,CAAC;IACtC;;;OAGG;IACH,QAAQ,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAC,IAAI,EAAE,cAAc,CAAC,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IACxE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,EAAE,OAAO,CAAC,CAAC;IAC3D;;;;OAIG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,KAAK,GAAG,OAAO,CAAC;CACnC;AAED,iFAAiF;AACjF,MAAM,WAAW,YAAY;IAC5B,6DAA6D;IAC7D,QAAQ,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAAC;IAC/B,mEAAmE;IACnE,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CACxB;AAED,uCAAuC;AACvC,MAAM,WAAW,WAAW;IAC3B,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;IAChC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;CAC3B;AAED,0EAA0E;AAC1E,MAAM,WAAW,YAAY;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,CAAC;IACtC,QAAQ,CAAC,OAAO,EAAE,KAAK,GAAG,OAAO,CAAC;IAClC;;;;;;;OAOG;IACH,QAAQ,CAAC,GAAG,EAAE,QAAQ,CACrB;QAAC,SAAS,EAAE,YAAY;QAAE,OAAO,EAAE,aAAa;KAAC,EACjD,WAAW,CACX,CAAC;CACF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAgB,kBAAkB,CACjC,IAAI,SAAS,SAAS,CAAC,MAAM,CAAC,EAC9B,KAAK,CAAC,KAAK,SAAS,SAAS,OAAO,EAAE,EACrC,UAAU,EAAE,sBAAsB,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,YAAY,CAsE/D"}
@@ -0,0 +1,113 @@
1
+ import { describeValue, } from "@ac-kit/core";
2
+ /**
3
+ * A sampler that replays `values` in order on every pass. A pass asking for
4
+ * more numbers than `values` holds throws a `RangeError`: the case needs more
5
+ * inputs than it was given.
6
+ *
7
+ * Time complexity: O(1) per number.
8
+ *
9
+ * @example
10
+ * const sampler = samplerOf([1, 2, 3]);
11
+ * const next = sampler();
12
+ * next(); // 1
13
+ * sampler()(); // 1 again, from a fresh pass
14
+ *
15
+ * @param values - The numbers of one pass.
16
+ * @returns A sampler whose every pass yields `values`.
17
+ */
18
+ export function samplerOf(values) {
19
+ // A copy: later changes to the caller's array must not change a later pass.
20
+ const snapshot = Array.from(values);
21
+ return () => {
22
+ let index = 0;
23
+ return () => {
24
+ if (index >= snapshot.length) {
25
+ throw new RangeError(`samplerOf: a case asked for number ${index + 1}, but only ${snapshot.length} were given`);
26
+ }
27
+ return snapshot[index++];
28
+ };
29
+ };
30
+ }
31
+ /**
32
+ * Describes a function that writes its result into a first `out` argument, for
33
+ * {@link expectAliasSafe}: how to build an `out`, which of the other arguments
34
+ * are of the same type (so `out` may be one of them), how to build the
35
+ * arguments from numbers and how to call it.
36
+ *
37
+ * A package keeps the table of its own functions — which take `out` first and
38
+ * which positions may alias — and hands each case to {@link expectAliasSafe}.
39
+ * Cases also serve other checks over the same table: `run` is the building
40
+ * block, and `aliasable` lists the positions.
41
+ *
42
+ * The harness never builds a value it passes to the function under test:
43
+ * `create` and `makeArguments` do, so a branded vector is always made by its
44
+ * own creator. It covers bulk kernels too — a `Float64Array` `out`, in place.
45
+ *
46
+ * Time complexity: O(1) to define; each `run` costs one call plus building the
47
+ * arguments.
48
+ *
49
+ * @example
50
+ * const testCase = defineOutFirstCase({
51
+ * name: "vec2Add",
52
+ * create: () => vec2Create(),
53
+ * aliasable: [0, 1],
54
+ * makeArguments: (next) => [
55
+ * vec2Of(next(), next()),
56
+ * vec2Of(next(), next()),
57
+ * ],
58
+ * call: (out, [a, b]) => vec2Add(out, a, b),
59
+ * });
60
+ *
61
+ * @param definition - The function's table entry.
62
+ * @returns The case.
63
+ * @throws {RangeError} When an aliasable index is negative, fractional or
64
+ * repeated.
65
+ */
66
+ export function defineOutFirstCase(definition) {
67
+ const { name, create, makeArguments, call } = definition;
68
+ const aliasable = [...definition.aliasable];
69
+ const returns = definition.returns ?? "out";
70
+ const seen = new Set();
71
+ for (const index of aliasable) {
72
+ if (!Number.isInteger(index) || index < 0 || seen.has(index)) {
73
+ throw new RangeError(`${name}: aliasable must be distinct non-negative integers, got ${describeValue(index)}`);
74
+ }
75
+ seen.add(index);
76
+ }
77
+ return {
78
+ name,
79
+ aliasable,
80
+ returns,
81
+ run(placement, sampler) {
82
+ const built = makeArguments(sampler());
83
+ for (const index of aliasable) {
84
+ if (index >= built.length) {
85
+ throw new RangeError(`${name}: aliasable index ${index} is past the ${built.length} arguments`);
86
+ }
87
+ }
88
+ if (placement.out !== "fresh" && !aliasable.includes(placement.out)) {
89
+ throw new RangeError(`${name}: out must be "fresh" or an aliasable index, got ${describeValue(placement.out)}`);
90
+ }
91
+ // The lengths are those of the arguments as built, before any sharing
92
+ // hides a difference between them.
93
+ const target = placement.out === "fresh" ? create() : built[placement.out];
94
+ for (const index of aliasable) {
95
+ const { length } = built[index];
96
+ if (length !== target.length) {
97
+ throw new TypeError(`${name}: argument ${index} has length ${length}, out has ${target.length}`);
98
+ }
99
+ }
100
+ let args = built;
101
+ if (placement.share && aliasable.length > 1) {
102
+ const shared = [...built];
103
+ for (const index of aliasable) {
104
+ shared[index] = built[aliasable[0]];
105
+ }
106
+ args = shared; // shared is a copy of the argument tuple with the aliased slots pointing at one value
107
+ }
108
+ const out = placement.out === "fresh" ? target : args[placement.out];
109
+ return { out, returned: call(out, args) };
110
+ },
111
+ };
112
+ }
113
+ //# sourceMappingURL=out-first-case.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"out-first-case.js","sourceRoot":"","sources":["../src/out-first-case.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,aAAa,GAGb,MAAM,cAAc,CAAC;AAQtB;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,SAAS,CAAC,MAAyB;IAClD,4EAA4E;IAC5E,MAAM,QAAQ,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAEpC,OAAO,GAAG,EAAE;QACX,IAAI,KAAK,GAAG,CAAC,CAAC;QAEd,OAAO,GAAG,EAAE;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KAAK,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAE,IAAI,CAAC,SAAS,CAAC,GAAG,CAAU,CAAC;YAEpE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,CAAC;QAC3C,CAAC;KACD,CAAC;AACH,CAAC"}
@@ -0,0 +1,25 @@
1
+ import v8 from "node:v8";
2
+ /**
3
+ * Two full collections. The first frees the garbage; its sweeping, left to
4
+ * background threads and to later allocations, still lowers the heap's used
5
+ * size after it returns, so a window opened then would read less than it
6
+ * allocated. The second finishes that sweeping before it starts and finds next
7
+ * to nothing to free, so what its own sweeping leaves is about nothing.
8
+ */
9
+ export declare function collect_(): void;
10
+ /** Used bytes of the spaces objects live in, now. */
11
+ export declare function objectHeapUsed_(): number;
12
+ /** What the collections inside one window freed. */
13
+ export type WindowCollections_ = {
14
+ /** Bytes of the spaces objects live in. */
15
+ readonly heapFreed: number;
16
+ /** External bytes: `ArrayBuffer` backing stores and the embedder's. */
17
+ readonly externalFreed: number;
18
+ /**
19
+ * Whether one of them sweeps after it ends, so `heapFreed` may fall short of
20
+ * what it freed.
21
+ */
22
+ readonly sweptAfter: boolean;
23
+ };
24
+ export declare function windowCollections_(profile: v8.GCProfilerResult): WindowCollections_;
25
+ //# sourceMappingURL=_collect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_collect.d.ts","sourceRoot":"","sources":["../../src/v8/_collect.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,SAAS,CAAC;AA4BzB;;;;;;GAMG;AACH,wBAAgB,QAAQ,IAAI,IAAI,CAI/B;AAkBD,qDAAqD;AACrD,wBAAgB,eAAe,IAAI,MAAM,CAUxC;AAwBD,oDAAoD;AACpD,MAAM,MAAM,kBAAkB,GAAG;IAChC,2CAA2C;IAC3C,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,uEAAuE;IACvE,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B;;;OAGG;IACH,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;CAC7B,CAAC;AAEF,wBAAgB,kBAAkB,CACjC,OAAO,EAAE,EAAE,CAAC,gBAAgB,GAC1B,kBAAkB,CAiBpB"}
@@ -0,0 +1,94 @@
1
+ /// <reference types="node" />
2
+ import v8 from "node:v8";
3
+ import vm from "node:vm";
4
+ let gc_;
5
+ /**
6
+ * Prepares the process for counting: exposes `gc`, and makes V8 free the
7
+ * backing stores of dead `ArrayBuffer`s inside the collection that found them
8
+ * dead (`--no-concurrent-array-buffer-sweeping`), so what a collection frees is
9
+ * visible in its own before and after statistics rather than later, on a
10
+ * background thread, outside any collection. Both flags stay set for the rest
11
+ * of the process: V8 cannot report a flag's previous value to restore it.
12
+ */
13
+ function prepare_() {
14
+ v8.setFlagsFromString("--no-concurrent-array-buffer-sweeping");
15
+ const exposed = globalThis.gc;
16
+ if (typeof exposed === "function") {
17
+ return exposed;
18
+ }
19
+ // The flag only adds `gc` to contexts created after it is set.
20
+ v8.setFlagsFromString("--expose-gc");
21
+ return vm.runInNewContext("gc");
22
+ }
23
+ /**
24
+ * Two full collections. The first frees the garbage; its sweeping, left to
25
+ * background threads and to later allocations, still lowers the heap's used
26
+ * size after it returns, so a window opened then would read less than it
27
+ * allocated. The second finishes that sweeping before it starts and finds next
28
+ * to nothing to free, so what its own sweeping leaves is about nothing.
29
+ */
30
+ export function collect_() {
31
+ gc_ ??= prepare_();
32
+ gc_();
33
+ gc_();
34
+ }
35
+ /**
36
+ * Spaces where V8 keeps what it compiles — machine code, bytecode, feedback
37
+ * metadata — and the read-only snapshot, rather than the objects a program
38
+ * allocates. What they gain or lose in a window is the engine tiering code up
39
+ * or sweeping code it collected, not an allocation of the code under test.
40
+ */
41
+ const CODE_SPACES_ = new Set([
42
+ "read_only_space",
43
+ "code_space",
44
+ "code_large_object_space",
45
+ "trusted_space",
46
+ "trusted_large_object_space",
47
+ "shared_trusted_space",
48
+ "shared_trusted_large_object_space",
49
+ ]);
50
+ /** Used bytes of the spaces objects live in, now. */
51
+ export function objectHeapUsed_() {
52
+ let used = 0;
53
+ for (const space of v8.getHeapSpaceStatistics()) {
54
+ if (!CODE_SPACES_.has(space.space_name)) {
55
+ used += space.space_used_size;
56
+ }
57
+ }
58
+ return used;
59
+ }
60
+ function objectSpacesUsed_(spaces) {
61
+ let used = 0;
62
+ for (const space of spaces) {
63
+ if (!CODE_SPACES_.has(space.spaceName)) {
64
+ used += space.spaceUsedSize;
65
+ }
66
+ }
67
+ return used;
68
+ }
69
+ /**
70
+ * Collection kinds after which sweeping goes on outside the collection: the
71
+ * heap's used size keeps dropping after them, by garbage their statistics do
72
+ * not show as freed.
73
+ */
74
+ const SWEEPING_COLLECTIONS_ = new Set([
75
+ "MarkSweepCompact",
76
+ "MinorMarkSweep",
77
+ ]);
78
+ export function windowCollections_(profile) {
79
+ let heapFreed = 0;
80
+ let externalFreed = 0;
81
+ let sweptAfter = false;
82
+ for (const collection of profile.statistics) {
83
+ const { beforeGC, afterGC } = collection;
84
+ heapFreed +=
85
+ objectSpacesUsed_(beforeGC.heapSpaceStatistics) -
86
+ objectSpacesUsed_(afterGC.heapSpaceStatistics);
87
+ externalFreed +=
88
+ beforeGC.heapStatistics.externalMemory -
89
+ afterGC.heapStatistics.externalMemory;
90
+ sweptAfter ||= SWEEPING_COLLECTIONS_.has(collection.gcType);
91
+ }
92
+ return { heapFreed, externalFreed, sweptAfter };
93
+ }
94
+ //# sourceMappingURL=_collect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_collect.js","sourceRoot":"","sources":["../../src/v8/_collect.ts"],"names":[],"mappings":"AAAA,8BAA8B;AAC9B,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,MAAM,SAAS,CAAC;AAIzB,IAAI,GAA+B,CAAC;AAEpC;;;;;;;GAOG;AACH,SAAS,QAAQ;IAChB,EAAE,CAAC,kBAAkB,CAAC,uCAAu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M,qBAAqB,GAAwB,IAAI,GAAG,CAAC;IAC1D,kBAAkB;IAClB,gBAAgB;CAChB,CAAC,CAAC;AAeH,MAAM,UAAU,kBAAkB,CACjC,OAA4B;IAE5B,IAAI,SAAS,GAAG,CAAC,CAAC;IAClB,IAAI,aAAa,GAAG,CAAC,CAAC;IACtB,IAAI,UAAU,GAAG,KAAK,CAAC;IAEvB,KAAK,MAAM,UAAU,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;QAC7C,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,UAAU,CAAC;QACzC,SAAS;YACR,iBAAiB,CAAC,QAAQ,CAAC,mBAAmB,CAAC;gBAC/C,iBAAiB,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC;QAChD,aAAa;YACZ,QAAQ,CAAC,cAAc,CAAC,cAAc;gBACtC,OAAO,CAAC,cAAc,CAAC,cAAc,CAAC;QACvC,UAAU,KAAK,qBAAqB,CAAC,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;IAC7D,CAAC;IAED,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,UAAU,EAAE,CAAC;AACjD,CAAC"}
@@ -0,0 +1,97 @@
1
+ import { type CallableNoArgs } from "@ac-kit/core";
2
+ export type AllocatedBytesOptions = {
3
+ /**
4
+ * Calls made before measuring, so the engine has optimised `body` and every
5
+ * buffer it grows has reached its working size. Default 10 000; an integer ≥ 0.
6
+ */
7
+ readonly warmUpCalls?: number;
8
+ /** Calls per measured window. Default 10 000; an integer ≥ 1. */
9
+ readonly calls?: number;
10
+ /**
11
+ * Measured windows; the least is kept, so a window in which the engine was
12
+ * still compiling `body` (code and feedback live in the heap too) does not
13
+ * count. Default 5; an integer ≥ 1.
14
+ */
15
+ readonly windows?: number;
16
+ };
17
+ /** What {@link allocatedMemoryPerCall} found: mean bytes per call, by kind. */
18
+ export type AllocatedMemory = {
19
+ /** `heapBytes + externalBytes`. */
20
+ readonly bytes: number;
21
+ /**
22
+ * JavaScript heap bytes: every object, array, closure, string, boxed number
23
+ * and elements store, a typed array's own object and an on-heap backing store
24
+ * (64 bytes or fewer) included, and what the engine allocates on the heap
25
+ * outside any JavaScript function; not the compiled code, bytecode and
26
+ * feedback metadata of the engine's code spaces.
27
+ */
28
+ readonly heapBytes: number;
29
+ /**
30
+ * Off-heap bytes V8 accounts as external: the backing stores of the
31
+ * `ArrayBuffer`s and `SharedArrayBuffer`s allocated (those of typed arrays
32
+ * and `DataView`s over more than 64 bytes, `Buffer`s), and memory the
33
+ * embedder reports to V8 as external.
34
+ */
35
+ readonly externalBytes: number;
36
+ };
37
+ /**
38
+ * Mean bytes one call of `body` allocates once warmed up, on the JavaScript
39
+ * heap and off it, for asserting that a hot path allocates nothing and, when it
40
+ * does, telling objects from buffers.
41
+ *
42
+ * Each window starts from two full collections and runs `calls` calls of `body`
43
+ * under `v8.GCProfiler`:
44
+ *
45
+ * - `heapBytes` is the growth of the spaces objects live in (new, old and
46
+ * large-object spaces) plus what every collection inside the window freed of
47
+ * them, so garbage is counted to the byte. The spaces of compiled code,
48
+ * bytecode and feedback metadata are left out: what they gain or lose in a
49
+ * window is the engine tiering code up, or sweeping code it collected, not
50
+ * what `body` allocates. A mark-compact collection goes on sweeping after it
51
+ * ends, freeing garbage its statistics do not show, so a window one ran in is
52
+ * measured again with half the calls, down to one call; a body that runs one
53
+ * in a single call reads low by what it swept. The measurement's own cost,
54
+ * the median of empty windows, is removed, and so are 256 bytes a window,
55
+ * what the engine's feedback and inline-cache updates around the loop add to
56
+ * it whatever the number of calls: a body that allocates nothing reads 0, and
57
+ * one that allocates reads at most `256 / calls` bytes low.
58
+ * - `externalBytes` is the growth of V8's external memory plus what every
59
+ * collection inside the window freed of it: each `ArrayBuffer` backing store
60
+ * counts once, at its byte length, when it is allocated, collected in the
61
+ * window or not. V8 is set to free dead backing stores inside the collection
62
+ * that finds them (`--no-concurrent-array-buffer-sweeping`) so that a
63
+ * collection's statistics show what it freed. A body that allocates no buffer
64
+ * reads 0; memory the embedder releases outside a collection (a native
65
+ * resource closed in `body`) offsets what `body` allocates, and the figure is
66
+ * then a lower bound.
67
+ *
68
+ * A backing store of 64 bytes or fewer lives on the heap, in `heapBytes`. The
69
+ * least of `windows` windows by `bytes` is kept, so the figure is the steady
70
+ * state rather than the engine still compiling. Never negative.
71
+ *
72
+ * What it shows is the engine's behaviour on this run: a body the engine has
73
+ * not optimised, or whose callers' inlining budget differs, may allocate where
74
+ * it otherwise would not (a double crossing a call that is not inlined is
75
+ * boxed). Warm it up as the code under test is warmed up in use.
76
+ *
77
+ * Node only (`node:v8`). Exposes `gc` to new contexts when the process was
78
+ * started without `--expose-gc`, and leaves array-buffer sweeping synchronous
79
+ * for the rest of the process. Runs `warmUpCalls + windows · calls` calls of
80
+ * `body`, more when sweeping collections run in a window.
81
+ *
82
+ * @throws {RangeError} `warmUpCalls` not an integer ≥ 0, `calls` or `windows`
83
+ * not an integer ≥ 1.
84
+ */
85
+ export declare function allocatedMemoryPerCall(body: CallableNoArgs, options?: AllocatedBytesOptions): AllocatedMemory;
86
+ /**
87
+ * Mean bytes one call of `body` allocates once warmed up, on the JavaScript
88
+ * heap and off it (`ArrayBuffer` backing stores included), for asserting that a
89
+ * hot path allocates nothing: the `bytes` of {@link allocatedMemoryPerCall},
90
+ * which tells the two apart and documents what is counted. A body that
91
+ * allocates nothing reads 0.
92
+ *
93
+ * @throws {RangeError} `warmUpCalls` not an integer ≥ 0, `calls` or `windows`
94
+ * not an integer ≥ 1.
95
+ */
96
+ export declare function allocatedBytesPerCall(body: CallableNoArgs, options?: AllocatedBytesOptions): number;
97
+ //# sourceMappingURL=allocated-bytes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"allocated-bytes.d.ts","sourceRoot":"","sources":["../../src/v8/allocated-bytes.ts"],"names":[],"mappings":"AAGA,OAAO,EAAiB,KAAK,cAAc,EAAE,MAAM,cAAc,CAAC;AAIlE,MAAM,MAAM,qBAAqB,GAAG;IACnC;;;OAGG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,iEAAiE;IACjE,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB;;;;OAIG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF,+EAA+E;AAC/E,MAAM,MAAM,eAAe,GAAG;IAC7B,mCAAmC;IACnC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB;;;;;;OAMG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B;;;;;OAKG;IACH,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;CAC/B,CAAC;AAyHF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,wBAAgB,sBAAsB,CACrC,IAAI,EAAE,cAAc,EACpB,OAAO,GAAE,qBAA0B,GACjC,eAAe,CAEjB;AAED;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CACpC,IAAI,EAAE,cAAc,EACpB,OAAO,GAAE,qBAA0B,GACjC,MAAM,CAER"}