Skip to content

Commit

Permalink
metadata: skip empty polymorphization bitset
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
davidtwco committed Aug 4, 2020
1 parent 5f89f02 commit 70b49c7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/librustc_metadata/rmeta/encoder.rs
Expand Up @@ -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);
}
}
}

Expand Down
7 changes: 7 additions & 0 deletions src/librustc_mir/monomorphize/polymorphize.rs
Expand Up @@ -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);

Expand Down

0 comments on commit 70b49c7

Please sign in to comment.