From 0ec35296184c0629993ced7b01205d3de19f4c09 Mon Sep 17 00:00:00 2001 From: "g. nicholas d'andrea" Date: Tue, 10 Nov 2026 19:06:48 -0500 Subject: [PATCH 1/8] format: add virtual regions for computed values --- .../format/src/types/pointer/pointer.test.ts | 4 + packages/format/src/types/pointer/pointer.ts | 22 +++- packages/pointers/src/cursor.ts | 5 +- .../pointers/src/dereference/index.test.ts | 104 ++++++++++++++++++ packages/pointers/src/dereference/region.ts | 51 ++++++++- packages/pointers/src/read.test.ts | 19 ++++ packages/pointers/src/read.ts | 9 ++ packages/pointers/test/test-cases.ts | 38 +++++++ packages/web/docs/concepts/pointers.mdx | 18 +++ .../docs/core-schemas/pointers/regions.mdx | 31 +++++- .../making-regions-concrete.mdx | 10 ++ .../testing/test-cases/test-cases.mdx | 2 + .../testing/test-cases/virtual-regions.mdx | 27 +++++ packages/web/spec/pointer/concepts.mdx | 8 +- .../spec/pointer/region/location/virtual.mdx | 11 ++ .../spec/pointer/region/scheme/fragment.mdx | 11 ++ packages/web/src/schemas.ts | 3 +- schemas/pointer.schema.yaml | 23 ++++ schemas/pointer/region.schema.yaml | 10 ++ schemas/pointer/region/virtual.schema.yaml | 46 ++++++++ schemas/pointer/scheme/fragment.schema.yaml | 66 +++++++++++ 21 files changed, 509 insertions(+), 9 deletions(-) create mode 100644 packages/web/docs/implementation-guides/pointers/testing/test-cases/virtual-regions.mdx create mode 100644 packages/web/spec/pointer/region/location/virtual.mdx create mode 100644 packages/web/spec/pointer/region/scheme/fragment.mdx create mode 100644 schemas/pointer/region/virtual.schema.yaml create mode 100644 schemas/pointer/scheme/fragment.schema.yaml diff --git a/packages/format/src/types/pointer/pointer.test.ts b/packages/format/src/types/pointer/pointer.test.ts index 27211c9e9b..eb124e4895 100644 --- a/packages/format/src/types/pointer/pointer.test.ts +++ b/packages/format/src/types/pointer/pointer.test.ts @@ -160,6 +160,10 @@ testSchemaGuards("ethdebug/format/pointer", [ schema: "schema:ethdebug/format/pointer/region/code", guard: Pointer.Region.isCode, }, + { + schema: "schema:ethdebug/format/pointer/region/virtual", + guard: Pointer.Region.isVirtual, + }, { schema: "schema:ethdebug/format/pointer/collection/group", guard: Pointer.Collection.isGroup, diff --git a/packages/format/src/types/pointer/pointer.ts b/packages/format/src/types/pointer/pointer.ts index f5bc859c89..baf15b387d 100644 --- a/packages/format/src/types/pointer/pointer.ts +++ b/packages/format/src/types/pointer/pointer.ts @@ -15,7 +15,8 @@ export namespace Pointer { | Region.Calldata | Region.Returndata | Region.Transient - | Region.Code; + | Region.Code + | Region.Virtual; export const isRegion = (value: unknown): value is Region => [ @@ -26,6 +27,7 @@ export namespace Pointer { Region.isReturndata, Region.isTransient, Region.isCode, + Region.isVirtual, ].some((guard) => guard(value)); export namespace Region { @@ -71,6 +73,10 @@ export namespace Pointer { export type Code = Base & Scheme.Slice & { location: "code" }; export const isCode = (value: unknown): value is Code => isBase(value) && Scheme.isSlice(value) && value.location === "code"; + + export type Virtual = Base & Scheme.Fragment & { location: "virtual" }; + export const isVirtual = (value: unknown): value is Virtual => + isBase(value) && Scheme.isFragment(value) && value.location === "virtual"; } export namespace Scheme { @@ -99,6 +105,20 @@ export namespace Pointer { isExpression(value.offset) && "length" in value && isExpression(value.length); + + export interface Fragment { + expression: Expression; + offset?: Expression; + length?: Expression; + } + + export const isFragment = (value: unknown): value is Fragment => + !!value && + typeof value === "object" && + "expression" in value && + isExpression(value.expression) && + (!("offset" in value) || isExpression(value.offset)) && + (!("length" in value) || isExpression(value.length)); } export type Collection = diff --git a/packages/pointers/src/cursor.ts b/packages/pointers/src/cursor.ts index 56be57cd6c..53b6e925be 100644 --- a/packages/pointers/src/cursor.ts +++ b/packages/pointers/src/cursor.ts @@ -30,10 +30,11 @@ export namespace Cursor { /** * A Pointer region where all dynamic expressions have been replaced with - * concrete bytes values. + * concrete bytes values. A virtual region's `expression` becomes the + * bytes of its value. */ export type Region = { - [K in keyof R]: K extends "slot" | "offset" | "length" + [K in keyof R]: K extends "slot" | "offset" | "length" | "expression" ? R[K] extends Pointer.Expression ? Data : R[K] extends Pointer.Expression | undefined diff --git a/packages/pointers/src/dereference/index.test.ts b/packages/pointers/src/dereference/index.test.ts index b6feb1c83d..bb7b525585 100644 --- a/packages/pointers/src/dereference/index.test.ts +++ b/packages/pointers/src/dereference/index.test.ts @@ -893,6 +893,110 @@ describe("dereference", () => { expect(regions.lookup["my-slot-value"]).toBeDefined(); }); + describe("virtual regions", () => { + // `a` is on the stack, which reads as 0x11223344 + const a: Pointer.Region = { name: "a", location: "stack", slot: 2 }; + + const view = async (...group: Pointer[]) => + await (await dereference({ group: [a, ...group] })).view(state); + + const x: Pointer.Region = { + name: "x", + location: "virtual", + expression: { "~wordsized": { "~sum": [{ "~read": "a" }, 1] } }, + }; + + it("defaults to the whole value of the expression", async () => { + const { regions, read } = await view(x); + const value = Data.fromNumber(0x11223345).resizeTo(32); + + expect(regions.lookup["x"]).toEqual({ + name: "x", + location: "virtual", + expression: value, + offset: Data.fromUint(0n), + length: Data.fromNumber(32), + }); + expect(await read(regions.lookup["x"])).toEqual(value); + }); + + it("reads the fragment at an explicit offset and length", async () => { + const { regions, read } = await view( + { ...x, offset: 29, length: 2 }, + { + name: "rest", + location: "virtual", + expression: "0xdeadbeef", + offset: 1, + }, + ); + + expect(await read(regions.lookup["x"])).toEqual(Data.fromHex("0x2233")); + expect(await read(regions.lookup["rest"])).toEqual( + Data.fromHex("0xadbeef"), + ); + expect(regions.lookup["rest"].length).toEqual(Data.fromNumber(3)); + }); + + it("allows lookups of offset and length from a later region", async () => { + const { regions } = await view( + { + name: "tag", + location: "virtual", + expression: "0xdeadbeef", + offset: 1, + }, + { + location: "memory", + offset: { ".offset": "tag" }, + length: { ".length": "tag" }, + }, + ); + + expect(regions[2]).toEqual({ + location: "memory", + offset: Data.fromNumber(1), + length: Data.fromNumber(3), + }); + }); + + it("allows reading a virtual region in another expression", async () => { + const { regions, read } = await view(x, { + name: "y", + location: "virtual", + expression: { "~concat": ["0x00", { "~read": "x" }] }, + length: 2, + }); + + expect(await read(regions.lookup["y"])).toEqual(Data.fromHex("0x0000")); + expect(regions.lookup["y"]).toHaveProperty("expression.length", 33); + }); + + it("rejects a lookup of slot", async () => { + await expect( + view(x, { location: "storage", slot: { ".slot": "x" } }), + ).rejects.toThrow("Region named x does not have slot needed by lookup"); + }); + + it("rejects an expression with no width", async () => { + await expect( + view({ location: "virtual", expression: { "~sum": [1, 2] } }), + ).rejects.toThrow("evaluates to the integer 3, which has no byte width"); + }); + + it("rejects a fragment outside the value", async () => { + for (const fragment of [ + { offset: 5 }, + { offset: 2, length: 3 }, + { length: 5 }, + ]) { + await expect( + view({ location: "virtual", expression: "0xdeadbeef", ...fragment }), + ).rejects.toThrow("extends outside the 4 bytes"); + } + }); + }); + describe("names that start with $", () => { it("resolves a region named $this, not the current region", async () => { const pointer: Pointer = { diff --git a/packages/pointers/src/dereference/region.ts b/packages/pointers/src/dereference/region.ts index 8c855a37c2..a2d11c66d3 100644 --- a/packages/pointers/src/dereference/region.ts +++ b/packages/pointers/src/dereference/region.ts @@ -1,6 +1,6 @@ import { Pointer } from "@ethdebug/format"; import type { Cursor } from "#cursor"; -import type { Data } from "#data"; +import { Data } from "#data"; import { evaluate, Value, type EvaluateOptions } from "#evaluate"; /** @@ -86,12 +86,61 @@ export async function evaluateRegion( } } + if (Pointer.Region.isVirtual(region)) { + const fragment = await evaluateFragment( + region, + evaluatedProperties, + options, + ); + return fragment as Cursor.Region; + } + return { ...region, ...evaluatedProperties, } as Cursor.Region; } +/** + * Evaluate a virtual region's `expression` to the bytes it addresses into, + * and fill in the default `offset` and `length` so that later regions may + * look them up + */ +async function evaluateFragment( + region: Pointer.Region.Virtual, + { offset, length }: { offset?: Data; length?: Data }, + options: EvaluateOptions, +): Promise> { + const value = await evaluate(region.expression, options); + if (Value.isInteger(value)) { + throw new Error( + [ + `Expression of virtual region (${JSON.stringify(region.expression)}) `, + `evaluates to the integer ${value.value}, which has no byte `, + `width; give it a width with ~wordsized or ~sizedN`, + ].join(""), + ); + } + + const width = BigInt(value.data.length); + const start = offset?.asUint() ?? 0n; + const end = length ? start + length.asUint() : width; + if (start > width || end > width) { + const fields = length ? `${start}, length ${length.asUint()}` : start; + throw new Error( + `Fragment of virtual region (offset ${fields}) extends outside ` + + `the ${width} bytes of its expression's value`, + ); + } + + return { + ...region, + expression: value.data, + offset: Data.fromUint(start), + length: Data.fromUint(end - start), + }; +} + /** * Detect a stack region and modify its `slot` expression to include the * appropriate sum or difference based on the machine stack length change diff --git a/packages/pointers/src/read.test.ts b/packages/pointers/src/read.test.ts index 5824ed3911..467bfe5761 100644 --- a/packages/pointers/src/read.test.ts +++ b/packages/pointers/src/read.test.ts @@ -455,4 +455,23 @@ describe("read (segment carry)", () => { }); expect(result).toEqual(bytes([0xa2, 2], [0xa3, 2])); }); + + it("reads the fragment of a virtual region", async () => { + const expression = Data.fromHex("0xdeadbeef"); + + expect( + await read( + { + location: "virtual", + expression, + offset: Data.fromNumber(1), + length: Data.fromNumber(2), + }, + options, + ), + ).toEqual(Data.fromHex("0xadbe")); + expect(await read({ location: "virtual", expression }, options)).toEqual( + expression, + ); + }); }); diff --git a/packages/pointers/src/read.ts b/packages/pointers/src/read.ts index 05784be47b..e38bb028c5 100644 --- a/packages/pointers/src/read.ts +++ b/packages/pointers/src/read.ts @@ -84,6 +84,15 @@ export async function read( return await state.code.read({ slice: { offset, length } }); } + case "virtual": { + const { offset = 0n, length } = withPropertiesAsUints( + ["offset", "length"], + region, + ); + const end = length === undefined ? undefined : Number(offset + length); + + return Data.fromBytes(region.expression.subarray(Number(offset), end)); + } } } diff --git a/packages/pointers/test/test-cases.ts b/packages/pointers/test/test-cases.ts index 8e7d3942f6..32d439286a 100644 --- a/packages/pointers/test/test-cases.ts +++ b/packages/pointers/test/test-cases.ts @@ -237,6 +237,43 @@ const uint256ArrayMemoryTest: ObserveTraceTest = { }, }; +/** + * the computed values example: `x` (`a + 1`) and `tag` (the first 4 bytes + * of the hash of `a`) exist only as virtual regions computed from `a` + */ +const virtualRegionsTest: ObserveTraceTest<{ x: number; tag: string }> = { + pointer: findExamplePointer("virtual-operand"), + compileOptions: singleSourceCompilation({ + path: "VirtualRegions.sol", + contractName: "VirtualRegions", + content: `contract VirtualRegions { + uint256 a; + + constructor() { + a = 2; + } + } + `, + }), + + expectedValues: [ + { x: 1, tag: "0x290decd9" }, + { x: 3, tag: "0x405787fa" }, + ], + + async observe({ regions, read }) { + const x = Number((await read(regions.lookup["x"])).asUint()); + + const tag = (await read(regions.lookup["tag"])).toHex(); + + return { x, tag }; + }, + + equals(a, b) { + return a.x === b.x && a.tag === b.tag; + }, +}; + /** * collection of descriptions of tests that compile+deploy Solidity code, * then step through the machine trace of that code's execution, watching @@ -251,4 +288,5 @@ export const observeTraceTests = { "string storage": stringStorageTest, "string storage (multi-slot)": multiSlotStringStorageTest, "uint256[] memory": uint256ArrayMemoryTest, + "virtual regions": virtualRegionsTest, }; diff --git a/packages/web/docs/concepts/pointers.mdx b/packages/web/docs/concepts/pointers.mdx index 0bab12659c..c50a89ade5 100644 --- a/packages/web/docs/concepts/pointers.mdx +++ b/packages/web/docs/concepts/pointers.mdx @@ -186,6 +186,24 @@ optional offset and length for packed values: }`} +**Fragment-based regions** (virtual) hold the bytes of a computed value, +for data that no EVM location stores (e.g., a variable the optimizer removed). +Optional offset and length select part of the value: + + + {`{ + "location": "virtual", + "expression": { + "~keccak256": [{ "~wordsized": 1 }] + }, + "length": 4 +}`} + + Regions can be **named** for reference elsewhere in the pointer: sourceFile.getFunction("evaluateRegion")} /> + +A virtual region also has an `expression`. The implementation evaluates it +last, keeps its bytes as the concrete region's `expression`, and fills in the +default `offset` and `length`, so that later regions can look them up: + + sourceFile.getFunction("evaluateFragment")} +/> diff --git a/packages/web/docs/implementation-guides/pointers/testing/test-cases/test-cases.mdx b/packages/web/docs/implementation-guides/pointers/testing/test-cases/test-cases.mdx index 71729817dc..c2a2bd083e 100644 --- a/packages/web/docs/implementation-guides/pointers/testing/test-cases/test-cases.mdx +++ b/packages/web/docs/implementation-guides/pointers/testing/test-cases/test-cases.mdx @@ -23,6 +23,8 @@ Test cases are aggregated into the `observeTraceTests` variable: "/docs/implementation-guides/pointers/testing/test-cases/string-storage/", uint256ArrayMemoryTest: "/docs/implementation-guides/pointers/testing/test-cases/uint256-array-memory/", + virtualRegionsTest: + "/docs/implementation-guides/pointers/testing/test-cases/virtual-regions/", }} /> diff --git a/packages/web/docs/implementation-guides/pointers/testing/test-cases/virtual-regions.mdx b/packages/web/docs/implementation-guides/pointers/testing/test-cases/virtual-regions.mdx new file mode 100644 index 0000000000..7ab06b3378 --- /dev/null +++ b/packages/web/docs/implementation-guides/pointers/testing/test-cases/virtual-regions.mdx @@ -0,0 +1,27 @@ +--- +sidebar_position: 4 +sidebar_label: virtual regions +--- + +import CodeListing from "@site/src/components/CodeListing"; +import TestedPointer from "./TestedPointer"; + +# Test case: virtual regions + +A virtual region holds a computed value instead of stored bytes. This test +computes two values from a `uint256` in storage: `x`, the value plus one, +and `tag`, the first 4 bytes of the value's hash. + +## Test source + + + sourceFile.getVariableStatement("virtualRegionsTest") + } +/> + +## Tested pointer + + diff --git a/packages/web/spec/pointer/concepts.mdx b/packages/web/spec/pointer/concepts.mdx index a3cc05030e..ed312b7c6a 100644 --- a/packages/web/spec/pointer/concepts.mdx +++ b/packages/web/spec/pointer/concepts.mdx @@ -277,11 +277,15 @@ abstractions, but instead it defines the concept of an **addressing scheme**. Each location-specific region schema is defined as an extension of the schema for a particular addressing scheme. -This format currently defines two such addressing schemes: +This format currently defines three such addressing schemes: **ethdebug/format/pointer/scheme/slice** and **ethdebug/format/pointer/scheme/segment**, for addressing ranges within a single continuous byte array and addressing a slot or collection of slots -in a word-arranged locaton (respectively). +in a word-arranged locaton (respectively), and +**ethdebug/format/pointer/scheme/fragment**, which supplies its own byte +space (the value of an expression) and addresses a range within it. The +`virtual` location uses the fragment scheme for values that are computed +instead of stored. Within a slot, the segment scheme numbers bytes from the most significant byte: byte `0` is the first byte of the slot's big-endian word. diff --git a/packages/web/spec/pointer/region/location/virtual.mdx b/packages/web/spec/pointer/region/location/virtual.mdx new file mode 100644 index 0000000000..9026269c55 --- /dev/null +++ b/packages/web/spec/pointer/region/location/virtual.mdx @@ -0,0 +1,11 @@ +--- +sidebar_position: 8 +--- + +import SchemaViewer from "@site/src/components/SchemaViewer"; + +# `virtual` + + diff --git a/packages/web/spec/pointer/region/scheme/fragment.mdx b/packages/web/spec/pointer/region/scheme/fragment.mdx new file mode 100644 index 0000000000..b43c18462f --- /dev/null +++ b/packages/web/spec/pointer/region/scheme/fragment.mdx @@ -0,0 +1,11 @@ +--- +sidebar_position: 3 +--- + +import SchemaViewer from "@site/src/components/SchemaViewer"; + +# `fragment` + + diff --git a/packages/web/src/schemas.ts b/packages/web/src/schemas.ts index 2a82d08f0b..02cf5873e1 100644 --- a/packages/web/src/schemas.ts +++ b/packages/web/src/schemas.ts @@ -92,6 +92,7 @@ const pointerSchemaIndex: SchemaIndex = { "returndata", "transient", "code", + "virtual", ] .map((location) => ({ [`schema:ethdebug/format/pointer/region/${location}`]: { @@ -100,7 +101,7 @@ const pointerSchemaIndex: SchemaIndex = { })) .reduce((a, b) => ({ ...a, ...b }), {}), - ...["slice", "segment"] + ...["slice", "segment", "fragment"] .map((scheme) => ({ [`schema:ethdebug/format/pointer/scheme/${scheme}`]: { href: `/spec/pointer/region/scheme/${scheme}`, diff --git a/schemas/pointer.schema.yaml b/schemas/pointer.schema.yaml index ad9cf49727..404c5f1723 100644 --- a/schemas/pointer.schema.yaml +++ b/schemas/pointer.schema.yaml @@ -297,3 +297,26 @@ examples: slot: "start-slot" offset: 0 length: "string-length" + + - # example computed values: `x = a + 1` after the optimizer removed `x`, + # and `tag`, the first 4 bytes of the hash of `a`, where `a` is a + # `uint256` in storage slot 0 + group: + - name: "virtual-operand" + location: storage + slot: 0 + + - name: "x" + location: virtual + expression: + ~wordsized: + ~sum: + - ~read: "virtual-operand" + - 1 + + - name: "tag" + location: virtual + expression: + ~keccak256: + - ~read: "virtual-operand" + length: 4 diff --git a/schemas/pointer/region.schema.yaml b/schemas/pointer/region.schema.yaml index e2f7f5e705..364bf404e9 100644 --- a/schemas/pointer/region.schema.yaml +++ b/schemas/pointer/region.schema.yaml @@ -76,6 +76,15 @@ allOf: then: $ref: "schema:ethdebug/format/pointer/region/code" + - if: + required: + - location + properties: + location: + const: virtual + then: + $ref: "schema:ethdebug/format/pointer/region/virtual" + $defs: Location: type: string @@ -87,6 +96,7 @@ $defs: - returndata - transient - code + - virtual unevaluatedProperties: false diff --git a/schemas/pointer/region/virtual.schema.yaml b/schemas/pointer/region/virtual.schema.yaml new file mode 100644 index 0000000000..9802f6651f --- /dev/null +++ b/schemas/pointer/region/virtual.schema.yaml @@ -0,0 +1,46 @@ +$schema: "https://json-schema.org/draft/2020-12/schema" +$id: "schema:ethdebug/format/pointer/region/virtual" + +title: ethdebug/format/pointer/region/virtual +description: | + A schema for representing a region of data that is not stored in any EVM + data location, but is computed from the machine state: the bytes of an + expression's value. + + A compiler may use a virtual region for a value that has no place in the + machine state of its own, e.g., a variable the optimizer removed whose + value can still be computed from other values that remain. + + This schema is constructed by extending the base region schema + and the schema for the fragment addressing scheme. +type: object +allOf: + - title: '{ "location": "virtual" }' # note: whitespace chars are \255 (nbsp) + properties: + location: + const: virtual + + required: + - location + - $ref: "schema:ethdebug/format/pointer/region/base" + - $ref: "schema:ethdebug/format/pointer/scheme/fragment" + +unevaluatedProperties: false + +examples: + # `x = a + 1` after the optimizer removed `x`, where a region named `a` + # comes before this one + - name: x + location: virtual + expression: + ~wordsized: + ~sum: + - ~read: a + - 1 + # the first 4 bytes of a hash + - name: tag + location: virtual + expression: + ~keccak256: + - ~read: a + length: 4 diff --git a/schemas/pointer/scheme/fragment.schema.yaml b/schemas/pointer/scheme/fragment.schema.yaml new file mode 100644 index 0000000000..3e4dcf7c46 --- /dev/null +++ b/schemas/pointer/scheme/fragment.schema.yaml @@ -0,0 +1,66 @@ +$schema: "https://json-schema.org/draft/2020-12/schema" +$id: "schema:ethdebug/format/pointer/scheme/fragment" + +title: ethdebug/format/pointer/scheme/fragment +description: | + An addressing scheme for pointing to a range of bytes inside the value of + an expression. + + The other addressing schemes address bytes in a byte space that the data + location already has. This scheme supplies the byte space itself: the + bytes of the value that `expression` evaluates to. It then addresses a + range of bytes in that value by `offset` and `length`, as the slice + scheme does. + + A fragment that extends outside the value's bytes (i.e., where `offset` + plus `length` exceeds the value's width) is invalid. + +type: object + +properties: + expression: + description: | + The expression whose value supplies the bytes for this fragment. + + This expression **must** be width-bearing (bytes), the same rule as + for the operands of `~concat` and `~keccak256`. A bare integer (a JSON + number, an odd-digit hex literal, `~wordsize`, an arithmetic result, + or a lookup) is **not** valid here: give it a width first with + `~sizedN` or `~wordsized`. + + This expression is evaluated against the same machine state as the + other regions of the pointer. It may refer only to regions that come + before this region. + $ref: "schema:ethdebug/format/pointer/expression" + offset: + description: | + The index of the byte (starting from zero) in the value's bytes where + the fragment begins. + + This field is **optional**. If unspecified, it has the default value + of `0`, indicating that the fragment begins at the first byte of the + value. + $ref: "schema:ethdebug/format/pointer/expression" + default: 0 + length: + description: | + The length of the fragment in number of bytes. + + This field is **optional**. If unspecified, its default value + indicates that the fragment ends at the end of the value: the value's + width minus `offset`. + $ref: "schema:ethdebug/format/pointer/expression" + +required: + - expression + +examples: + - expression: + ~wordsized: 1 + - expression: + ~keccak256: + - ~wordsized: 0 + length: 4 + - expression: "0xdeadbeef" + offset: 2 + length: 2 From 60fd38d89326705de05f24b26fd16eb164f259dc Mon Sep 17 00:00:00 2001 From: "g. nicholas d'andrea" Date: Tue, 10 Nov 2026 19:07:11 -0500 Subject: [PATCH 2/8] Add changelog entries for virtual regions --- CHANGELOG.md | 15 +++++++++++++++ packages/format/CHANGELOG.md | 7 +++++++ packages/pointers/CHANGELOG.md | 7 +++++++ 3 files changed, 29 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 519bf11bde..431488ff29 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -53,6 +53,21 @@ The sections do not signal obligations; the prefixes do. ## Unreleased +### Added + +- A region with `"location": "virtual"` holds the bytes of a computed value, + e.g., a variable the optimizer removed. It uses the new `fragment` + addressing scheme: a width-bearing `expression` supplies the bytes, and + optional `offset` and `length` select a range of them. + - Schemas: **ethdebug/format/pointer/region/virtual**, + **ethdebug/format/pointer/scheme/fragment**, + **ethdebug/format/pointer/region** + - Producers: optional: a pointer may describe a value that no data location + stores as a virtual region. + - Consumers: required: a region may have `"location": "virtual"`. Its bytes + are the fragment of its `expression`'s value, which a consumer must + evaluate. A fragment outside the value's bytes is invalid. + ### Changed - The members of a `define` no longer depend on their order, since JSON diff --git a/packages/format/CHANGELOG.md b/packages/format/CHANGELOG.md index 58918d31d2..b9f3817cac 100644 --- a/packages/format/CHANGELOG.md +++ b/packages/format/CHANGELOG.md @@ -6,6 +6,13 @@ tracked in the root [`CHANGELOG.md`](../../CHANGELOG.md). ## Unreleased +### Added + +- The **ethdebug/format/pointer/region/virtual** and + **ethdebug/format/pointer/scheme/fragment** schemas, with the types + `Pointer.Region.Virtual` and `Pointer.Scheme.Fragment` and their guards + `Pointer.Region.isVirtual` and `Pointer.Scheme.isFragment`. + ### Changed - `schemas` parses each schema from YAML on first access instead of at diff --git a/packages/pointers/CHANGELOG.md b/packages/pointers/CHANGELOG.md index bf9623c77c..86a1227f7d 100644 --- a/packages/pointers/CHANGELOG.md +++ b/packages/pointers/CHANGELOG.md @@ -6,6 +6,13 @@ itself are tracked in the root [`CHANGELOG.md`](../../CHANGELOG.md). ## Unreleased +### Added + +- `dereference` and `read` support virtual regions. A concrete virtual + region keeps the bytes of its `expression` and has `offset` and `length` + filled in with their defaults. An expression with no width, or a fragment + outside the value, throws. + ### Changed - `dereference` evaluates the members of a scope's `define` in dependency From 5aa8a7b12c3b8ed3c595a59095834f363b53c3e2 Mon Sep 17 00:00:00 2001 From: "g. nicholas d'andrea" Date: Tue, 10 Nov 2026 19:08:05 -0500 Subject: [PATCH 3/8] Link the virtual regions changelog entries to #411 --- CHANGELOG.md | 3 ++- packages/format/CHANGELOG.md | 3 ++- packages/pointers/CHANGELOG.md | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 431488ff29..be55167952 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -58,7 +58,7 @@ The sections do not signal obligations; the prefixes do. - A region with `"location": "virtual"` holds the bytes of a computed value, e.g., a variable the optimizer removed. It uses the new `fragment` addressing scheme: a width-bearing `expression` supplies the bytes, and - optional `offset` and `length` select a range of them. + optional `offset` and `length` select a range of them ([#411]). - Schemas: **ethdebug/format/pointer/region/virtual**, **ethdebug/format/pointer/scheme/fragment**, **ethdebug/format/pointer/region** @@ -778,3 +778,4 @@ First published version of the specification. [#402]: https://github.com/ethdebug/format/pull/402 [#404]: https://github.com/ethdebug/format/pull/404 [#408]: https://github.com/ethdebug/format/pull/408 +[#411]: https://github.com/ethdebug/format/pull/411 diff --git a/packages/format/CHANGELOG.md b/packages/format/CHANGELOG.md index b9f3817cac..0241128a54 100644 --- a/packages/format/CHANGELOG.md +++ b/packages/format/CHANGELOG.md @@ -11,7 +11,7 @@ tracked in the root [`CHANGELOG.md`](../../CHANGELOG.md). - The **ethdebug/format/pointer/region/virtual** and **ethdebug/format/pointer/scheme/fragment** schemas, with the types `Pointer.Region.Virtual` and `Pointer.Scheme.Fragment` and their guards - `Pointer.Region.isVirtual` and `Pointer.Scheme.isFragment`. + `Pointer.Region.isVirtual` and `Pointer.Scheme.isFragment` ([#411]). ### Changed @@ -163,6 +163,7 @@ First publication. [#323]: https://github.com/ethdebug/format/pull/323 [#325]: https://github.com/ethdebug/format/pull/325 [#373]: https://github.com/ethdebug/format/pull/373 +[#411]: https://github.com/ethdebug/format/pull/411 [`0ef2f37`]: https://github.com/ethdebug/format/commit/0ef2f37 [`10ab103`]: https://github.com/ethdebug/format/commit/10ab103 [`21e532e`]: https://github.com/ethdebug/format/commit/21e532e diff --git a/packages/pointers/CHANGELOG.md b/packages/pointers/CHANGELOG.md index 86a1227f7d..ef4a7e46b5 100644 --- a/packages/pointers/CHANGELOG.md +++ b/packages/pointers/CHANGELOG.md @@ -11,7 +11,7 @@ itself are tracked in the root [`CHANGELOG.md`](../../CHANGELOG.md). - `dereference` and `read` support virtual regions. A concrete virtual region keeps the bytes of its `expression` and has `offset` and `length` filled in with their defaults. An expression with no width, or a fragment - outside the value, throws. + outside the value, throws ([#411]). ### Changed @@ -162,3 +162,4 @@ First publication. [#323]: https://github.com/ethdebug/format/pull/323 [#325]: https://github.com/ethdebug/format/pull/325 [#408]: https://github.com/ethdebug/format/pull/408 +[#411]: https://github.com/ethdebug/format/pull/411 From 5b540c7e2310c5a54234354c78d015d277792eec Mon Sep 17 00:00:00 2001 From: "g. nicholas d'andrea" Date: Thu, 19 Nov 2026 14:59:22 -0500 Subject: [PATCH 4/8] format: let a lookup use a default that a description gives --- CHANGELOG.md | 10 ++++++++++ schemas/pointer/expression.schema.yaml | 4 +++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index be55167952..d43b5a76b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -108,6 +108,16 @@ The sections do not signal obligations; the prefixes do. `bytesN` value on the right, concatenate it with zero bytes (`~concat`). - Consumers: no change needed. The evaluation rules did not change. +- The rule for a lookup (`{ ".": }`) of an omitted + property said that the property's schema must specify a default. A + segment's `length` and a fragment's `length` have defaults that only their + descriptions give. The rule now accepts a default given either way + ([#411]). + - Schemas: **ethdebug/format/pointer/expression** + - Producers: no change needed. + - Consumers: no change needed if a lookup of an omitted segment `length` + already gives its default. + ## 0.1.0-draft.2 — 2026-10-07 ### Changed diff --git a/schemas/pointer/expression.schema.yaml b/schemas/pointer/expression.schema.yaml index 35ab08bf9d..202e506e07 100644 --- a/schemas/pointer/expression.schema.yaml +++ b/schemas/pointer/expression.schema.yaml @@ -176,7 +176,9 @@ $defs: `` **must** be a valid and present property on the corresponding region, or it **must** correspond to an optional property - whose schema specifies a default value for that property. + that has a default value. The default may be given by the property's + schema `default` or by its description (e.g., the `length` of a + segment or a fragment). type: object patternProperties: "^\\.(offset|length|slot)$": From 90a0d030c25cf2ddae6b459eefc2f0f56078a4a8 Mon Sep 17 00:00:00 2001 From: "g. nicholas d'andrea" Date: Thu, 19 Nov 2026 15:01:39 -0500 Subject: [PATCH 5/8] pointers-react: give virtual regions their own style A pink badge with a dashed border, and a dashed left border in the region output, since a virtual region's bytes are computed, not stored. --- packages/pointers-react/CHANGELOG.md | 8 ++++++++ packages/pointers-react/src/components/RegionMap.css | 8 ++++++++ packages/pointers-react/src/components/RegionMap.tsx | 1 + packages/pointers-react/src/components/RegionOutput.css | 4 ++++ packages/pointers-react/src/components/RegionOutput.tsx | 1 + packages/pointers-react/src/components/variables.css | 4 ++++ packages/web/src/theme/PointersExample/RegionMap.css | 8 ++++++++ packages/web/src/theme/PointersExample/RegionOutput.css | 4 ++++ packages/web/src/theme/PointersExample/variables.css | 4 ++++ 9 files changed, 42 insertions(+) diff --git a/packages/pointers-react/CHANGELOG.md b/packages/pointers-react/CHANGELOG.md index d0a975d942..7b93f1e535 100644 --- a/packages/pointers-react/CHANGELOG.md +++ b/packages/pointers-react/CHANGELOG.md @@ -7,6 +7,13 @@ root [`CHANGELOG.md`](../../CHANGELOG.md). ## Unreleased +### Added + +- A region with `"location": "virtual"` has its own style: a pink badge + with a dashed border, and a dashed left border in the region output. + The new `--pointers-region-virtual` and `--pointers-region-virtual-bg` + variables set its colors ([#411]). + ### Changed - The `react` and `react-dom` peer ranges now include React 19 @@ -54,3 +61,4 @@ First publication. [#300]: https://github.com/ethdebug/format/pull/300 [#323]: https://github.com/ethdebug/format/pull/323 [#374]: https://github.com/ethdebug/format/pull/374 +[#411]: https://github.com/ethdebug/format/pull/411 diff --git a/packages/pointers-react/src/components/RegionMap.css b/packages/pointers-react/src/components/RegionMap.css index 0a68a79824..78600a11e3 100644 --- a/packages/pointers-react/src/components/RegionMap.css +++ b/packages/pointers-react/src/components/RegionMap.css @@ -107,6 +107,14 @@ background: var(--pointers-region-transient-bg); } +/* A virtual region's bytes are computed, not stored: dashed */ +.region-virtual .region-location-badge { + color: var(--pointers-region-virtual); + background: var(--pointers-region-virtual-bg); + outline: 1px dashed var(--pointers-region-virtual); + outline-offset: -1px; +} + .region-details { font-size: 0.75rem; font-family: var(--ifm-font-family-monospace, monospace); diff --git a/packages/pointers-react/src/components/RegionMap.tsx b/packages/pointers-react/src/components/RegionMap.tsx index 8293c3f75c..46ff0117ec 100644 --- a/packages/pointers-react/src/components/RegionMap.tsx +++ b/packages/pointers-react/src/components/RegionMap.tsx @@ -37,6 +37,7 @@ function getLocationClass(location: string): string { returndata: "region-returndata", code: "region-code", transient: "region-transient", + virtual: "region-virtual", }; return locationClasses[location] || "region-unknown"; } diff --git a/packages/pointers-react/src/components/RegionOutput.css b/packages/pointers-react/src/components/RegionOutput.css index c9112a4b07..393f8592d4 100644 --- a/packages/pointers-react/src/components/RegionOutput.css +++ b/packages/pointers-react/src/components/RegionOutput.css @@ -147,3 +147,7 @@ .region-output-item.region-transient { border-left: 3px solid var(--pointers-region-transient); } + +.region-output-item.region-virtual { + border-left: 3px dashed var(--pointers-region-virtual); +} diff --git a/packages/pointers-react/src/components/RegionOutput.tsx b/packages/pointers-react/src/components/RegionOutput.tsx index e0ddaedcd2..199c94d43b 100644 --- a/packages/pointers-react/src/components/RegionOutput.tsx +++ b/packages/pointers-react/src/components/RegionOutput.tsx @@ -37,6 +37,7 @@ function getLocationClass(location: string): string { returndata: "region-returndata", code: "region-code", transient: "region-transient", + virtual: "region-virtual", }; return locationClasses[location] || "region-unknown"; } diff --git a/packages/pointers-react/src/components/variables.css b/packages/pointers-react/src/components/variables.css index 54ff98f013..63f2e4be6b 100644 --- a/packages/pointers-react/src/components/variables.css +++ b/packages/pointers-react/src/components/variables.css @@ -46,6 +46,8 @@ --pointers-region-code-bg: rgba(110, 119, 129, 0.1); --pointers-region-transient: #953800; --pointers-region-transient-bg: rgba(149, 56, 0, 0.1); + --pointers-region-virtual: #bf3989; + --pointers-region-virtual-bg: rgba(191, 57, 137, 0.1); /* Accent colors */ --pointers-accent-blue: #0969da; @@ -101,6 +103,8 @@ --pointers-region-code-bg: rgba(133, 133, 133, 0.15); --pointers-region-transient: #ce9178; --pointers-region-transient-bg: rgba(206, 145, 120, 0.15); + --pointers-region-virtual: #f778ba; + --pointers-region-virtual-bg: rgba(247, 120, 186, 0.15); /* Accent colors */ --pointers-accent-blue: #569cd6; diff --git a/packages/web/src/theme/PointersExample/RegionMap.css b/packages/web/src/theme/PointersExample/RegionMap.css index 0a68a79824..78600a11e3 100644 --- a/packages/web/src/theme/PointersExample/RegionMap.css +++ b/packages/web/src/theme/PointersExample/RegionMap.css @@ -107,6 +107,14 @@ background: var(--pointers-region-transient-bg); } +/* A virtual region's bytes are computed, not stored: dashed */ +.region-virtual .region-location-badge { + color: var(--pointers-region-virtual); + background: var(--pointers-region-virtual-bg); + outline: 1px dashed var(--pointers-region-virtual); + outline-offset: -1px; +} + .region-details { font-size: 0.75rem; font-family: var(--ifm-font-family-monospace, monospace); diff --git a/packages/web/src/theme/PointersExample/RegionOutput.css b/packages/web/src/theme/PointersExample/RegionOutput.css index c9112a4b07..393f8592d4 100644 --- a/packages/web/src/theme/PointersExample/RegionOutput.css +++ b/packages/web/src/theme/PointersExample/RegionOutput.css @@ -147,3 +147,7 @@ .region-output-item.region-transient { border-left: 3px solid var(--pointers-region-transient); } + +.region-output-item.region-virtual { + border-left: 3px dashed var(--pointers-region-virtual); +} diff --git a/packages/web/src/theme/PointersExample/variables.css b/packages/web/src/theme/PointersExample/variables.css index 57812fc89f..040bb47cf2 100644 --- a/packages/web/src/theme/PointersExample/variables.css +++ b/packages/web/src/theme/PointersExample/variables.css @@ -46,6 +46,8 @@ --pointers-region-code-bg: rgba(110, 119, 129, 0.1); --pointers-region-transient: #953800; --pointers-region-transient-bg: rgba(149, 56, 0, 0.1); + --pointers-region-virtual: #bf3989; + --pointers-region-virtual-bg: rgba(191, 57, 137, 0.1); /* Accent colors */ --pointers-accent-blue: #0969da; @@ -101,6 +103,8 @@ --pointers-region-code-bg: rgba(133, 133, 133, 0.15); --pointers-region-transient: #ce9178; --pointers-region-transient-bg: rgba(206, 145, 120, 0.15); + --pointers-region-virtual: #f778ba; + --pointers-region-virtual-bg: rgba(247, 120, 186, 0.15); /* Accent colors */ --pointers-accent-blue: #569cd6; From 2192ff628ef99e224e3134063a90898968f43c4c Mon Sep 17 00:00:00 2001 From: "g. nicholas d'andrea" Date: Thu, 19 Nov 2026 15:08:03 -0500 Subject: [PATCH 6/8] Correct the consumer impact of the lookup default rule --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d43b5a76b3..da429ca91e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -115,8 +115,8 @@ The sections do not signal obligations; the prefixes do. ([#411]). - Schemas: **ethdebug/format/pointer/expression** - Producers: no change needed. - - Consumers: no change needed if a lookup of an omitted segment `length` - already gives its default. + - Consumers: required: a lookup of an omitted segment or fragment `length` + gives the default that its description defines. ## 0.1.0-draft.2 — 2026-10-07 From b8ce678ed2523f4c81c24b7f0fd679509074c83b Mon Sep 17 00:00:00 2001 From: "g. nicholas d'andrea" Date: Thu, 19 Nov 2026 15:12:07 -0500 Subject: [PATCH 7/8] pointers: give a segment's omitted offset and length their defaults A lookup of either one threw, though the spec gives both a default. --- packages/pointers/CHANGELOG.md | 5 +++ .../pointers/src/dereference/index.test.ts | 32 +++++++++++++++++++ packages/pointers/src/dereference/region.ts | 20 ++++++++++++ 3 files changed, 57 insertions(+) diff --git a/packages/pointers/CHANGELOG.md b/packages/pointers/CHANGELOG.md index ef4a7e46b5..eb0ed3a3ac 100644 --- a/packages/pointers/CHANGELOG.md +++ b/packages/pointers/CHANGELOG.md @@ -22,6 +22,11 @@ itself are tracked in the root [`CHANGELOG.md`](../../CHANGELOG.md). ### Fixed +- A lookup of a stack, storage or transient region's omitted `offset` or + `length` gives its default (`0`, and the bytes to the end of the slot in + which the region begins). It threw "does not have ... needed by lookup" + before. A concrete region of these locations now always has `offset` and + `length` ([#411]). - The published type declarations no longer reference Node's `util` types. `Data.inspect` and its `util.inspect.custom` hook used `util.InspectOptionsStylized`, which newer `@types/node` versions no longer diff --git a/packages/pointers/src/dereference/index.test.ts b/packages/pointers/src/dereference/index.test.ts index bb7b525585..f7905936dc 100644 --- a/packages/pointers/src/dereference/index.test.ts +++ b/packages/pointers/src/dereference/index.test.ts @@ -108,6 +108,38 @@ describe("dereference", () => { }); }); + it("gives a segment's omitted offset and length their defaults", async () => { + const pointer: Pointer = { + group: [ + { name: "a", location: "storage", slot: 0 }, + { name: "b", location: "storage", slot: 1, offset: 12 }, + { + location: "memory", + offset: { ".offset": "a" }, + length: { "~sum": [{ ".length": "a" }, { ".length": "b" }] }, + }, + ], + }; + + const cursor = await dereference(pointer); + + const { regions } = await cursor.view(state); + + expect(regions.lookup["a"]).toMatchObject({ + offset: Data.fromNumber(0), + length: Data.fromNumber(32), + }); + expect(regions.lookup["b"]).toMatchObject({ + offset: Data.fromNumber(12), + length: Data.fromNumber(20), + }); + expect(regions[2]).toEqual({ + location: "memory", + offset: Data.fromNumber(0), + length: Data.fromNumber(52), + }); + }); + it("works for a list of regions", async () => { const pointer: Pointer = { list: { diff --git a/packages/pointers/src/dereference/region.ts b/packages/pointers/src/dereference/region.ts index a2d11c66d3..a1e93b526d 100644 --- a/packages/pointers/src/dereference/region.ts +++ b/packages/pointers/src/dereference/region.ts @@ -51,6 +51,26 @@ export async function evaluateRegion( Pointer.Expression, ][]; + // a segment's omitted offset and length have defaults, which lookups + // (including ~this) must see: offset 0, and a length that ends the + // segment at the end of the slot in which it begins + if (Pointer.Scheme.isSegment(region)) { + if (!("offset" in region)) { + expressionQueue.push(["offset" as keyof R, 0]); + } + if (!("length" in region)) { + expressionQueue.push([ + "length" as keyof R, + { + "~difference": [ + "~wordsize", + { "~remainder": [{ ".offset": "~this" }, "~wordsize"] }, + ], + }, + ]); + } + } + while (expressionQueue.length > 0) { const [property, expression] = expressionQueue.shift()!; From 011b7300ab080212173bbea0f8523d0e9c3d6ad1 Mon Sep 17 00:00:00 2001 From: "g. nicholas d'andrea" Date: Thu, 19 Nov 2026 15:38:56 -0500 Subject: [PATCH 8/8] bugc: drop the before-templates golden test It checked the move to templates (#399) against the compiler from before it. That move is long done, and the test that templates read as the inline pointers do still runs on every example. --- .../src/irgen/debug/templates.golden.json | 66 ----------------- .../bugc/src/irgen/debug/templates.test.ts | 74 ++----------------- 2 files changed, 8 insertions(+), 132 deletions(-) delete mode 100644 packages/bugc/src/irgen/debug/templates.golden.json diff --git a/packages/bugc/src/irgen/debug/templates.golden.json b/packages/bugc/src/irgen/debug/templates.golden.json deleted file mode 100644 index cbe7c925ed..0000000000 --- a/packages/bugc/src/irgen/debug/templates.golden.json +++ /dev/null @@ -1,66 +0,0 @@ -{ - "advanced/nested-arrays.bug at O0": { - "reads": 571, - "digest": "4ec3e3a37c971656218b53321691f84d963075cf6b503053932c425250c14c27" - }, - "advanced/nested-arrays.bug at O2": { - "reads": 392, - "digest": "9e36b17023c5f85a534188d78fcfe7e57e137b5f2e26ffabf6a59d881c7840a9" - }, - "advanced/nested-structs.bug at O0": { - "reads": 61, - "digest": "a04f810aeb08ab9e3f9e5f0056ebc6a0bcd50ed52d99bf7281ca63b60f7c53dc" - }, - "advanced/nested-structs.bug at O2": { - "reads": 38, - "digest": "c1bc27083ae0ff87be015c5afbc67c9ebfb38ec6691301a3828097504d1449d7" - }, - "advanced/token-registry.bug at O0": { - "reads": 150, - "digest": "98d06f5fe6dfbb9d58cde4c0d0539ad383819672b291bfaea0f2802bb6963f1c" - }, - "advanced/token-registry.bug at O2": { - "reads": 156, - "digest": "4c5bc026e29fcc42f34df492846a242f9f46d91846660a38e9b883ba56108793" - }, - "basic/functions.bug at O0": { - "reads": 821, - "digest": "336b3b9a140a08e9314630a3cd17b91cc8e086cfc9738575628c829e715453cc" - }, - "basic/functions.bug at O2": { - "reads": 146, - "digest": "f7677cbb9aa7cf6119a6f015056b1b903114706c85be6f4b7321ad78603c2f63" - }, - "intermediate/mappings.bug at O0": { - "reads": 439, - "digest": "93dc2f8d15d7499b832253cec263149836b5b17985b7197c1361bd8ad9c6974b" - }, - "intermediate/mappings.bug at O2": { - "reads": 188, - "digest": "c538ebd3daf832a1200e5861d0d856324c1e1325f585d7a46595f5967d187bd0" - }, - "intermediate/memory-arrays.bug at O0": { - "reads": 23, - "digest": "a47973739f3e06057e87b87287e94c5bb80b0af2fb118681364a6e43eee5d679" - }, - "intermediate/memory-arrays.bug at O2": { - "reads": 11, - "digest": "a65147f06d247180df9b07f7d6091f309c49e9bafb542b41b0e9760b3dc65aa8" - }, - "intermediate/pointer-shapes.bug at O0": { - "reads": 9450, - "digest": "ad31f8a041360eca8424cd6ce211be103360102eb1f471c047f84f834ff5f3f4" - }, - "intermediate/pointer-shapes.bug at O2": { - "reads": 6331, - "digest": "7477d2810c3df1dead6397d6ffcb29be4f47af6c25d9a29c9180ea2cf404cc53" - }, - "intermediate/strings.bug at O0": { - "reads": 74, - "digest": "567a1663aa4c23d39c491a51e822be394e4aa6d52a12653c85642ecbee48d19a" - }, - "intermediate/strings.bug at O2": { - "reads": 68, - "digest": "afe096adad34620894c92cdb7dcfc2579506552eaa05fe8fac6c09a4739ce518" - } -} diff --git a/packages/bugc/src/irgen/debug/templates.test.ts b/packages/bugc/src/irgen/debug/templates.test.ts index bf8974a281..372d0f9b50 100644 --- a/packages/bugc/src/irgen/debug/templates.test.ts +++ b/packages/bugc/src/irgen/debug/templates.test.ts @@ -1,20 +1,13 @@ /** - * A pointer that refers to shared templates must read what bugc's - * pointers read before they referred to templates. Every listed - * variable's pointer is read at every step of a run of an example: - * - * - For every example, at every level, both ways: with the - * compilation's templates, and inline (each reference replaced by its - * template's pointer, regions renamed as the reference's `yields` - * says). The two must give the same regions with the same bytes. - * - For some examples, at O0 and O2, the reads must be those of bugc - * before templates (origin/main at 9c8d7ccb1, all inline pointers): - * `templates.golden.json` holds the number of reads and a digest of - * them. `UPDATE_TEMPLATES_GOLDEN=1` writes it again from the - * compiler at hand, so it is written with a compiler from before. + * A pointer that refers to shared templates must read what the same + * pointer written inline reads. For every example, at every level, + * every listed variable's pointer is read at every step of a run both + * ways: with the compilation's templates, and inline (each reference + * replaced by its template's pointer, regions renamed as the + * reference's `yields` says). The two must give the same regions with + * the same bytes. */ -import { describe, it, expect, afterAll, afterEach } from "vitest"; -import { createHash } from "crypto"; +import { describe, it, expect, afterEach } from "vitest"; import { promises as fs } from "fs"; import path from "path"; import { glob } from "glob"; @@ -209,54 +202,3 @@ describe("pointers that refer to templates read as written out", async () => { } } }); - -const GOLDEN = path.join(__dirname, "templates.golden.json"); -const goldenExamples = [ - "advanced/nested-arrays.bug", - "advanced/nested-structs.bug", - "advanced/token-registry.bug", - "basic/functions.bug", - "intermediate/mappings.bug", - "intermediate/memory-arrays.bug", - "intermediate/pointer-shapes.bug", - "intermediate/strings.bug", -]; - -describe("pointers read as they did before templates", async () => { - const update = !!process.env.UPDATE_TEMPLATES_GOLDEN; - const golden: Record = update - ? {} - : JSON.parse(await fs.readFile(GOLDEN, "utf-8")); - if (update) { - afterAll(() => - fs.writeFile(GOLDEN, JSON.stringify(golden, null, 2) + "\n"), - ); - } - - for (const file of goldenExamples) { - for (const level of [0, 2] as const) { - const key = `${file} at O${level}`; - it( - key, - async () => { - const source = await fs.readFile( - path.join(EXAMPLES_DIR, file), - "utf-8", - ); - const hash = createHash("sha256"); - let reads = 0; - await eachPointer(source, level, async (label, pointer, state, t) => { - const read_ = await read(pointer, state, t); - hash.update(JSON.stringify([label, read_]) + "\n"); - if (Array.isArray(read_)) reads++; - }); - const actual = { reads, digest: hash.digest("hex") }; - expect(reads).toBeGreaterThan(0); - if (update) golden[key] = actual; - else expect(actual).toEqual(golden[key]); - }, - 60_000, - ); - } - } -});