Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 10b0e2d

Browse files
committedMar 25, 2025
Auto merge of rust-lang#138871 - smoelius:librustdoc-fx-index-map, r=<try>
Change one `FxHashMap` to `FxIndexMap` in librustdoc This PR changes one `FxHashMap` to `FxIndexMap` in librustdoc's cache and adds a comment explaining why (i.e., to promote reproducibility across operating systems). I have been [trying to understand](rust-lang/rustdoc-types#44) why the following command produces different results on Linux and MacOS when run on a project whose lib.rs contains only `#![no_std]`: ```sh cargo rustdoc --target x86_64-unknown-linux-gnu -Zbuild-std -- -Z unstable-options --output-format=json ``` I obtained a partial answer in that elements were being read out of this `FxHashMap` in different orders, even when the elements were inserted in the same order: https://github.com/rust-lang/rust/blob/aa8f0fd7163a2f23aa958faed30c9c2b77b934a5/src/librustdoc/formats/cache.rs#L50 I [opened an issue](rust-lang/hashbrown#612) on the Hashbrown repo to see whether this was a bug. The response I got was that if one wants the elements to be read out in the same order, one should use something like `FxIndexMap`. cc: `@aDotInTheVoid`
2 parents 43f0014 + fb97d2f commit 10b0e2d

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed
 

‎src/librustdoc/formats/cache.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ use crate::visit_lib::RustdocEffectiveVisibilities;
2828
/// to be a fairly large and expensive structure to clone. Instead this adheres
2929
/// to `Send` so it may be stored in an `Arc` instance and shared among the various
3030
/// rendering threads.
31+
///
32+
/// To promote reproducibility across operating systems, this structure
33+
/// intentionally does not use [`rustc_data_structures::fx::FxHashMap`].
34+
/// Elements can be stored in deferent orders in an `FxHashMap`, even if the
35+
/// elements are inserted in the same order. Wherever an `FxHashMap` would be
36+
/// needed, an [`rustc_data_structures::fx::FxIndexMap`] is used instead.
3137
#[derive(Default)]
3238
pub(crate) struct Cache {
3339
/// Maps a type ID to all known implementations for that type. This is only
@@ -47,7 +53,7 @@ pub(crate) struct Cache {
4753

4854
/// Similar to `paths`, but only holds external paths. This is only used for
4955
/// generating explicit hyperlinks to other crates.
50-
pub(crate) external_paths: FxHashMap<DefId, (Vec<Symbol>, ItemType)>,
56+
pub(crate) external_paths: FxIndexMap<DefId, (Vec<Symbol>, ItemType)>,
5157

5258
/// Maps local `DefId`s of exported types to fully qualified paths.
5359
/// Unlike 'paths', this mapping ignores any renames that occur

0 commit comments

Comments
 (0)
Failed to load comments.