Skip to content

Commit

Permalink
Rollup merge of rust-lang#129124 - aDotInTheVoid:rdj-hashmap-3, r=Gui…
Browse files Browse the repository at this point in the history
…llaumeGomez

rustdoc-json: Use FxHashMap from rustdoc_json_types

Alternative to rust-lang#110051 and rust-lang#127456.

This lets us avoid rehashing the json index after building it by using the same hashmap type in construction and in rustdoc_json_types. The above PR's tried to do this by having rustdoc_json_types get the same hashmap that rustdoc has via rustc_data_structures. However, this can be made simpler if we change rustdoc instead.

For the rustdoc-type republish on crates.io, It will filter out the `pub use`, and not change source at all. rust-lang/rustdoc-types#30. That code [already replaces the hashmap](https://github.com/aDotInTheVoid/rustdoc-types/blob/8d6528669ec64c2af43d1c79a228b7711cefdad7/update.sh#L11) to use the one in `std::collections` (instead of `FxHashMap`)

try-job: dist-arm-linux

r? ``@GuillaumeGomez``
  • Loading branch information
matthiaskrgr authored Aug 15, 2024
2 parents bc986c7 + 9028b53 commit ef72a6a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/librustdoc/json/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ use std::io::{stdout, BufWriter, Write};
use std::path::PathBuf;
use std::rc::Rc;

use rustc_data_structures::fx::FxHashMap;
use rustc_hir::def_id::{DefId, DefIdSet};
use rustc_middle::ty::TyCtxt;
use rustc_session::Session;
use rustc_span::def_id::LOCAL_CRATE;
use rustdoc_json_types as types;
// It's important to use the FxHashMap from rustdoc_json_types here, instead of
// the one from rustc_data_structures, as they're different types due to sysroots.
// See #110051 and #127456 for details
use rustdoc_json_types::FxHashMap;

use crate::clean::types::{ExternalCrate, ExternalLocation};
use crate::clean::ItemKind;
Expand Down Expand Up @@ -234,14 +237,11 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
let index = (*self.index).clone().into_inner();

debug!("Constructing Output");
// This needs to be the default HashMap for compatibility with the public interface for
// rustdoc-json-types
#[allow(rustc::default_hash_types)]
let output = types::Crate {
root: types::Id(format!("0:0:{}", e.name(self.tcx).as_u32())),
crate_version: self.cache.crate_version.clone(),
includes_private: self.cache.document_private,
index: index.into_iter().collect(),
index,
paths: self
.cache
.paths
Expand Down
2 changes: 1 addition & 1 deletion src/rustdoc-json-types/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

use std::path::PathBuf;

use rustc_hash::FxHashMap;
pub use rustc_hash::FxHashMap;
use serde::{Deserialize, Serialize};

/// The version of JSON output that this crate represents.
Expand Down

0 comments on commit ef72a6a

Please sign in to comment.