Files
scriptc/tests/harness/large-artifacts.test.ts
T
Malte Ubl fa55ce6b07 Keep the RC entry points of array elements in one shared descriptor
Every SCR_ELEM_REF array stored its element type's retain, release and trace entry points in its own header (24 bytes), so ScrArr was 80 bytes: an 80-byte block for arrays of acyclic elements and a 96-byte block for cycle-capable ones. The three pointers now live in one constant ScrArrOps descriptor per element type, which the compiler emits once per module (@sc_arrops.*) and the runtime keeps static, and the header holds a pointer to it plus a 4-byte `cyc` flag beside `elem` that the inline RC fast paths test. ScrArr is 64 bytes: arrays take 64- and 80-byte blocks.

scr_arr_new_ref(retain, release, trace, cap) becomes scr_arr_new_ops(ops, cap); scr_set_to_arr_ref takes the result's descriptor from its caller instead of building an array from the set's key adapters. The backend names the %ScrArr fields in SCR_ARR_FIELD. The layout change bumps the runtime ABI marker to scr_runtime_abi_v13.
2026-10-11 19:46:48 -07:00

31 lines
1.3 KiB
TypeScript

import { expect, test } from "vitest";
import { occurrences, withoutFirstLine, withoutRange } from "./large-artifacts.js";
test("byte-level artifact edits match their string equivalents", () => {
const text =
"x declare void @scr_runtime_abi_v3()\ndeclare void @scr_runtime_abi_vX()\n" +
"declare void @scr_runtime_abi_v13()\n call void @scr_runtime_abi_v13()\n" +
"é\n call void @scr_runtime_abi_v13()\n";
const bytes = Buffer.from(text);
const declaration = /^declare void @scr_runtime_abi_v\d+\(\)\n/m;
const call = /^ {2}call void @scr_runtime_abi_v\d+\(\)\n/m;
const edited = withoutFirstLine(
withoutFirstLine(
bytes,
"declare void @scr_runtime_abi_v",
/^declare void @scr_runtime_abi_v\d+\(\)\n$/,
),
" call void @scr_runtime_abi_v",
/^ {2}call void @scr_runtime_abi_v\d+\(\)\n$/,
);
expect(edited.toString()).toBe(text.replace(declaration, "").replace(call, ""));
expect(withoutFirstLine(bytes, "missing", /^missing\n$/)).toBe(bytes);
const line = " call void @scr_runtime_abi_v13()\n";
const found = occurrences(bytes, line);
expect(found).toHaveLength(text.split(line).length - 1);
expect(withoutRange(bytes, found[0]!, Buffer.byteLength(line)).toString()).toBe(
text.replace(line, ""),
);
});