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

+11-6
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

+3-3
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

+1-1
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

+2-2
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

-28
This file was deleted.

compiler/rustc_middle/src/hir/mod.rs

-1
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

+1
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

+24
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

+4-4
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

+2-1
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

compiler/rustc_middle/src/ty/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub use assoc::*;
1919
pub use generics::*;
2020
pub use vtable::*;
2121

22-
use crate::hir::exports::ExportMap;
22+
use crate::metadata::ModChild;
2323
use crate::mir::{Body, GeneratorLayout};
2424
use crate::traits::{self, Reveal};
2525
use crate::ty;
@@ -126,7 +126,7 @@ pub struct ResolverOutputs {
126126
pub extern_crate_map: FxHashMap<LocalDefId, CrateNum>,
127127
pub maybe_unused_trait_imports: FxHashSet<LocalDefId>,
128128
pub maybe_unused_extern_crates: Vec<(LocalDefId, Span)>,
129-
pub export_map: ExportMap,
129+
pub reexport_map: FxHashMap<LocalDefId, Vec<ModChild>>,
130130
pub glob_map: FxHashMap<LocalDefId, FxHashSet<Symbol>>,
131131
/// Extern prelude entries. The value is `true` if the entry was introduced
132132
/// via `extern crate` item and not `--extern` option or compiler built-in.

compiler/rustc_middle/src/ty/query.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::dep_graph;
2-
use crate::hir::exports::Export;
32
use crate::infer::canonical::{self, Canonical};
43
use crate::lint::LintLevelMap;
4+
use crate::metadata::ModChild;
55
use crate::middle::codegen_fn_attrs::CodegenFnAttrs;
66
use crate::middle::exported_symbols::{ExportedSymbol, SymbolExportLevel};
77
use crate::middle::lib_features::LibFeatures;

compiler/rustc_privacy/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ impl<'tcx> EmbargoVisitor<'tcx> {
520520
let vis = self.tcx.visibility(item_id.def_id);
521521
self.update_macro_reachable_def(item_id.def_id, def_kind, vis, defining_mod);
522522
}
523-
if let Some(exports) = self.tcx.module_exports(module_def_id) {
523+
if let Some(exports) = self.tcx.module_reexports(module_def_id) {
524524
for export in exports {
525525
if export.vis.is_accessible_from(defining_mod.to_def_id(), self.tcx) {
526526
if let Res::Def(def_kind, def_id) = export.res {
@@ -926,7 +926,7 @@ impl<'tcx> Visitor<'tcx> for EmbargoVisitor<'tcx> {
926926
// crate module gets processed as well.
927927
if self.prev_level.is_some() {
928928
let def_id = self.tcx.hir().local_def_id(id);
929-
if let Some(exports) = self.tcx.module_exports(def_id) {
929+
if let Some(exports) = self.tcx.module_reexports(def_id) {
930930
for export in exports.iter() {
931931
if export.vis.is_public() {
932932
if let Some(def_id) = export.res.opt_def_id() {

compiler/rustc_resolve/src/build_reduced_graph.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use rustc_hir::def::{self, *};
2626
use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_INDEX};
2727
use rustc_metadata::creader::LoadedMacro;
2828
use rustc_middle::bug;
29-
use rustc_middle::hir::exports::Export;
29+
use rustc_middle::metadata::ModChild;
3030
use rustc_middle::ty;
3131
use rustc_session::cstore::CrateStore;
3232
use rustc_span::hygiene::{ExpnId, LocalExpnId, MacroKind};
@@ -938,9 +938,9 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
938938
}
939939

940940
/// Builds the reduced graph for a single item in an external crate.
941-
fn build_reduced_graph_for_external_crate_res(&mut self, child: Export) {
941+
fn build_reduced_graph_for_external_crate_res(&mut self, child: ModChild) {
942942
let parent = self.parent_scope.module;
943-
let Export { ident, res, vis, span } = child;
943+
let ModChild { ident, res, vis, span } = child;
944944
let res = res.expect_non_local();
945945
let expansion = self.parent_scope.expansion;
946946
// Record primary definitions.

compiler/rustc_resolve/src/imports.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc_data_structures::ptr_key::PtrKey;
1515
use rustc_errors::{pluralize, struct_span_err, Applicability};
1616
use rustc_hir::def::{self, PartialRes};
1717
use rustc_hir::def_id::DefId;
18-
use rustc_middle::hir::exports::Export;
18+
use rustc_middle::metadata::ModChild;
1919
use rustc_middle::span_bug;
2020
use rustc_middle::ty;
2121
use rustc_session::lint::builtin::{PUB_USE_OF_PRIVATE_EXTERN_CRATE, UNUSED_IMPORTS};
@@ -1409,7 +1409,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
14091409
if is_good_import || binding.is_macro_def() {
14101410
let res = binding.res().expect_non_local();
14111411
if res != def::Res::Err {
1412-
reexports.push(Export { ident, res, span: binding.span, vis: binding.vis });
1412+
reexports.push(ModChild { ident, res, vis: binding.vis, span: binding.span });
14131413
}
14141414
}
14151415
});
@@ -1418,7 +1418,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
14181418
if let Some(def_id) = module.opt_def_id() {
14191419
// Call to `expect_local` should be fine because current
14201420
// code is only called for local modules.
1421-
self.r.export_map.insert(def_id.expect_local(), reexports);
1421+
self.r.reexport_map.insert(def_id.expect_local(), reexports);
14221422
}
14231423
}
14241424
}

compiler/rustc_resolve/src/lib.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ use rustc_hir::definitions::{DefKey, DefPathData, Definitions};
4949
use rustc_hir::TraitCandidate;
5050
use rustc_index::vec::IndexVec;
5151
use rustc_metadata::creader::{CStore, CrateLoader};
52-
use rustc_middle::hir::exports::ExportMap;
52+
use rustc_middle::metadata::ModChild;
5353
use rustc_middle::span_bug;
5454
use rustc_middle::ty::query::Providers;
5555
use rustc_middle::ty::{self, DefIdTree, MainDefinition, ResolverOutputs};
@@ -927,7 +927,7 @@ pub struct Resolver<'a> {
927927

928928
/// `CrateNum` resolutions of `extern crate` items.
929929
extern_crate_map: FxHashMap<LocalDefId, CrateNum>,
930-
export_map: ExportMap,
930+
reexport_map: FxHashMap<LocalDefId, Vec<ModChild>>,
931931
trait_map: NodeMap<Vec<TraitCandidate>>,
932932

933933
/// A map from nodes to anonymous modules.
@@ -1333,7 +1333,7 @@ impl<'a> Resolver<'a> {
13331333
import_res_map: Default::default(),
13341334
label_res_map: Default::default(),
13351335
extern_crate_map: Default::default(),
1336-
export_map: FxHashMap::default(),
1336+
reexport_map: FxHashMap::default(),
13371337
trait_map: NodeMap::default(),
13381338
underscore_disambiguator: 0,
13391339
empty_module,
@@ -1446,7 +1446,7 @@ impl<'a> Resolver<'a> {
14461446
let definitions = self.definitions;
14471447
let visibilities = self.visibilities;
14481448
let extern_crate_map = self.extern_crate_map;
1449-
let export_map = self.export_map;
1449+
let reexport_map = self.reexport_map;
14501450
let maybe_unused_trait_imports = self.maybe_unused_trait_imports;
14511451
let maybe_unused_extern_crates = self.maybe_unused_extern_crates;
14521452
let glob_map = self.glob_map;
@@ -1457,7 +1457,7 @@ impl<'a> Resolver<'a> {
14571457
cstore: Box::new(self.crate_loader.into_cstore()),
14581458
visibilities,
14591459
extern_crate_map,
1460-
export_map,
1460+
reexport_map,
14611461
glob_map,
14621462
maybe_unused_trait_imports,
14631463
maybe_unused_extern_crates,
@@ -1480,7 +1480,7 @@ impl<'a> Resolver<'a> {
14801480
cstore: Box::new(self.cstore().clone()),
14811481
visibilities: self.visibilities.clone(),
14821482
extern_crate_map: self.extern_crate_map.clone(),
1483-
export_map: self.export_map.clone(),
1483+
reexport_map: self.reexport_map.clone(),
14841484
glob_map: self.glob_map.clone(),
14851485
maybe_unused_trait_imports: self.maybe_unused_trait_imports.clone(),
14861486
maybe_unused_extern_crates: self.maybe_unused_extern_crates.clone(),

src/librustdoc/visit_ast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
112112
// is declared but also a reexport of itself producing two exports of the same
113113
// macro in the same module.
114114
let mut inserted = FxHashSet::default();
115-
for export in self.cx.tcx.module_exports(CRATE_DEF_ID).unwrap_or(&[]) {
115+
for export in self.cx.tcx.module_reexports(CRATE_DEF_ID).unwrap_or(&[]) {
116116
if let Res::Def(DefKind::Macro(_), def_id) = export.res {
117117
if let Some(local_def_id) = def_id.as_local() {
118118
if self.cx.tcx.has_attr(def_id, sym::macro_export) {

0 commit comments

Comments
 (0)