mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
Rollup merge of #109324 - cjgillot:fixed-unused-params, r=Nilstrieb
Implement FixedSizeEncoding for UnusedGenericParams. Using a `Lazy` for actually a `u32` value is 50% overhead, so let's encode the bitset directly.
This commit is contained in:
commit
881c9898ad
@ -226,15 +226,7 @@ provide! { tcx, def_id, other, cdata,
|
||||
lookup_default_body_stability => { table }
|
||||
lookup_deprecation_entry => { table }
|
||||
params_in_repr => { table }
|
||||
// FIXME: Could be defaulted, but `LazyValue<UnusedGenericParams>` is not `FixedSizeEncoding`..
|
||||
unused_generic_params => {
|
||||
cdata
|
||||
.root
|
||||
.tables
|
||||
.unused_generic_params
|
||||
.get(cdata, def_id.index)
|
||||
.map_or_else(|| ty::UnusedGenericParams::new_all_used(), |lazy| lazy.decode((cdata, tcx)))
|
||||
}
|
||||
unused_generic_params => { cdata.root.tables.unused_generic_params.get(cdata, def_id.index) }
|
||||
opt_def_kind => { table_direct }
|
||||
impl_parent => { table }
|
||||
impl_polarity => { table_direct }
|
||||
|
@ -1440,9 +1440,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
||||
let instance =
|
||||
ty::InstanceDef::Item(ty::WithOptConstParam::unknown(def_id.to_def_id()));
|
||||
let unused = tcx.unused_generic_params(instance);
|
||||
if !unused.all_used() {
|
||||
record!(self.tables.unused_generic_params[def_id.to_def_id()] <- unused);
|
||||
}
|
||||
self.tables.unused_generic_params.set(def_id.local_def_index, unused);
|
||||
}
|
||||
|
||||
// Encode all the deduced parameter attributes for everything that has MIR, even for items
|
||||
|
@ -356,6 +356,7 @@ define_tables! {
|
||||
inherent_impls: Table<DefIndex, LazyArray<DefIndex>>,
|
||||
associated_items_for_impl_trait_in_trait: Table<DefIndex, LazyArray<DefId>>,
|
||||
opt_rpitit_info: Table<DefIndex, Option<LazyValue<ty::ImplTraitInTraitData>>>,
|
||||
unused_generic_params: Table<DefIndex, UnusedGenericParams>,
|
||||
|
||||
- optional:
|
||||
attributes: Table<DefIndex, LazyArray<ast::Attribute>>,
|
||||
@ -398,7 +399,6 @@ define_tables! {
|
||||
trait_def: Table<DefIndex, LazyValue<ty::TraitDef>>,
|
||||
trait_item_def_id: Table<DefIndex, RawDefId>,
|
||||
expn_that_defined: Table<DefIndex, LazyValue<ExpnId>>,
|
||||
unused_generic_params: Table<DefIndex, LazyValue<UnusedGenericParams>>,
|
||||
params_in_repr: Table<DefIndex, LazyValue<BitSet<u32>>>,
|
||||
repr_options: Table<DefIndex, LazyValue<ReprOptions>>,
|
||||
// `def_keys` and `def_path_hashes` represent a lazy version of a
|
||||
|
@ -3,7 +3,7 @@ use crate::rmeta::*;
|
||||
use rustc_data_structures::fingerprint::Fingerprint;
|
||||
use rustc_hir::def::{CtorKind, CtorOf};
|
||||
use rustc_index::vec::Idx;
|
||||
use rustc_middle::ty::ParameterizedOverTcx;
|
||||
use rustc_middle::ty::{ParameterizedOverTcx, UnusedGenericParams};
|
||||
use rustc_serialize::opaque::FileEncoder;
|
||||
use rustc_serialize::Encoder as _;
|
||||
use rustc_span::hygiene::MacroKind;
|
||||
@ -50,6 +50,16 @@ impl IsDefault for DefPathHash {
|
||||
}
|
||||
}
|
||||
|
||||
impl IsDefault for UnusedGenericParams {
|
||||
fn is_default(&self) -> bool {
|
||||
// UnusedGenericParams encodes the *un*usedness as a bitset.
|
||||
// This means that 0 corresponds to all bits used, which is indeed the default.
|
||||
let is_default = self.bits() == 0;
|
||||
debug_assert_eq!(is_default, self.all_used());
|
||||
is_default
|
||||
}
|
||||
}
|
||||
|
||||
/// Helper trait, for encoding to, and decoding from, a fixed number of bytes.
|
||||
/// Used mainly for Lazy positions and lengths.
|
||||
/// Unchecked invariant: `Self::default()` should encode as `[0; BYTE_LEN]`,
|
||||
@ -271,6 +281,21 @@ impl FixedSizeEncoding for bool {
|
||||
}
|
||||
}
|
||||
|
||||
impl FixedSizeEncoding for UnusedGenericParams {
|
||||
type ByteArray = [u8; 4];
|
||||
|
||||
#[inline]
|
||||
fn from_bytes(b: &[u8; 4]) -> Self {
|
||||
let x: u32 = u32::from_bytes(b);
|
||||
UnusedGenericParams::from_bits(x)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn write_to_bytes(self, b: &mut [u8; 4]) {
|
||||
self.bits().write_to_bytes(b);
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE(eddyb) there could be an impl for `usize`, which would enable a more
|
||||
// generic `LazyValue<T>` impl, but in the general case we might not need / want
|
||||
// to fit every `usize` in `u32`.
|
||||
|
@ -781,6 +781,12 @@ fn needs_fn_once_adapter_shim(
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq, Decodable, Encodable, HashStable)]
|
||||
pub struct UnusedGenericParams(FiniteBitSet<u32>);
|
||||
|
||||
impl Default for UnusedGenericParams {
|
||||
fn default() -> Self {
|
||||
UnusedGenericParams::new_all_used()
|
||||
}
|
||||
}
|
||||
|
||||
impl UnusedGenericParams {
|
||||
pub fn new_all_unused(amount: u32) -> Self {
|
||||
let mut bitset = FiniteBitSet::new_empty();
|
||||
@ -807,4 +813,12 @@ impl UnusedGenericParams {
|
||||
pub fn all_used(&self) -> bool {
|
||||
self.0.is_empty()
|
||||
}
|
||||
|
||||
pub fn bits(&self) -> u32 {
|
||||
self.0.0
|
||||
}
|
||||
|
||||
pub fn from_bits(bits: u32) -> UnusedGenericParams {
|
||||
UnusedGenericParams(FiniteBitSet(bits))
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user