Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions packages/compiler/src/ir/int32-slots.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,52 @@ test("an Error subclass constructor forwarding dynamic arguments stores no class
expect(slots.isField("C", "a")).toBe(true);
});

test("Buffer.from over an ArrayBuffer range and Buffer as a value keep class fields int32", () => {
// `Buffer.from(view.buffer, offset, length)` passes its operands as
// checked values, and a program that reads the Buffer function's value
// installs it in %main; neither stores into a class instance.
const classes = [cls("C", ["a"])];
const view: IrExpr = { loc, kind: "dynFrom", value: ref("o", obj("C")), type: DYN };
const libCall = (fnName: string, args: IrExpr[], type: IrType = VOID): IrStmt =>
stmt({ loc, kind: "libCall", fn: fnName, args, type } as IrExpr);
const slots = analyzeInt32Slots(
mod(classes, [
fn(
"load",
[
{ id: "o", type: obj("C") },
{ id: "storage", type: DYN },
],
[
set(ref("o", obj("C")), "C", "a", num(1)),
libCall("dyn.typedRefIs", [
view,
{ loc, kind: "strLit", value: "object:C", type: STRING },
]),
libCall("buffer.installValue", []),
libCall("buffer.constructor", [], DYN),
libCall(
"buffer.poolFromDynRange",
[ref("storage", DYN), num(2), num(4)].map((arg): IrExpr =>
arg.type.kind === "dyn" ? arg : { loc, kind: "dynFrom", value: arg, type: DYN },
),
),
libCall("buffer.poolFromDynOffset", [
ref("storage", DYN),
{
loc,
kind: "dynFrom",
value: num(2),
type: DYN,
},
]),
],
),
]),
);
expect(slots.isField("C", "a")).toBe(true);
});

test("captured bindings share one proof across the declaring function and its closures", () => {
const closure: IrExpr = { loc, kind: "closure", fnName: "inner", captures: ["s"], type: DYN };
const outer = (): IrFunction => ({
Expand Down
5 changes: 5 additions & 0 deletions packages/compiler/src/ir/int32-slots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,11 @@ const DYN_READ_ONLY = new Set<string>([
"fs.utimesSync",
// Buffer.prototype members read as values: a lookup by key.
"buffer.prototypeMember",
// Buffer.from(value, offset[, length]) over checked values: an
// ArrayBuffer's view after Node's offset and length conversions, or a copy
// of a string, array-like or typed array's values.
"buffer.poolFromDynOffset",
"buffer.poolFromDynRange",
"insp.dyn",
"insp.dynS",
// The dynamic-tier operators run their dyn twins (scr_js_value.c); the
Expand Down
Loading