Skip to content

Make LinkedGraph modification order independent#151821

Open
zetanumbers wants to merge 6 commits intorust-lang:mainfrom
zetanumbers:out-of-order-linked-graph
Open

Make LinkedGraph modification order independent#151821
zetanumbers wants to merge 6 commits intorust-lang:mainfrom
zetanumbers:out-of-order-linked-graph

Conversation

@zetanumbers
Copy link
Contributor

@zetanumbers zetanumbers commented Jan 29, 2026

LinkedGraph is a graph data structure used by DepGraphQuery for -Zquery-dep-graph and by RegionGraph for lexical region resolution. Current DepGraphQuery implementation is problematic for our parallel frontend as some edges could be added before their source or target nodes, which never happens in single-threaded mode. To solve this I've made two changes:

  1. Adding an edge to DepGraphQuery looks up its target node in dep_index_to_index to translate query system's DepNodeIndex into LinkedGraph's newtype NodeIndex for usize to index nodes. For both DepGraphQuery and RegionGraph nodes correspond one-to-one to DepNodeIndex's and RegionVid's indices. Those types are defined by the rustc_index::newtype_index! macro and implement Idx trait, so instead of using NodeIndex and Vec<Node<N>> I've changed it to use a generic I: Idx type and IndexVec<I, Node<N>>. Thus field dep_index_to_index is no longer required.
  2. Adding an edge to LinkedGraph requires its target and source nodes to already be present in the graph in order to construct a linked list of edge indices for fast iteration of edges. As such I've added code to postpone linked list construction in case source/target node was not present and count linked_edges up to now. Upon creation of an AdjacentEdges iterator there's an assertion that every edge is linked.

Fixes #142152

@rustbot rustbot added A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 29, 2026
@rustbot
Copy link
Collaborator

rustbot commented Jan 29, 2026

r? @mati865

rustbot has assigned @mati865.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rust-log-analyzer

This comment has been minimized.

@zetanumbers
Copy link
Contributor Author

r? @petrochenkov

Updated the issue's top comment to include detailed description of changes.

@rustbot rustbot assigned petrochenkov and unassigned mati865 Feb 2, 2026
@zetanumbers zetanumbers force-pushed the out-of-order-linked-graph branch from f0938a3 to 1dd0c95 Compare February 4, 2026 14:25
@rust-log-analyzer

This comment has been minimized.

@zetanumbers zetanumbers force-pushed the out-of-order-linked-graph branch from 1dd0c95 to 264aa3a Compare February 5, 2026 10:34
@rust-bors
Copy link
Contributor

rust-bors bot commented Feb 5, 2026

☔ The latest upstream changes (presumably #152156) made this pull request unmergeable. Please resolve the merge conflicts.

@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-tools failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
REPOSITORY                                   TAG       IMAGE ID       CREATED      SIZE
ghcr.io/dependabot/dependabot-updater-core   latest    bcec0b4e062b   9 days ago   783MB
=> Removing docker images...
Deleted Images:
untagged: ghcr.io/dependabot/dependabot-updater-core:latest
untagged: ghcr.io/dependabot/dependabot-updater-core@sha256:b662be51f7b8ef7e2c8464428f14e49cb79c36aa9afb7ecb9221dfe0f507050c
deleted: sha256:bcec0b4e062b5ffe11cc1c2729558c0cd96621c0271ab5e97ff3a56e0c25045a
deleted: sha256:64e147d5e54d9be8b8aa322e511cda02296eda4b8b8d063c6a314833aca50e29
deleted: sha256:5cba409bb463f4e7fa1a19f695450170422582c1bc7c0e934d893b4e5f558bc6
deleted: sha256:cddc6ebd344b0111eaab170ead1dfda24acdfe865ed8a12599a34d338fa8e28b
deleted: sha256:2412c3f334d79134573cd45e657fb6cc0abd75bef3881458b0d498d936545c8d
---
tests/ui/double_parens.rs ... ok
tests/ui/drop_non_drop.rs ... ok
tests/ui/duplicate_underscore_argument.rs ... ok
tests/ui/duplicated_attributes.rs ... ok
tests/ui/duration_suboptimal_units.rs ... ok
tests/ui/duration_suboptimal_units_days_weeks.rs ... ok
tests/ui/duration_subsec.rs ... ok
tests/ui/double_parens.fixed ... ok
tests/ui/duration_suboptimal_units.fixed ... ok
tests/ui/duration_suboptimal_units_days_weeks.fixed ... ok
tests/ui/duration_subsec.fixed ... ok
tests/ui/else_if_without_else.rs ... ok
tests/ui/empty_docs.rs ... ok
tests/ui/elidable_lifetime_names.rs ... ok
tests/ui/eager_transmute.rs ... ok
---
...............................................    (147/147)

======== tests/rustdoc-gui/search-filter.goml ========

[ERROR] line 48: Error: The CSS selector "#search-tabs .count.loading" still exists: for command `wait-for-false: "#search-tabs .count.loading"`
    at <file:///checkout/obj/build/x86_64-unknown-linux-gnu/test/rustdoc-gui/doc/test_docs/index.html?search=test>

======== tests/rustdoc-gui/search-result-display.goml ========

[WARNING] line 39: Delta is 0 for "x", maybe try to use `compare-elements-position` instead?

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

Labels

A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ICE compiler/rustc_query_system/src/dep_graph/query.rs index out of bounds

5 participants