Repository navigation
Remove the Graph engine; LayoutTyped returns errors where it fell back (v0.4.0) - #10
Merged
Merged
Conversation
Before the Graph engine goes, record what the typed engine produces so the tests keep checking the same layouts without it. TestGolden runs 14,111 inputs through the typed engine's steps (the D2 corpus, 3,000 D2-shaped random inputs and random inputs with every option and unusual values) and compares each with testdata/golden: the kind of outcome (a layout, an engine error, an input the typed engine does not take, a panic), the number of dummy-name counter draws and a hash of the layout's exact bits. 9,838 of the inputs are laid out. The dagre.js oracle tests (TestLayoutMatchesDagreJS, the D2 corpus and the D2-profile tests) now build LayoutInputs and call LayoutTyped instead of building a Graph, with the same inputs and expected outputs; the two fixtures that test Attrs key spelling and number coercion are left out. Co-Authored-By: Claude Opus 5.5 <[email protected]>
dagro kept two engines: the line-by-line port of dagre's JavaScript (Graph, Attrs, Layout and their phases) and the typed engine behind LayoutTyped, which D2 uses for every diagram. LayoutTyped handed the inputs the typed engine does not take, and the inputs on which it panicked, to the Graph engine. This removes the Graph engine and everything only it used. LayoutTyped now returns: - an error wrapping the new ErrUnsupportedInput where it used to fall back: no nodes, an empty node id or one containing "\x01", repeated node ids, a parent out of range or a parent cycle, an edge endpoint out of range or with children, two edges with the same endpoints and name, and more than 2^26 ranks (the decline, now an error); - a *PanicError (Value = the panic value, Unwrap gives it when it is an error) when the layout panics, including the places where dagre itself fails, which used to panic through to the caller with Go's "assignment to entry in nil map" and now say "dagre fails on this input: it sets "order" on a node missing from a layer". The panic guard covers updateTyped too. The state of a panicked call is dropped. Acyclicer "greedy" ran dagre's greedyFAS on a Graph copy; greedyFAS is now ported onto the typed graph (typed_util.go has it and the few numeric and key-order helpers the engine kept using). Removed exported API: Graph and its methods, NewGraph, GraphOptions, Edge, Attrs, Layout, LayoutOptions, DebugOrdering, Time, NoTime and LayoutInput.Graph. Point moves to typed_api.go unchanged. The tests that compared the two engines go with the Graph engine; TestGolden (14,111 inputs) gives the same results as before this change, and the dagre.js oracle tests, the retention, pool and single-node tests run on LayoutTyped. New tests cover every unsupported-input error, the panic errors and concurrent use. README, UPSTREAM.md and a package doc describe the new API. This is a breaking change, released as v0.4.0. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…endent CI (linux/amd64) found 145 golden differences that the darwin/arm64 recording did not show: NaN payloads in layouts differ between the two, and where a failing layout stops (so how many counter values it drew) depends on Go's platform-dependent conversion of NaN and infinities to int. goldenDump now writes every NaN as "NaN", and a panic's draws are not recorded. A minlen of +Inf converts to a negative int on amd64; TestLayoutTypedDeclinesHugeRanks accepts that layout failure there. The new golden files were recorded with this change's code and, separately, with v0.3.1's typed engine (the first commit with this golden format): the two sets of files are identical. Co-Authored-By: Claude Opus 5.5 <[email protected]>
alixander
force-pushed
the
perf/typed-only
branch
from
November 26, 2026 02:47
bee9df0 to
20bc94d
Compare
This was referenced Nov 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
dagro had two engines: the line-by-line port of dagre's JavaScript (
Graph,Attrs,Layoutand their phases) and the typed engine behindLayoutTyped, which D2 uses for every diagram.LayoutTypedhanded inputs the typed engine does not take, and inputs on which it panicked, to the Graph engine. This removes the Graph engine (supersedes #9, which only made it optional behind a build tag).Commit 1 pins the typed engine before anything is deleted.
TestGoldenruns 14,111 inputs (the 311-input D2 corpus, 3,000 D2-shaped random inputs, and random inputs with every option and unusual values) through v0.3.1's typed engine and records, per input, the kind of outcome, the dummy-name counter draws and a hash of the layout's exact bits intestdata/golden. 9,838 of them are laid out (605 with acyclicergreedy). The dagre.js oracle tests (D2 corpus, D2-profile compatibility oracle,TestLayoutMatchesDagreJS) now buildLayoutInputs and callLayoutTyped.Commit 2 removes the Graph engine. The golden files are unchanged by it: every input gets the same result.
LayoutTypednow returnsErrUnsupportedInputwhere it used to fall back: no nodes, an empty node id or one containing"\x01", repeated ids, a parent out of range or a parent cycle, an edge endpoint out of range or with children, two edges with the same endpoints and name, more than 2^26 ranks;*PanicErrorwhen the layout panics, including where dagre itself fails (these used to panic through to the caller withassignment to entry in nil map). The guard also covers writing the output.greedyFAS(acyclicergreedy) used a Graph copy; it is now ported onto the typed graph, checked by the 605 golden greedy layouts andTestLayoutMatchesDagreJS/cycle-greedy.Removed API:
Graphand its methods,NewGraph,GraphOptions,Edge,Attrs,Layout,LayoutOptions,DebugOrdering,Time,NoTime,LayoutInput.Graph. Breaking: to be tagged v0.4.0.Local checks:
go test ./...,go test -race ./...,go vet ./...,GOOS=js GOARCH=wasm go build ./..., the js/wasmTestD2ProfileRandomLayoutsAreFiniterun, andTestLayoutMatchesDagreJSwith the dagre 3.1.1 bundle all pass.🤖 Generated with Claude Code