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 <david@davidtw.co>
This commit is contained in:
David Wood 2020-08-04 18:16:39 +01:00
parent 5f89f02c4e
commit 70b49c7bdd
No known key found for this signature in database
GPG Key ID: 2592E76C87381FD9
2 changed files with 12 additions and 2 deletions

View File

@ -1134,8 +1134,11 @@ impl EncodeContext<'a, 'tcx> {
debug!("EntryBuilder::encode_mir({:?})", def_id);
if self.tcx.mir_keys(LOCAL_CRATE).contains(&def_id) {
record!(self.tables.mir[def_id.to_def_id()] <- self.tcx.optimized_mir(def_id));
record!(self.tables.unused_generic_params[def_id.to_def_id()] <-
self.tcx.unused_generic_params(def_id));
let unused = self.tcx.unused_generic_params(def_id);
if !unused.is_empty() {
record!(self.tables.unused_generic_params[def_id.to_def_id()] <- unused);
}
}
}

View File

@ -36,6 +36,13 @@ fn unused_generic_params(tcx: TyCtxt<'_>, def_id: DefId) -> FiniteBitSet<u32> {
return FiniteBitSet::new_empty();
}
// Polymorphization results are stored in cross-crate metadata only when there are unused
// parameters, so assume that non-local items must have only used parameters (else this query
// would not be invoked, and the cross-crate metadata used instead).
if !def_id.is_local() {
return FiniteBitSet::new_empty();
}
let generics = tcx.generics_of(def_id);
debug!("unused_generic_params: generics={:?}", generics);