Skip to content

Switch topological sort to SCC in condition extraction.#207

Merged
garretrieger merged 1 commit intow3c:mainfrom
garretrieger:scc
Apr 10, 2026
Merged

Switch topological sort to SCC in condition extraction.#207
garretrieger merged 1 commit intow3c:mainfrom
garretrieger:scc

Conversation

@garretrieger
Copy link
Copy Markdown
Contributor

@garretrieger garretrieger commented Apr 10, 2026

Dependency graphs can have cycles within a closure phase (for example bidi mirror dependencies naturally form cycles). Since topological sorting can't handle cycles a different approach is needed.

In condition extraction topological sorting is swapped out with a strongly connected component finding algorithm (Tarjan's, ref: https://en.wikipedia.org/wiki/Tarjan%27s_strongly_connected_components_algorithm). This returns a topological sorting of strongly connected components. When the dependency graph is a DAG this gives the exact same behaviour as the prior topological sorting based implementation. To handle the cycles within a strongly connected component condition propagation has been modified to iteratively propagate conditions inside a component until they stabilize.

New high level algorithm:

  • Generate a topological sorting of strongly connected components of the dep graph.
  • Generate a list of incoming edge conditions for each node. Where a condition is a CNF boolean expression in terms of other nodes.
  • Working in topological order for each component iteratively resolve node conditions by combining the incoming edge conditions on each node. Simplify the combined condition to CNF. Repeat until stable conditions are formed within the component.
  • Repeat this process for each closure phase.

Dependency graphs can have cycles within a closure phase (for example bidi mirror dependencies naturally form cycles). Since topological sorting can't handle cycles a different approach is needed.

In condition extraction topological sorting is swapped out with a strongly connected component finding algorithm (Tarjan's, ref: https://en.wikipedia.org/wiki/Tarjan%27s_strongly_connected_components_algorithm). This returns a topological sorting of strongly connected components. When the dependency graph is a DAG this gives the exact same behaviour as the prior topological sorting based implementation. To handle the cycles within a strongly connected component condition propagation has been modified to iteratively propagate conditions inside a component until they stabilize.
@garretrieger garretrieger merged commit ae44e7f into w3c:main Apr 10, 2026
3 checks passed
@garretrieger garretrieger deleted the scc branch April 10, 2026 23:34
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.

1 participant