Skip to content

Commit

Permalink
Auto merge of #90842 - pierwill:localdefid-indexmap, r=wesleywiser
Browse files Browse the repository at this point in the history
Use `indexmap` to avoid sorting `LocalDefId`s

See discussion in #90408 (comment).

Related to work on #90317.
  • Loading branch information
bors committed Jan 24, 2022
2 parents 51126be + 4f89224 commit e7825f2
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 31 deletions.
5 changes: 3 additions & 2 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1739,12 +1739,13 @@ dependencies = [

[[package]]
name = "indexmap"
version = "1.7.0"
version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc633605454125dec4b66843673f01c7df2b89479b32e0ed634e43a91cff62a5"
checksum = "282a6247722caba404c065016bbfa522806e51714c34f5dfc3e4a3a46fcb4223"
dependencies = [
"autocfg",
"hashbrown 0.11.2",
"rustc-rayon",
"serde",
]

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_cranelift/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@ checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e"

[[package]]
name = "indexmap"
version = "1.7.0"
version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc633605454125dec4b66843673f01c7df2b89479b32e0ed634e43a91cff62a5"
checksum = "282a6247722caba404c065016bbfa522806e51714c34f5dfc3e4a3a46fcb4223"
dependencies = [
"autocfg",
"hashbrown",
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_cranelift/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ gimli = { version = "0.25.0", default-features = false, features = ["write"]}
object = { version = "0.27.0", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] }

ar = { git = "https://github.com/bjorn3/rust-ar.git", branch = "do_not_remove_cg_clif_ranlib" }
indexmap = "1.0.2"
indexmap = "1.8.0"
libloading = { version = "0.6.0", optional = true }
smallvec = "1.6.1"

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_data_structures/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ doctest = false
[dependencies]
arrayvec = { version = "0.7", default-features = false }
ena = "0.14"
indexmap = "1.5.1"
indexmap = { version = "1.8.0", features = ["rustc-rayon"] }
tracing = "0.1"
jobserver_crate = { version = "0.1.13", package = "jobserver" }
rustc_serialize = { path = "../rustc_serialize" }
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_metadata/src/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1314,7 +1314,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
return;
}

let mut keys_and_jobs = self
let keys_and_jobs = self
.tcx
.mir_keys(())
.iter()
Expand All @@ -1327,8 +1327,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
}
})
.collect::<Vec<_>>();
// Sort everything to ensure a stable order for diagnotics.
keys_and_jobs.sort_by_key(|&(def_id, _, _)| def_id.index());
for (def_id, encode_const, encode_opt) in keys_and_jobs.into_iter() {
debug_assert!(encode_const || encode_opt);

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ rustc_queries! {
/// Set of all the `DefId`s in this crate that have MIR associated with
/// them. This includes all the body owners, but also things like struct
/// constructors.
query mir_keys(_: ()) -> FxHashSet<LocalDefId> {
query mir_keys(_: ()) -> rustc_data_structures::fx::FxIndexSet<LocalDefId> {
storage(ArenaCacheSelector<'tcx>)
desc { "getting a list of all mir_keys" }
}
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_mir_transform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ extern crate rustc_middle;

use required_consts::RequiredConstsVisitor;
use rustc_const_eval::util;
use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::fx::FxIndexSet;
use rustc_data_structures::steal::Steal;
use rustc_hir as hir;
use rustc_hir::def_id::{DefId, LocalDefId};
Expand Down Expand Up @@ -136,8 +136,8 @@ fn is_mir_available(tcx: TyCtxt<'_>, def_id: DefId) -> bool {

/// Finds the full set of `DefId`s within the current crate that have
/// MIR associated with them.
fn mir_keys(tcx: TyCtxt<'_>, (): ()) -> FxHashSet<LocalDefId> {
let mut set = FxHashSet::default();
fn mir_keys(tcx: TyCtxt<'_>, (): ()) -> FxIndexSet<LocalDefId> {
let mut set = FxIndexSet::default();

// All body-owners have MIR associated with them.
set.extend(tcx.hir().body_owners());
Expand All @@ -146,7 +146,7 @@ fn mir_keys(tcx: TyCtxt<'_>, (): ()) -> FxHashSet<LocalDefId> {
// they don't have a BodyId, so we need to build them separately.
struct GatherCtors<'a, 'tcx> {
tcx: TyCtxt<'tcx>,
set: &'a mut FxHashSet<LocalDefId>,
set: &'a mut FxIndexSet<LocalDefId>,
}
impl<'tcx> Visitor<'tcx> for GatherCtors<'_, 'tcx> {
fn visit_variant_data(
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_serialize/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.0.0"
edition = "2021"

[dependencies]
indexmap = "1"
indexmap = "1.8.0"
smallvec = { version = "1.6.1", features = ["union", "may_dangle"] }

[dev-dependencies]
Expand Down
32 changes: 16 additions & 16 deletions src/test/run-make/const_fn_mir/dump.mir
Original file line number Diff line number Diff line change
@@ -1,21 +1,5 @@
// WARNING: This output format is intended for human consumers only
// and is subject to change without notice. Knock yourself out.
fn main() -> () {
let mut _0: (); // return place in scope 0 at main.rs:8:11: 8:11
let _1: i32; // in scope 0 at main.rs:9:5: 9:10

bb0: {
_1 = foo() -> bb1; // scope 0 at main.rs:9:5: 9:10
// mir::Constant
// + span: main.rs:9:5: 9:8
// + literal: Const { ty: fn() -> i32 {foo}, val: Value(Scalar(<ZST>)) }
}

bb1: {
return; // scope 0 at main.rs:10:2: 10:2
}
}

fn foo() -> i32 {
let mut _0: i32; // return place in scope 0 at main.rs:4:19: 4:22

Expand All @@ -40,3 +24,19 @@ fn foo() -> i32 {
return; // scope 0 at main.rs:6:2: 6:2
}
}

fn main() -> () {
let mut _0: (); // return place in scope 0 at main.rs:8:11: 8:11
let _1: i32; // in scope 0 at main.rs:9:5: 9:10

bb0: {
_1 = foo() -> bb1; // scope 0 at main.rs:9:5: 9:10
// mir::Constant
// + span: main.rs:9:5: 9:8
// + literal: Const { ty: fn() -> i32 {foo}, val: Value(Scalar(<ZST>)) }
}

bb1: {
return; // scope 0 at main.rs:10:2: 10:2
}
}

0 comments on commit e7825f2

Please sign in to comment.