Skip to content

format: evaluate a scope's define in dependency order - #408

Open
gnidan wants to merge 4 commits into
mainfrom
format-define-order
Open

gnidan wants to merge 4 commits into
mainfrom
format-define-order

Conversation

@gnidan

@gnidan gnidan commented Nov 10, 2026

Copy link
Copy Markdown
Member

Closes #401. Stacked on #404.

The scope schema said define variables are evaluated in order, so later ones may use earlier ones. JSON objects are unordered, so tools that sort keys broke such pointers. This change makes member order irrelevant:

  • A name in a variable's expression that matches another member of the same define means that member.
  • A name that matches the variable itself means the variable with that name in the enclosing scope, so a variable never depends on itself ({slot: {~sum: [slot, 1]}} still means the outer slot plus 1).
  • Any other name means a variable of the enclosing scope.

A consumer evaluates each member after the members it uses; a cycle makes the pointer invalid.

@ethdebug/pointers follows the precedent of region fields that refer to each other through ~this: processScope queues the members and retries one that uses a member not evaluated yet, and throws "Circular reference detected" when every remaining member has failed since the last success. Each member sees its siblings through a view of the outer variables, so a sibling name never falls back to the outer variable before that sibling is evaluated.

The long string storage example in ethdebug/format/pointer now lists total-slots before the string-length it uses, so the pointers integration test resolves an out-of-order define on a real trace. The scope schema gains a small example of both an out-of-order member and a member's own name meaning the outer variable, and the web docs no longer say JSON objects are ordered.

gnidan added a commit that referenced this pull request Nov 10, 2026
@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.2

QR code for preview link

🚀 View preview at
https://ethdebug.github.io/format/pr-preview/pr-408/

Built to branch gh-pages at 2026-11-10 08:28 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

gnidan added a commit that referenced this pull request Nov 10, 2026
@gnidan
gnidan force-pushed the format-define-order branch from de6be9b to 8c2b29a Compare November 10, 2026 06:09
@gnidan
gnidan changed the base branch from format-variable-sorts to main November 10, 2026 06:09
A member sees the other members of the same define by name, and its
own name means the variable of the enclosing scope. Members are queued
and retried, as region fields are for ~this; a cycle throws.
JSON objects are unordered, so the members of a define may use each
other in any order. Reorder the long string example's define so the
integration test resolves a member before the one it uses.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Scope definitions should not depend on JSON member order

1 participant