Skip to content

Commit 70b49c7

Browse files
committed
metadata: skip empty polymorphization bitset
This commit skips encoding empty polymorphization results - while polymorphization is disabled, this should be every polymorphization result; but when polymorphization is re-enabled, this would help with non-generic functions and those which do use all their parameters (most functions). Signed-off-by: David Wood <[email protected]>
1 parent 5f89f02 commit 70b49c7

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/librustc_metadata/rmeta/encoder.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1134,8 +1134,11 @@ impl EncodeContext<'a, 'tcx> {
11341134
debug!("EntryBuilder::encode_mir({:?})", def_id);
11351135
if self.tcx.mir_keys(LOCAL_CRATE).contains(&def_id) {
11361136
record!(self.tables.mir[def_id.to_def_id()] <- self.tcx.optimized_mir(def_id));
1137-
record!(self.tables.unused_generic_params[def_id.to_def_id()] <-
1138-
self.tcx.unused_generic_params(def_id));
1137+
1138+
let unused = self.tcx.unused_generic_params(def_id);
1139+
if !unused.is_empty() {
1140+
record!(self.tables.unused_generic_params[def_id.to_def_id()] <- unused);
1141+
}
11391142
}
11401143
}
11411144

src/librustc_mir/monomorphize/polymorphize.rs

+7
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ fn unused_generic_params(tcx: TyCtxt<'_>, def_id: DefId) -> FiniteBitSet<u32> {
3636
return FiniteBitSet::new_empty();
3737
}
3838

39+
// Polymorphization results are stored in cross-crate metadata only when there are unused
40+
// parameters, so assume that non-local items must have only used parameters (else this query
41+
// would not be invoked, and the cross-crate metadata used instead).
42+
if !def_id.is_local() {
43+
return FiniteBitSet::new_empty();
44+
}
45+
3946
let generics = tcx.generics_of(def_id);
4047
debug!("unused_generic_params: generics={:?}", generics);
4148

0 commit comments

Comments
 (0)