Skip to content

Conversation

@tautschnig
Copy link
Collaborator

The root cause was in the topological sort implementation. The dfs() method enforced that seen and inserted sets must be empty on entry (via PRECONDITION) and would clear them on exit. However, topological_sort() calls dfs() multiple times in a loop for each item in the input collection. This meant only the first item was sorted correctly; subsequent items would fail the precondition or produce incorrect results.

The fix moves the set clearing logic to the beginning of topological_sort(), ensuring a fresh DFS traversal for the entire collection while allowing the DFS to maintain state across recursive calls within a single item's dependency graph.

Co-authored-by: Kiro autonomous agent

Fixes: #4978

  • Each commit message has a non-empty body, explaining why the change was made.
  • n/a Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • n/a The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/
  • Regression or unit tests are included, or existing tests cover the modified code (in this case I have detailed which ones those are in the commit message).
  • n/a My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • n/a White-space or formatting changes outside the feature-related changed lines are in commits of their own.

The root cause was in the topological sort implementation. The `dfs()`
method enforced that seen and inserted sets must be empty on entry (via
`PRECONDITION`) and would clear them on exit. However,
`topological_sort()` calls `dfs()` multiple times in a loop for each
item in the input collection. This meant only the first item was sorted
correctly; subsequent items would fail the precondition or produce
incorrect results.

The fix moves the set clearing logic to the beginning of
`topological_sort()`, ensuring a fresh DFS traversal for the entire
collection while allowing the DFS to maintain state across recursive
calls within a single item's dependency graph.

Co-authored-by: Kiro autonomous agent

Fixes: diffblue#4978
@tautschnig tautschnig force-pushed the fix-4978-snapshot-init branch from 1e25c00 to f154c3e Compare December 9, 2025 14:59
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.

Snapshot-harness may initialise variables in the wrong order

1 participant