Skip to content

Commit ec8f688

Browse files
committed
rustc_metadata: Remove Span from ModChild
It can be decoded on demand from regular `def_span` tables. Partially mitigates perf regressions from rust-lang#109500.
1 parent de96f3d commit ec8f688

File tree

5 files changed

+12
-16
lines changed

5 files changed

+12
-16
lines changed

compiler/rustc_metadata/src/rmeta/decoder.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -998,9 +998,8 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
998998
let ident = self.item_ident(id, sess);
999999
let res = Res::Def(self.def_kind(id), self.local_def_id(id));
10001000
let vis = self.get_visibility(id);
1001-
let span = self.get_span(id, sess);
10021001

1003-
ModChild { ident, res, vis, span, reexport_chain: Default::default() }
1002+
ModChild { ident, res, vis, reexport_chain: Default::default() }
10041003
}
10051004

10061005
/// Iterates over all named children of the given module,

compiler/rustc_metadata/src/rmeta/encoder.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -831,16 +831,16 @@ fn should_encode_span(def_kind: DefKind) -> bool {
831831
| DefKind::AssocFn
832832
| DefKind::AssocConst
833833
| DefKind::Macro(_)
834+
| DefKind::ExternCrate
835+
| DefKind::Use
834836
| DefKind::AnonConst
835837
| DefKind::InlineConst
836838
| DefKind::OpaqueTy
837839
| DefKind::Field
838840
| DefKind::Impl { .. }
839841
| DefKind::Closure
840842
| DefKind::Generator => true,
841-
DefKind::ExternCrate
842-
| DefKind::Use
843-
| DefKind::ForeignMod
843+
DefKind::ForeignMod
844844
| DefKind::ImplTraitPlaceholder
845845
| DefKind::LifetimeParam
846846
| DefKind::GlobalAsm => false,

compiler/rustc_middle/src/metadata.rs

-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use rustc_hir::def::Res;
44
use rustc_macros::HashStable;
55
use rustc_span::def_id::DefId;
66
use rustc_span::symbol::Ident;
7-
use rustc_span::Span;
87
use smallvec::SmallVec;
98

109
/// A simplified version of `ImportKind` from resolve.
@@ -41,8 +40,6 @@ pub struct ModChild {
4140
pub res: Res<!>,
4241
/// Visibility of the item.
4342
pub vis: ty::Visibility<DefId>,
44-
/// Span of the item.
45-
pub span: Span,
4643
/// Reexport chain linking this module child to its original reexported item.
4744
/// Empty if the module child is a proper item.
4845
pub reexport_chain: SmallVec<[Reexport; 2]>,

compiler/rustc_resolve/src/build_reduced_graph.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,13 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
931931
/// Builds the reduced graph for a single item in an external crate.
932932
fn build_reduced_graph_for_external_crate_res(&mut self, child: ModChild) {
933933
let parent = self.parent_scope.module;
934-
let ModChild { ident, res, vis, span, .. } = child;
934+
let ModChild { ident, res, vis, reexport_chain } = child;
935+
let span = self.r.def_span(
936+
reexport_chain
937+
.first()
938+
.and_then(|reexport| reexport.id())
939+
.unwrap_or_else(|| res.def_id()),
940+
);
935941
let res = res.expect_non_local();
936942
let expansion = self.parent_scope.expansion;
937943
// Record primary definitions.

compiler/rustc_resolve/src/imports.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -1276,13 +1276,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
12761276
next_binding = binding;
12771277
}
12781278

1279-
reexports.push(ModChild {
1280-
ident,
1281-
res,
1282-
vis: binding.vis,
1283-
span: binding.span,
1284-
reexport_chain,
1285-
});
1279+
reexports.push(ModChild { ident, res, vis: binding.vis, reexport_chain });
12861280
}
12871281
});
12881282

0 commit comments

Comments
 (0)