about summary refs log tree commit diff
path: root/compiler/rustc_llvm/llvm-wrapper/CoverageMappingWrapper.cpp
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-06-20 07:53:57 +0000
committerbors <bors@rust-lang.org>2024-06-20 07:53:57 +0000
commit153a2bab588fe13467d9de9626fe9f67b5fa18ea (patch)
treec61322c5f02a2180505e6eb45aca732409543557 /compiler/rustc_llvm/llvm-wrapper/CoverageMappingWrapper.cpp
parentf18fe6c437b0fbaa45bd2e5253d0c40c45189833 (diff)
parent185971c47da0c72c847e3d15504b194a002e2b8c (diff)
downloadrust-153a2bab588fe13467d9de9626fe9f67b5fa18ea.tar.gz
rust-153a2bab588fe13467d9de9626fe9f67b5fa18ea.zip
Auto merge of #17457 - roife:remove-circle, r=Veykril
fix: ensure there are no cycles in the source_root_parent_map

See #17409

We can view the connections between roots as a graph. The problem is that this graph may contain cycles, so when adding edges, it is necessary to check whether it will lead to a cycle.

Since we ensure that each node has at most one outgoing edge (because each SourceRoot can have only one parent), we can use a disjoint-set to maintain the connectivity between nodes. If an edge’s two nodes belong to the same set, they are already connected.

Additionally, this PR includes the following three changes:

1. Removed the workaround from #17409.
2. Added an optimization: If `map.contains_key(&SourceRootId(*root_id as u32))`, we can skip the current loop iteration since we have already found its parent.
3. Modified the inner loop to iterate in reverse order with `roots[..idx].iter().rev()` at line 319. This ensures that if we are looking for the parent of `a/b/c`, and both `a` and `a/b` meet the criteria, we will choose the longer match (`a/b`).
Diffstat (limited to 'compiler/rustc_llvm/llvm-wrapper/CoverageMappingWrapper.cpp')
0 files changed, 0 insertions, 0 deletions