/** * Topological sort over a per-variable init dep graph (built by * `initDepGraph.ts`). * * On success: returns the init order — every node appears after all of * its deps. On a cycle in the variable graph: returns a structured * `CycleError` listing the cycle path so Task 3 can render a clean * compile-time error. * * Ordering rule: var-level edges always win. For nodes the edges leave * unordered, sort by each node's pre-computed `sequenceHint` (built * from the file-import-DAG depth + source line by the graph builder). * One ordering key, one consumer. * * Implementation: Kahn's algorithm; the "ready" bag is sorted by * sequenceHint between iterations. N (top-level decls in the closure) * is small enough that a per-round `.sort()` reads more clearly than a * hand-rolled priority queue. */ import type { InitDepGraph, InitVarKey, InitVarNode } from "./initDepGraph.js"; export type CycleError = { kind: "cycle"; /** Representative cycle: each node depends on the next; the last * depends on the first. */ cycle: InitVarNode[]; }; export type TopSortResult = { kind: "ok"; order: InitVarKey[]; } | CycleError; export declare function topSortInitGraph(graph: InitDepGraph): TopSortResult;