Skip to content

Commit affb122

Browse files
committed
Create a module-reexports table.
1 parent d330dc8 commit affb122

File tree

3 files changed

+11
-18
lines changed

3 files changed

+11
-18
lines changed

compiler/rustc_metadata/src/rmeta/decoder.rs

+5-11
Original file line numberDiff line numberDiff line change
@@ -1086,14 +1086,10 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
10861086
}
10871087
}
10881088

1089-
match self.kind(id) {
1090-
EntryKind::Mod(exports) => {
1091-
for exp in exports.decode((self, sess)) {
1092-
callback(exp);
1093-
}
1089+
if let Some(exports) = self.root.tables.module_reexports.get(self, id) {
1090+
for exp in exports.decode((self, sess)) {
1091+
callback(exp);
10941092
}
1095-
EntryKind::Enum | EntryKind::Trait => {}
1096-
_ => bug!("`for_each_module_child` is called on a non-module: {:?}", self.def_kind(id)),
10971093
}
10981094
}
10991095

@@ -1106,10 +1102,8 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
11061102
}
11071103

11081104
fn module_expansion(self, id: DefIndex, sess: &Session) -> ExpnId {
1109-
match self.kind(id) {
1110-
EntryKind::Mod(_) | EntryKind::Enum | EntryKind::Trait => {
1111-
self.get_expn_that_defined(id, sess)
1112-
}
1105+
match self.def_kind(id) {
1106+
DefKind::Mod | DefKind::Enum | DefKind::Trait => self.get_expn_that_defined(id, sess),
11131107
_ => panic!("Expected module, found {:?}", self.local_def_id(id)),
11141108
}
11151109
}

compiler/rustc_metadata/src/rmeta/encoder.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -1254,15 +1254,13 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
12541254
// code uses it). However, we skip encoding anything relating to child
12551255
// items - we encode information about proc-macros later on.
12561256
let reexports = if !self.is_proc_macro {
1257-
match tcx.module_reexports(local_def_id) {
1258-
Some(exports) => self.lazy_array(exports),
1259-
_ => LazyArray::empty(),
1260-
}
1257+
tcx.module_reexports(local_def_id).unwrap_or(&[])
12611258
} else {
1262-
LazyArray::empty()
1259+
&[]
12631260
};
12641261

1265-
record!(self.tables.kind[def_id] <- EntryKind::Mod(reexports));
1262+
record_array!(self.tables.module_reexports[def_id] <- reexports);
1263+
record!(self.tables.kind[def_id] <- EntryKind::Mod);
12661264
if self.is_proc_macro {
12671265
// Encode this here because we don't do it in encode_def_ids.
12681266
record!(self.tables.expn_that_defined[def_id] <- tcx.expn_that_defined(local_def_id));

compiler/rustc_metadata/src/rmeta/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ define_tables! {
399399
proc_macro: Table<DefIndex, MacroKind>,
400400
// Slot is full when there is a self parameter.
401401
fn_has_self_parameter: Table<DefIndex, ()>,
402+
module_reexports: Table<DefIndex, LazyArray<ModChild>>,
402403
}
403404

404405
#[derive(Copy, Clone, MetadataEncodable, MetadataDecodable)]
@@ -421,7 +422,7 @@ enum EntryKind {
421422
Union,
422423
Fn,
423424
ForeignFn,
424-
Mod(LazyArray<ModChild>),
425+
Mod,
425426
MacroDef,
426427
ProcMacro,
427428
Closure,

0 commit comments

Comments
 (0)