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
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 ([#411]).
- 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 `places` of a `fixed` or `ufixed` type may now be 0, as Solidity
Expand Down Expand Up @@ -101,6 +116,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 (`{ ".<property>": <region> }`) 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: 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

### Changed
Expand Down Expand Up @@ -771,4 +796,5 @@ 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
[#420]: https://github.com/ethdebug/format/pull/420
13 changes: 13 additions & 0 deletions bin/check-changelog.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,19 @@ describe("missingPackageChangelogs", () => {
]);
});

it("ignores test files and JSON data under src", () => {
expect(
missingPackageChangelogs(
[
"packages/pointers/src/read.test.ts",
"packages/pointers/src/read.golden.json",
"packages/format/src/style.css",
],
packagePrefixes,
),
).toEqual(["packages/format/CHANGELOG.md"]);
});

it("omits a package whose CHANGELOG.md is already in the diff", () => {
expect(
missingPackageChangelogs(
Expand Down
5 changes: 5 additions & 0 deletions bin/check-changelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@
// change, and this also covers the *.examples.test.ts suites
const testFile = /\.test\.tsx?(\.snap)?$/;

// tsc copies a JSON file into dist only when code imports it, so a JSON
// file under src (such as data a test reads) is not published by itself
const jsonFile = /\.json$/;

function touchesPackage(changedPaths: string[], prefix: string): boolean {
return changedPaths.some(
(path) =>
!testFile.test(path) &&
!(jsonFile.test(path) && path !== `${prefix}/package.json`) &&
(path.startsWith(`${prefix}/src/`) ||
path.startsWith(`${prefix}/bin/`) ||
path === `${prefix}/package.json`),
Expand Down Expand Up @@ -188,7 +193,7 @@
const base = argv[0] ?? defaultBase;
const root = fileURLToPath(new URL("..", import.meta.url));
if (!resolvesToCommit(root, base)) {
console.error(

Check warning on line 196 in bin/check-changelog.ts

View workflow job for this annotation

GitHub Actions / lint-and-format

Unexpected console statement
`check-changelog: cannot resolve the base ref "${base}"; fetch it` +
" first, or name one that exists.",
);
Expand All @@ -207,10 +212,10 @@
formatProblemsMessage(problems),
].filter((message) => message.length > 0);
if (messages.length > 0) {
console.error(messages.join("\n\n"));

Check warning on line 215 in bin/check-changelog.ts

View workflow job for this annotation

GitHub Actions / lint-and-format

Unexpected console statement
return 1;
}
console.log("changelog: ok");

Check warning on line 218 in bin/check-changelog.ts

View workflow job for this annotation

GitHub Actions / lint-and-format

Unexpected console statement
return 0;
}

Expand Down
66 changes: 0 additions & 66 deletions packages/bugc/src/irgen/debug/templates.golden.json

This file was deleted.

74 changes: 8 additions & 66 deletions packages/bugc/src/irgen/debug/templates.test.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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<string, { reads: number; digest: string }> = 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,
);
}
}
});
8 changes: 8 additions & 0 deletions packages/format/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` ([#411]).

### Changed

- `schemas` parses each schema from YAML on first access instead of at
Expand Down Expand Up @@ -158,6 +165,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
[#420]: https://github.com/ethdebug/format/pull/420
[`0ef2f37`]: https://github.com/ethdebug/format/commit/0ef2f37
[`10ab103`]: https://github.com/ethdebug/format/commit/10ab103
Expand Down
4 changes: 4 additions & 0 deletions packages/format/src/types/pointer/pointer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
22 changes: 21 additions & 1 deletion packages/format/src/types/pointer/pointer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
[
Expand All @@ -26,6 +27,7 @@ export namespace Pointer {
Region.isReturndata,
Region.isTransient,
Region.isCode,
Region.isVirtual,
].some((guard) => guard(value));

export namespace Region {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 =
Expand Down
8 changes: 8 additions & 0 deletions packages/pointers-react/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
8 changes: 8 additions & 0 deletions packages/pointers-react/src/components/RegionMap.css
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions packages/pointers-react/src/components/RegionMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down
4 changes: 4 additions & 0 deletions packages/pointers-react/src/components/RegionOutput.css
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
1 change: 1 addition & 0 deletions packages/pointers-react/src/components/RegionOutput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down
4 changes: 4 additions & 0 deletions packages/pointers-react/src/components/variables.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Loading
Loading