Skip to content

Commit 4b03fd9

Browse files
committed
rustc_middle: Rename Export to ModChild and add some comments
Also rename `module_exports`/`export_map` to `module_reexports`/`reexport_map` for clarity.
1 parent 3051f6e commit 4b03fd9

File tree

17 files changed

+66
-64
lines changed

17 files changed

+66
-64
lines changed

compiler/rustc_metadata/src/rmeta/decoder.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use rustc_hir::definitions::{DefKey, DefPath, DefPathData, DefPathHash};
2121
use rustc_hir::diagnostic_items::DiagnosticItems;
2222
use rustc_hir::lang_items;
2323
use rustc_index::vec::{Idx, IndexVec};
24-
use rustc_middle::hir::exports::Export;
24+
use rustc_middle::metadata::ModChild;
2525
use rustc_middle::middle::exported_symbols::{ExportedSymbol, SymbolExportLevel};
2626
use rustc_middle::mir::interpret::{AllocDecodingSession, AllocDecodingState};
2727
use rustc_middle::mir::{self, Body, Promoted};
@@ -1082,7 +1082,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
10821082
fn for_each_module_child(
10831083
&self,
10841084
id: DefIndex,
1085-
mut callback: impl FnMut(Export),
1085+
mut callback: impl FnMut(ModChild),
10861086
sess: &Session,
10871087
) {
10881088
if let Some(data) = &self.root.proc_macro_data {
@@ -1096,7 +1096,12 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
10961096
self.local_def_id(def_index),
10971097
);
10981098
let ident = self.item_ident(def_index, sess);
1099-
callback(Export { ident, res, vis: ty::Visibility::Public, span: ident.span });
1099+
callback(ModChild {
1100+
ident,
1101+
res,
1102+
vis: ty::Visibility::Public,
1103+
span: ident.span,
1104+
});
11001105
}
11011106
}
11021107
return;
@@ -1117,7 +1122,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
11171122
let vis = self.get_visibility(child_index);
11181123
let span = self.get_span(child_index, sess);
11191124

1120-
callback(Export { ident, res, vis, span });
1125+
callback(ModChild { ident, res, vis, span });
11211126

11221127
// For non-re-export structs and variants add their constructors to children.
11231128
// Re-export lists automatically contain constructors when necessary.
@@ -1129,7 +1134,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
11291134
let ctor_res =
11301135
Res::Def(DefKind::Ctor(CtorOf::Struct, ctor_kind), ctor_def_id);
11311136
let vis = self.get_visibility(ctor_def_id.index);
1132-
callback(Export { res: ctor_res, vis, ident, span });
1137+
callback(ModChild { ident, res: ctor_res, vis, span });
11331138
}
11341139
}
11351140
DefKind::Variant => {
@@ -1154,7 +1159,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
11541159
vis = ty::Visibility::Restricted(crate_def_id);
11551160
}
11561161
}
1157-
callback(Export { res: ctor_res, ident, vis, span });
1162+
callback(ModChild { ident, res: ctor_res, vis, span });
11581163
}
11591164
_ => {}
11601165
}

compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_data_structures::stable_map::FxHashMap;
77
use rustc_hir::def::{CtorKind, DefKind, Res};
88
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, CRATE_DEF_INDEX, LOCAL_CRATE};
99
use rustc_hir::definitions::{DefKey, DefPath, DefPathHash};
10-
use rustc_middle::hir::exports::Export;
10+
use rustc_middle::metadata::ModChild;
1111
use rustc_middle::middle::exported_symbols::ExportedSymbol;
1212
use rustc_middle::middle::stability::DeprecationEntry;
1313
use rustc_middle::ty::query::{ExternProviders, Providers};
@@ -309,7 +309,7 @@ pub(in crate::rmeta) fn provide(providers: &mut Providers) {
309309
bfs_queue.push_back(DefId { krate: cnum, index: CRATE_DEF_INDEX });
310310
}
311311

312-
let mut add_child = |bfs_queue: &mut VecDeque<_>, child: &Export, parent: DefId| {
312+
let mut add_child = |bfs_queue: &mut VecDeque<_>, child: &ModChild, parent: DefId| {
313313
if !child.vis.is_public() {
314314
return;
315315
}
@@ -388,7 +388,7 @@ impl CStore {
388388
self.get_crate_data(def.krate).get_visibility(def.index)
389389
}
390390

391-
pub fn module_children_untracked(&self, def_id: DefId, sess: &Session) -> Vec<Export> {
391+
pub fn module_children_untracked(&self, def_id: DefId, sess: &Session) -> Vec<ModChild> {
392392
let mut result = vec![];
393393
self.get_crate_data(def_id.krate).for_each_module_child(
394394
def_id.index,

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1094,7 +1094,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
10941094
// code uses it). However, we skip encoding anything relating to child
10951095
// items - we encode information about proc-macros later on.
10961096
let reexports = if !self.is_proc_macro {
1097-
match tcx.module_exports(local_def_id) {
1097+
match tcx.module_reexports(local_def_id) {
10981098
Some(exports) => self.lazy(exports),
10991099
_ => Lazy::empty(),
11001100
}

compiler/rustc_metadata/src/rmeta/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_hir::def_id::{DefId, DefIndex, DefPathHash, StableCrateId};
1212
use rustc_hir::definitions::DefKey;
1313
use rustc_hir::lang_items;
1414
use rustc_index::{bit_set::FiniteBitSet, vec::IndexVec};
15-
use rustc_middle::hir::exports::Export;
15+
use rustc_middle::metadata::ModChild;
1616
use rustc_middle::middle::exported_symbols::{ExportedSymbol, SymbolExportLevel};
1717
use rustc_middle::mir;
1818
use rustc_middle::thir;
@@ -350,7 +350,7 @@ enum EntryKind {
350350
Union(Lazy<VariantData>, ReprOptions),
351351
Fn(Lazy<FnData>),
352352
ForeignFn(Lazy<FnData>),
353-
Mod(Lazy<[Export]>),
353+
Mod(Lazy<[ModChild]>),
354354
MacroDef(Lazy<MacroDef>),
355355
ProcMacro(MacroKind),
356356
Closure,

compiler/rustc_middle/src/hir/exports.rs

Lines changed: 0 additions & 28 deletions
This file was deleted.

compiler/rustc_middle/src/hir/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
//!
33
//! [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/hir.html
44
5-
pub mod exports;
65
pub mod map;
76
pub mod place;
87

compiler/rustc_middle/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ pub mod dep_graph;
8484
pub mod hir;
8585
pub mod infer;
8686
pub mod lint;
87+
pub mod metadata;
8788
pub mod middle;
8889
pub mod mir;
8990
pub mod thir;

compiler/rustc_middle/src/metadata.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use crate::ty;
2+
3+
use rustc_hir::def::Res;
4+
use rustc_macros::HashStable;
5+
use rustc_span::symbol::Ident;
6+
use rustc_span::Span;
7+
8+
/// This structure is supposed to keep enough data to re-create `NameBinding`s for other crates
9+
/// during name resolution. Right now the bindings are not recreated entirely precisely so we may
10+
/// need to add more data in the future to correctly support macros 2.0, for example.
11+
/// Module child can be either a proper item or a reexport (including private imports).
12+
/// In case of reexport all the fields describe the reexport item itself, not what it refers to.
13+
#[derive(Copy, Clone, Debug, TyEncodable, TyDecodable, HashStable)]
14+
pub struct ModChild {
15+
/// Name of the item.
16+
pub ident: Ident,
17+
/// Resolution result corresponding to the item.
18+
/// Local variables cannot be exported, so this `Res` doesn't need the ID parameter.
19+
pub res: Res<!>,
20+
/// Visibility of the item.
21+
pub vis: ty::Visibility,
22+
/// Span of the item.
23+
pub span: Span,
24+
}

compiler/rustc_middle/src/query/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,8 +1300,8 @@ rustc_queries! {
13001300
desc { "traits in scope at a block" }
13011301
}
13021302

1303-
query module_exports(def_id: LocalDefId) -> Option<&'tcx [Export]> {
1304-
desc { |tcx| "looking up items exported by `{}`", tcx.def_path_str(def_id.to_def_id()) }
1303+
query module_reexports(def_id: LocalDefId) -> Option<&'tcx [ModChild]> {
1304+
desc { |tcx| "looking up reexports of module `{}`", tcx.def_path_str(def_id.to_def_id()) }
13051305
}
13061306

13071307
query impl_defaultness(def_id: DefId) -> hir::Defaultness {
@@ -1528,8 +1528,8 @@ rustc_queries! {
15281528
desc { "fetching what a crate is named" }
15291529
separate_provide_extern
15301530
}
1531-
query module_children(def_id: DefId) -> &'tcx [Export] {
1532-
desc { |tcx| "collecting child items of `{}`", tcx.def_path_str(def_id) }
1531+
query module_children(def_id: DefId) -> &'tcx [ModChild] {
1532+
desc { |tcx| "collecting child items of module `{}`", tcx.def_path_str(def_id) }
15331533
separate_provide_extern
15341534
}
15351535
query extern_mod_stmt_cnum(def_id: LocalDefId) -> Option<CrateNum> {

compiler/rustc_middle/src/ty/context.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2820,7 +2820,8 @@ pub fn provide(providers: &mut ty::query::Providers) {
28202820
providers.in_scope_traits_map =
28212821
|tcx, id| tcx.hir_crate(()).owners[id].as_ref().map(|owner_info| &owner_info.trait_map);
28222822
providers.resolutions = |tcx, ()| &tcx.untracked_resolutions;
2823-
providers.module_exports = |tcx, id| tcx.resolutions(()).export_map.get(&id).map(|v| &v[..]);
2823+
providers.module_reexports =
2824+
|tcx, id| tcx.resolutions(()).reexport_map.get(&id).map(|v| &v[..]);
28242825
providers.crate_name = |tcx, id| {
28252826
assert_eq!(id, LOCAL_CRATE);
28262827
tcx.crate_name

0 commit comments

Comments
 (0)