Skip to content

Commit

Permalink
rustc: remove "GlobalMetaData" dead code from hir::map::definitions.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Nov 5, 2019
1 parent 2e4da3c commit 2595332
Show file tree
Hide file tree
Showing 29 changed files with 116 additions and 201 deletions.
90 changes: 3 additions & 87 deletions src/librustc/hir/map/definitions.rs
Expand Up @@ -19,7 +19,7 @@ use std::hash::Hash;
use syntax::ast;
use syntax_pos::symbol::{Symbol, sym};
use syntax_pos::hygiene::ExpnId;
use syntax_pos::{Span, DUMMY_SP};
use syntax_pos::Span;

/// The `DefPathTable` maps `DefIndex`es to `DefKey`s and vice versa.
/// Internally the `DefPathTable` holds a tree of `DefKey`s, where each `DefKey`
Expand Down Expand Up @@ -310,10 +310,6 @@ pub enum DefPathData {
AnonConst,
/// An `impl Trait` type node.
ImplTrait,
/// Identifies a piece of crate metadata that is global to a whole crate
/// (as opposed to just one item). `GlobalMetaData` components are only
/// supposed to show up right below the crate root.
GlobalMetaData(Symbol),
}

#[derive(Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord, Debug,
Expand Down Expand Up @@ -444,9 +440,6 @@ impl Definitions {
self.node_to_def_index.insert(ast::CRATE_NODE_ID, root_index);
self.set_invocation_parent(ExpnId::root(), root_index);

// Allocate some other `DefIndex`es that always must exist.
GlobalMetaDataKind::allocate_def_indices(self);

root_index
}

Expand Down Expand Up @@ -553,8 +546,7 @@ impl DefPathData {
TypeNs(name) |
ValueNs(name) |
MacroNs(name) |
LifetimeNs(name) |
GlobalMetaData(name) => Some(name),
LifetimeNs(name) => Some(name),

Impl |
CrateRoot |
Expand All @@ -572,8 +564,7 @@ impl DefPathData {
TypeNs(name) |
ValueNs(name) |
MacroNs(name) |
LifetimeNs(name) |
GlobalMetaData(name) => {
LifetimeNs(name) => {
name
}
// Note that this does not show up in user print-outs.
Expand All @@ -591,78 +582,3 @@ impl DefPathData {
self.as_symbol().to_string()
}
}

// We define the `GlobalMetaDataKind` enum with this macro because we want to
// make sure that we exhaustively iterate over all variants when registering
// the corresponding `DefIndex`es in the `DefTable`.
macro_rules! define_global_metadata_kind {
(pub enum GlobalMetaDataKind {
$($variant:ident),*
}) => (
pub enum GlobalMetaDataKind {
$($variant),*
}

impl GlobalMetaDataKind {
fn allocate_def_indices(definitions: &mut Definitions) {
$({
let instance = GlobalMetaDataKind::$variant;
definitions.create_def_with_parent(
CRATE_DEF_INDEX,
ast::DUMMY_NODE_ID,
DefPathData::GlobalMetaData(instance.name()),
ExpnId::root(),
DUMMY_SP
);

// Make sure calling `def_index` does not crash.
instance.def_index(&definitions.table);
})*
}

pub fn def_index(&self, def_path_table: &DefPathTable) -> DefIndex {
let def_key = DefKey {
parent: Some(CRATE_DEF_INDEX),
disambiguated_data: DisambiguatedDefPathData {
data: DefPathData::GlobalMetaData(self.name()),
disambiguator: 0,
}
};

// These `DefKey`s are all right after the root,
// so a linear search is fine.
let index = def_path_table.index_to_key
.iter()
.position(|k| *k == def_key)
.unwrap();

DefIndex::from(index)
}

fn name(&self) -> Symbol {

let string = match *self {
$(
GlobalMetaDataKind::$variant => {
concat!("{{GlobalMetaData::", stringify!($variant), "}}")
}
)*
};

Symbol::intern(string)
}
}
)
}

define_global_metadata_kind!(pub enum GlobalMetaDataKind {
Krate,
CrateDeps,
DylibDependencyFormats,
LangItems,
LangItemsMissing,
NativeLibraries,
SourceMap,
Impls,
ExportedSymbols
});
3 changes: 1 addition & 2 deletions src/librustc_codegen_utils/symbol_names/v0.rs
Expand Up @@ -601,8 +601,7 @@ impl Printer<'tcx> for SymbolMangler<'tcx> {
| DefPathData::Misc
| DefPathData::Impl
| DefPathData::MacroNs(_)
| DefPathData::LifetimeNs(_)
| DefPathData::GlobalMetaData(_) => {
| DefPathData::LifetimeNs(_) => {
bug!("symbol_names: unexpected DefPathData: {:?}", disambiguated_data.data)
}
};
Expand Down
10 changes: 5 additions & 5 deletions src/test/mir-opt/graphviz.rs
Expand Up @@ -7,14 +7,14 @@ fn main() {}

// END RUST SOURCE
// START rustc.main.mir_map.0.dot
// digraph Mir_0_12 { // The name here MUST be an ASCII identifier.
// digraph Mir_0_3 { // The name here MUST be an ASCII identifier.
// graph [fontname="monospace"];
// node [fontname="monospace"];
// edge [fontname="monospace"];
// label=<fn main() -&gt; ()<br align="left"/>>;
// bb0__0_12 [shape="none", label=<<table border="0" cellborder="1" cellspacing="0"><tr><td bgcolor="gray" align="center" colspan="1">0</td></tr><tr><td align="left" balign="left">_0 = ()<br/></td></tr><tr><td align="left">goto</td></tr></table>>];
// bb1__0_12 [shape="none", label=<<table border="0" cellborder="1" cellspacing="0"><tr><td bgcolor="gray" align="center" colspan="1">1</td></tr><tr><td align="left">resume</td></tr></table>>];
// bb2__0_12 [shape="none", label=<<table border="0" cellborder="1" cellspacing="0"><tr><td bgcolor="gray" align="center" colspan="1">2</td></tr><tr><td align="left">return</td></tr></table>>];
// bb0__0_12 -> bb2__0_12 [label=""];
// bb0__0_3 [shape="none", label=<<table border="0" cellborder="1" cellspacing="0"><tr><td bgcolor="gray" align="center" colspan="1">0</td></tr><tr><td align="left" balign="left">_0 = ()<br/></td></tr><tr><td align="left">goto</td></tr></table>>];
// bb1__0_3 [shape="none", label=<<table border="0" cellborder="1" cellspacing="0"><tr><td bgcolor="gray" align="center" colspan="1">1</td></tr><tr><td align="left">resume</td></tr></table>>];
// bb2__0_3 [shape="none", label=<<table border="0" cellborder="1" cellspacing="0"><tr><td bgcolor="gray" align="center" colspan="1">2</td></tr><tr><td align="left">return</td></tr></table>>];
// bb0__0_3 -> bb2__0_3 [label=""];
// }
// END rustc.main.mir_map.0.dot
2 changes: 1 addition & 1 deletion src/test/mir-opt/inline-closure-borrows-arg.rs
Expand Up @@ -20,7 +20,7 @@ fn foo<T: Copy>(_t: T, q: &i32) -> i32 {
// ...
// bb0: {
// ...
// _3 = [closure@HirId { owner: DefIndex(13), local_id: 31 }];
// _3 = [closure@HirId { owner: DefIndex(4), local_id: 31 }];
// ...
// _4 = &_3;
// ...
Expand Down
2 changes: 1 addition & 1 deletion src/test/mir-opt/inline-closure.rs
Expand Up @@ -16,7 +16,7 @@ fn foo<T: Copy>(_t: T, q: i32) -> i32 {
// ...
// bb0: {
// ...
// _3 = [closure@HirId { owner: DefIndex(13), local_id: 15 }];
// _3 = [closure@HirId { owner: DefIndex(4), local_id: 15 }];
// ...
// _4 = &_3;
// ...
Expand Down
2 changes: 1 addition & 1 deletion src/test/mir-opt/retag.rs
Expand Up @@ -100,7 +100,7 @@ fn main() {
// }
// END rustc.main.EraseRegions.after.mir
// START rustc.main-{{closure}}.EraseRegions.after.mir
// fn main::{{closure}}#0(_1: &[closure@HirId { owner: DefIndex(22), local_id: 72 }], _2: &i32) -> &i32 {
// fn main::{{closure}}#0(_1: &[closure@HirId { owner: DefIndex(13), local_id: 72 }], _2: &i32) -> &i32 {
// ...
// bb0: {
// Retag([fn entry] _1);
Expand Down
Expand Up @@ -4,7 +4,7 @@ note: No external requirements
LL | let mut closure = expect_sig(|p, y| *p = y);
| ^^^^^^^^^^^^^
|
= note: defining type: DefId(0:13 ~ escape_argument_callee[317d]::test[0]::{{closure}}[0]) with closure substs [
= note: defining type: DefId(0:4 ~ escape_argument_callee[317d]::test[0]::{{closure}}[0]) with closure substs [
i16,
for<'r, 's, 't0> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 'r)) mut &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 's)) i32, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 't0)) i32)),
]
Expand All @@ -30,7 +30,7 @@ LL | | deref(p);
LL | | }
| |_^
|
= note: defining type: DefId(0:12 ~ escape_argument_callee[317d]::test[0]) with substs []
= note: defining type: DefId(0:3 ~ escape_argument_callee[317d]::test[0]) with substs []

error: aborting due to previous error

4 changes: 2 additions & 2 deletions src/test/ui/nll/closure-requirements/escape-argument.stderr
Expand Up @@ -4,7 +4,7 @@ note: No external requirements
LL | let mut closure = expect_sig(|p, y| *p = y);
| ^^^^^^^^^^^^^
|
= note: defining type: DefId(0:13 ~ escape_argument[317d]::test[0]::{{closure}}[0]) with closure substs [
= note: defining type: DefId(0:4 ~ escape_argument[317d]::test[0]::{{closure}}[0]) with closure substs [
i16,
for<'r, 's> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 'r)) mut &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 's)) i32, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 's)) i32)),
]
Expand All @@ -21,7 +21,7 @@ LL | | deref(p);
LL | | }
| |_^
|
= note: defining type: DefId(0:12 ~ escape_argument[317d]::test[0]) with substs []
= note: defining type: DefId(0:3 ~ escape_argument[317d]::test[0]) with substs []

error[E0597]: `y` does not live long enough
--> $DIR/escape-argument.rs:27:25
Expand Down
Expand Up @@ -4,7 +4,7 @@ note: External requirements
LL | let mut closure1 = || p = &y;
| ^^^^^^^^^
|
= note: defining type: DefId(0:14 ~ escape_upvar_nested[317d]::test[0]::{{closure}}[0]::{{closure}}[0]) with closure substs [
= note: defining type: DefId(0:5 ~ escape_upvar_nested[317d]::test[0]::{{closure}}[0]::{{closure}}[0]) with closure substs [
i16,
extern "rust-call" fn(()),
&'_#1r i32,
Expand All @@ -23,7 +23,7 @@ LL | | closure1();
LL | | };
| |_________^
|
= note: defining type: DefId(0:13 ~ escape_upvar_nested[317d]::test[0]::{{closure}}[0]) with closure substs [
= note: defining type: DefId(0:4 ~ escape_upvar_nested[317d]::test[0]::{{closure}}[0]) with closure substs [
i16,
extern "rust-call" fn(()),
&'_#1r i32,
Expand All @@ -44,7 +44,7 @@ LL | | deref(p);
LL | | }
| |_^
|
= note: defining type: DefId(0:12 ~ escape_upvar_nested[317d]::test[0]) with substs []
= note: defining type: DefId(0:3 ~ escape_upvar_nested[317d]::test[0]) with substs []

error[E0597]: `y` does not live long enough
--> $DIR/escape-upvar-nested.rs:21:40
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/nll/closure-requirements/escape-upvar-ref.stderr
Expand Up @@ -4,7 +4,7 @@ note: External requirements
LL | let mut closure = || p = &y;
| ^^^^^^^^^
|
= note: defining type: DefId(0:13 ~ escape_upvar_ref[317d]::test[0]::{{closure}}[0]) with closure substs [
= note: defining type: DefId(0:4 ~ escape_upvar_ref[317d]::test[0]::{{closure}}[0]) with closure substs [
i16,
extern "rust-call" fn(()),
&'_#1r i32,
Expand All @@ -25,7 +25,7 @@ LL | | deref(p);
LL | | }
| |_^
|
= note: defining type: DefId(0:12 ~ escape_upvar_ref[317d]::test[0]) with substs []
= note: defining type: DefId(0:3 ~ escape_upvar_ref[317d]::test[0]) with substs []

error[E0597]: `y` does not live long enough
--> $DIR/escape-upvar-ref.rs:23:35
Expand Down
Expand Up @@ -8,7 +8,7 @@ LL | | demand_y(x, y, p)
LL | | },
| |_________^
|
= note: defining type: DefId(0:27 ~ propagate_approximated_fail_no_postdom[317d]::supply[0]::{{closure}}[0]) with closure substs [
= note: defining type: DefId(0:18 ~ propagate_approximated_fail_no_postdom[317d]::supply[0]::{{closure}}[0]) with closure substs [
i16,
for<'r, 's> extern "rust-call" fn((std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 'r)) u32>, std::cell::Cell<&'_#2r &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 'r)) u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 's)) &'_#3r u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 'r)) u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 's)) u32>)),
]
Expand Down Expand Up @@ -39,7 +39,7 @@ LL | | );
LL | | }
| |_^
|
= note: defining type: DefId(0:23 ~ propagate_approximated_fail_no_postdom[317d]::supply[0]) with substs []
= note: defining type: DefId(0:14 ~ propagate_approximated_fail_no_postdom[317d]::supply[0]) with substs []

error: aborting due to previous error

Expand Up @@ -9,7 +9,7 @@ LL | |
LL | | });
| |_____^
|
= note: defining type: DefId(0:25 ~ propagate_approximated_ref[317d]::supply[0]::{{closure}}[0]) with closure substs [
= note: defining type: DefId(0:16 ~ propagate_approximated_ref[317d]::supply[0]::{{closure}}[0]) with closure substs [
i16,
for<'r, 's, 't0, 't1, 't2, 't3> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 'r)) std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 's)) u32>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 't0)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 't1)) &'_#2r u32>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 't2)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 's)) u32>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 't3)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 't1)) u32>)),
]
Expand All @@ -30,7 +30,7 @@ LL | | });
LL | | }
| |_^
|
= note: defining type: DefId(0:22 ~ propagate_approximated_ref[317d]::supply[0]) with substs []
= note: defining type: DefId(0:13 ~ propagate_approximated_ref[317d]::supply[0]) with substs []

error: lifetime may not live long enough
--> $DIR/propagate-approximated-ref.rs:45:9
Expand Down
Expand Up @@ -8,7 +8,7 @@ LL | |
LL | | })
| |_____^
|
= note: defining type: DefId(0:18 ~ propagate_approximated_shorter_to_static_comparing_against_free[317d]::case1[0]::{{closure}}[0]) with closure substs [
= note: defining type: DefId(0:9 ~ propagate_approximated_shorter_to_static_comparing_against_free[317d]::case1[0]::{{closure}}[0]) with closure substs [
i32,
for<'r> extern "rust-call" fn((std::cell::Cell<&'_#1r u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 'r)) u32>)),
]
Expand All @@ -35,7 +35,7 @@ LL | | })
LL | | }
| |_^
|
= note: defining type: DefId(0:17 ~ propagate_approximated_shorter_to_static_comparing_against_free[317d]::case1[0]) with substs []
= note: defining type: DefId(0:8 ~ propagate_approximated_shorter_to_static_comparing_against_free[317d]::case1[0]) with substs []

note: External requirements
--> $DIR/propagate-approximated-shorter-to-static-comparing-against-free.rs:35:15
Expand All @@ -46,7 +46,7 @@ LL | | cell_x.set(cell_a.get()); // forces 'a: 'x, implies 'a = 'static
LL | | })
| |_____^
|
= note: defining type: DefId(0:20 ~ propagate_approximated_shorter_to_static_comparing_against_free[317d]::case2[0]::{{closure}}[0]) with closure substs [
= note: defining type: DefId(0:11 ~ propagate_approximated_shorter_to_static_comparing_against_free[317d]::case2[0]::{{closure}}[0]) with closure substs [
i32,
for<'r> extern "rust-call" fn((std::cell::Cell<&'_#1r u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 'r)) u32>)),
]
Expand All @@ -65,7 +65,7 @@ LL | | })
LL | | }
| |_^
|
= note: defining type: DefId(0:19 ~ propagate_approximated_shorter_to_static_comparing_against_free[317d]::case2[0]) with substs []
= note: defining type: DefId(0:10 ~ propagate_approximated_shorter_to_static_comparing_against_free[317d]::case2[0]) with substs []

error[E0597]: `a` does not live long enough
--> $DIR/propagate-approximated-shorter-to-static-comparing-against-free.rs:30:26
Expand Down
Expand Up @@ -10,7 +10,7 @@ LL | | demand_y(x, y, x.get())
LL | | });
| |_____^
|
= note: defining type: DefId(0:25 ~ propagate_approximated_shorter_to_static_no_bound[317d]::supply[0]::{{closure}}[0]) with closure substs [
= note: defining type: DefId(0:16 ~ propagate_approximated_shorter_to_static_no_bound[317d]::supply[0]::{{closure}}[0]) with closure substs [
i16,
for<'r, 's, 't0, 't1, 't2> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 'r)) std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 's)) u32>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 't0)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 's)) u32>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 't1)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 't2)) u32>)),
]
Expand All @@ -31,7 +31,7 @@ LL | | });
LL | | }
| |_^
|
= note: defining type: DefId(0:22 ~ propagate_approximated_shorter_to_static_no_bound[317d]::supply[0]) with substs []
= note: defining type: DefId(0:13 ~ propagate_approximated_shorter_to_static_no_bound[317d]::supply[0]) with substs []

error[E0521]: borrowed data escapes outside of function
--> $DIR/propagate-approximated-shorter-to-static-no-bound.rs:32:5
Expand Down
Expand Up @@ -10,7 +10,7 @@ LL | | demand_y(x, y, x.get())
LL | | });
| |_____^
|
= note: defining type: DefId(0:25 ~ propagate_approximated_shorter_to_static_wrong_bound[317d]::supply[0]::{{closure}}[0]) with closure substs [
= note: defining type: DefId(0:16 ~ propagate_approximated_shorter_to_static_wrong_bound[317d]::supply[0]::{{closure}}[0]) with closure substs [
i16,
for<'r, 's, 't0, 't1, 't2, 't3> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 'r)) std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 's)) u32>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 't0)) std::cell::Cell<&'_#2r &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 't1)) u32>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 't2)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 's)) u32>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 't3)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 't1)) u32>)),
]
Expand All @@ -31,7 +31,7 @@ LL | | });
LL | | }
| |_^
|
= note: defining type: DefId(0:22 ~ propagate_approximated_shorter_to_static_wrong_bound[317d]::supply[0]) with substs []
= note: defining type: DefId(0:13 ~ propagate_approximated_shorter_to_static_wrong_bound[317d]::supply[0]) with substs []

error[E0521]: borrowed data escapes outside of function
--> $DIR/propagate-approximated-shorter-to-static-wrong-bound.rs:35:5
Expand Down
Expand Up @@ -9,7 +9,7 @@ LL | |
LL | | });
| |_____^
|
= note: defining type: DefId(0:25 ~ propagate_approximated_val[317d]::test[0]::{{closure}}[0]) with closure substs [
= note: defining type: DefId(0:16 ~ propagate_approximated_val[317d]::test[0]::{{closure}}[0]) with closure substs [
i16,
for<'r, 's> extern "rust-call" fn((std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 'r)) u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 's)) &'_#2r u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 'r)) u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 's)) u32>)),
]
Expand All @@ -30,7 +30,7 @@ LL | | });
LL | | }
| |_^
|
= note: defining type: DefId(0:22 ~ propagate_approximated_val[317d]::test[0]) with substs []
= note: defining type: DefId(0:13 ~ propagate_approximated_val[317d]::test[0]) with substs []

error: lifetime may not live long enough
--> $DIR/propagate-approximated-val.rs:38:9
Expand Down

0 comments on commit 2595332

Please sign in to comment.