mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-21 03:57:38 +00:00
Rollup merge of #107166 - petrochenkov:nooptable, r=oli-obk
rustc_metadata: Support non-`Option` nullable values in metadata tables This is a convenience feature for cases in which "no value in the table" and "default value in the table" are equivalent. Tables using `Table<DefIndex, ()>` are migrated in this PR, some other cases can be migrated later. This helps `DocFlags` in https://github.com/rust-lang/rust/pull/107136 in particular.
This commit is contained in:
commit
a788ce243a
@ -985,7 +985,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
|
|||||||
let vis = self.get_visibility(id);
|
let vis = self.get_visibility(id);
|
||||||
let span = self.get_span(id, sess);
|
let span = self.get_span(id, sess);
|
||||||
let macro_rules = match kind {
|
let macro_rules = match kind {
|
||||||
DefKind::Macro(..) => self.root.tables.macro_rules.get(self, id).is_some(),
|
DefKind::Macro(..) => self.root.tables.is_macro_rules.get(self, id),
|
||||||
_ => false,
|
_ => false,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1283,7 +1283,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
|
|||||||
fn get_macro(self, id: DefIndex, sess: &Session) -> ast::MacroDef {
|
fn get_macro(self, id: DefIndex, sess: &Session) -> ast::MacroDef {
|
||||||
match self.def_kind(id) {
|
match self.def_kind(id) {
|
||||||
DefKind::Macro(_) => {
|
DefKind::Macro(_) => {
|
||||||
let macro_rules = self.root.tables.macro_rules.get(self, id).is_some();
|
let macro_rules = self.root.tables.is_macro_rules.get(self, id);
|
||||||
let body =
|
let body =
|
||||||
self.root.tables.macro_definition.get(self, id).unwrap().decode((self, sess));
|
self.root.tables.macro_definition.get(self, id).unwrap().decode((self, sess));
|
||||||
ast::MacroDef { macro_rules, body: ast::ptr::P(body) }
|
ast::MacroDef { macro_rules, body: ast::ptr::P(body) }
|
||||||
@ -1595,11 +1595,11 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_attr_flags(self, index: DefIndex) -> AttrFlags {
|
fn get_attr_flags(self, index: DefIndex) -> AttrFlags {
|
||||||
self.root.tables.attr_flags.get(self, index).unwrap_or(AttrFlags::empty())
|
self.root.tables.attr_flags.get(self, index)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_is_intrinsic(self, index: DefIndex) -> bool {
|
fn get_is_intrinsic(self, index: DefIndex) -> bool {
|
||||||
self.root.tables.is_intrinsic.get(self, index).is_some()
|
self.root.tables.is_intrinsic.get(self, index)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -226,12 +226,7 @@ provide! { tcx, def_id, other, cdata,
|
|||||||
deduced_param_attrs => { table }
|
deduced_param_attrs => { table }
|
||||||
is_type_alias_impl_trait => {
|
is_type_alias_impl_trait => {
|
||||||
debug_assert_eq!(tcx.def_kind(def_id), DefKind::OpaqueTy);
|
debug_assert_eq!(tcx.def_kind(def_id), DefKind::OpaqueTy);
|
||||||
cdata
|
cdata.root.tables.is_type_alias_impl_trait.get(cdata, def_id.index)
|
||||||
.root
|
|
||||||
.tables
|
|
||||||
.is_type_alias_impl_trait
|
|
||||||
.get(cdata, def_id.index)
|
|
||||||
.is_some()
|
|
||||||
}
|
}
|
||||||
collect_return_position_impl_trait_in_trait_tys => {
|
collect_return_position_impl_trait_in_trait_tys => {
|
||||||
Ok(cdata
|
Ok(cdata
|
||||||
|
@ -483,7 +483,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
|||||||
self.lazy(DefPathHashMapRef::BorrowedFromTcx(self.tcx.def_path_hash_to_def_index_map()))
|
self.lazy(DefPathHashMapRef::BorrowedFromTcx(self.tcx.def_path_hash_to_def_index_map()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn encode_source_map(&mut self) -> LazyTable<u32, LazyValue<rustc_span::SourceFile>> {
|
fn encode_source_map(&mut self) -> LazyTable<u32, Option<LazyValue<rustc_span::SourceFile>>> {
|
||||||
let source_map = self.tcx.sess.source_map();
|
let source_map = self.tcx.sess.source_map();
|
||||||
let all_source_files = source_map.files();
|
let all_source_files = source_map.files();
|
||||||
|
|
||||||
@ -1130,7 +1130,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
|||||||
attr_flags |= AttrFlags::IS_DOC_HIDDEN;
|
attr_flags |= AttrFlags::IS_DOC_HIDDEN;
|
||||||
}
|
}
|
||||||
if !attr_flags.is_empty() {
|
if !attr_flags.is_empty() {
|
||||||
self.tables.attr_flags.set(def_id.local_def_index, attr_flags);
|
self.tables.attr_flags.set_nullable(def_id.local_def_index, attr_flags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1387,7 +1387,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
|||||||
if impl_item.kind == ty::AssocKind::Fn {
|
if impl_item.kind == ty::AssocKind::Fn {
|
||||||
record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id));
|
record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id));
|
||||||
if tcx.is_intrinsic(def_id) {
|
if tcx.is_intrinsic(def_id) {
|
||||||
self.tables.is_intrinsic.set(def_id.index, ());
|
self.tables.is_intrinsic.set_nullable(def_id.index, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1519,7 +1519,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
|||||||
}
|
}
|
||||||
hir::ItemKind::Macro(ref macro_def, _) => {
|
hir::ItemKind::Macro(ref macro_def, _) => {
|
||||||
if macro_def.macro_rules {
|
if macro_def.macro_rules {
|
||||||
self.tables.macro_rules.set(def_id.index, ());
|
self.tables.is_macro_rules.set_nullable(def_id.index, true);
|
||||||
}
|
}
|
||||||
record!(self.tables.macro_definition[def_id] <- &*macro_def.body);
|
record!(self.tables.macro_definition[def_id] <- &*macro_def.body);
|
||||||
}
|
}
|
||||||
@ -1529,7 +1529,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
|||||||
hir::ItemKind::OpaqueTy(ref opaque) => {
|
hir::ItemKind::OpaqueTy(ref opaque) => {
|
||||||
self.encode_explicit_item_bounds(def_id);
|
self.encode_explicit_item_bounds(def_id);
|
||||||
if matches!(opaque.origin, hir::OpaqueTyOrigin::TyAlias) {
|
if matches!(opaque.origin, hir::OpaqueTyOrigin::TyAlias) {
|
||||||
self.tables.is_type_alias_impl_trait.set(def_id.index, ());
|
self.tables.is_type_alias_impl_trait.set_nullable(def_id.index, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hir::ItemKind::Enum(..) => {
|
hir::ItemKind::Enum(..) => {
|
||||||
@ -1636,7 +1636,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
|||||||
if let hir::ItemKind::Fn(..) = item.kind {
|
if let hir::ItemKind::Fn(..) = item.kind {
|
||||||
record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id));
|
record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id));
|
||||||
if tcx.is_intrinsic(def_id) {
|
if tcx.is_intrinsic(def_id) {
|
||||||
self.tables.is_intrinsic.set(def_id.index, ());
|
self.tables.is_intrinsic.set_nullable(def_id.index, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let hir::ItemKind::Impl { .. } = item.kind {
|
if let hir::ItemKind::Impl { .. } = item.kind {
|
||||||
@ -2038,7 +2038,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
|||||||
}
|
}
|
||||||
if let hir::ForeignItemKind::Fn(..) = nitem.kind {
|
if let hir::ForeignItemKind::Fn(..) = nitem.kind {
|
||||||
if tcx.is_intrinsic(def_id) {
|
if tcx.is_intrinsic(def_id) {
|
||||||
self.tables.is_intrinsic.set(def_id.index, ());
|
self.tables.is_intrinsic.set_nullable(def_id.index, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -185,9 +185,9 @@ enum LazyState {
|
|||||||
Previous(NonZeroUsize),
|
Previous(NonZeroUsize),
|
||||||
}
|
}
|
||||||
|
|
||||||
type SyntaxContextTable = LazyTable<u32, LazyValue<SyntaxContextData>>;
|
type SyntaxContextTable = LazyTable<u32, Option<LazyValue<SyntaxContextData>>>;
|
||||||
type ExpnDataTable = LazyTable<ExpnIndex, LazyValue<ExpnData>>;
|
type ExpnDataTable = LazyTable<ExpnIndex, Option<LazyValue<ExpnData>>>;
|
||||||
type ExpnHashTable = LazyTable<ExpnIndex, LazyValue<ExpnHash>>;
|
type ExpnHashTable = LazyTable<ExpnIndex, Option<LazyValue<ExpnHash>>>;
|
||||||
|
|
||||||
#[derive(MetadataEncodable, MetadataDecodable)]
|
#[derive(MetadataEncodable, MetadataDecodable)]
|
||||||
pub(crate) struct ProcMacroData {
|
pub(crate) struct ProcMacroData {
|
||||||
@ -253,7 +253,7 @@ pub(crate) struct CrateRoot {
|
|||||||
|
|
||||||
def_path_hash_map: LazyValue<DefPathHashMapRef<'static>>,
|
def_path_hash_map: LazyValue<DefPathHashMapRef<'static>>,
|
||||||
|
|
||||||
source_map: LazyTable<u32, LazyValue<rustc_span::SourceFile>>,
|
source_map: LazyTable<u32, Option<LazyValue<rustc_span::SourceFile>>>,
|
||||||
|
|
||||||
compiler_builtins: bool,
|
compiler_builtins: bool,
|
||||||
needs_allocator: bool,
|
needs_allocator: bool,
|
||||||
@ -315,21 +315,27 @@ pub(crate) struct IncoherentImpls {
|
|||||||
|
|
||||||
/// Define `LazyTables` and `TableBuilders` at the same time.
|
/// Define `LazyTables` and `TableBuilders` at the same time.
|
||||||
macro_rules! define_tables {
|
macro_rules! define_tables {
|
||||||
($($name:ident: Table<$IDX:ty, $T:ty>),+ $(,)?) => {
|
(
|
||||||
|
- nullable: $($name1:ident: Table<$IDX1:ty, $T1:ty>,)+
|
||||||
|
- optional: $($name2:ident: Table<$IDX2:ty, $T2:ty>,)+
|
||||||
|
) => {
|
||||||
#[derive(MetadataEncodable, MetadataDecodable)]
|
#[derive(MetadataEncodable, MetadataDecodable)]
|
||||||
pub(crate) struct LazyTables {
|
pub(crate) struct LazyTables {
|
||||||
$($name: LazyTable<$IDX, $T>),+
|
$($name1: LazyTable<$IDX1, $T1>,)+
|
||||||
|
$($name2: LazyTable<$IDX2, Option<$T2>>,)+
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct TableBuilders {
|
struct TableBuilders {
|
||||||
$($name: TableBuilder<$IDX, $T>),+
|
$($name1: TableBuilder<$IDX1, $T1>,)+
|
||||||
|
$($name2: TableBuilder<$IDX2, Option<$T2>>,)+
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TableBuilders {
|
impl TableBuilders {
|
||||||
fn encode(&self, buf: &mut FileEncoder) -> LazyTables {
|
fn encode(&self, buf: &mut FileEncoder) -> LazyTables {
|
||||||
LazyTables {
|
LazyTables {
|
||||||
$($name: self.$name.encode(buf)),+
|
$($name1: self.$name1.encode(buf),)+
|
||||||
|
$($name2: self.$name2.encode(buf),)+
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -337,9 +343,15 @@ macro_rules! define_tables {
|
|||||||
}
|
}
|
||||||
|
|
||||||
define_tables! {
|
define_tables! {
|
||||||
|
- nullable:
|
||||||
|
is_intrinsic: Table<DefIndex, bool>,
|
||||||
|
is_macro_rules: Table<DefIndex, bool>,
|
||||||
|
is_type_alias_impl_trait: Table<DefIndex, bool>,
|
||||||
|
attr_flags: Table<DefIndex, AttrFlags>,
|
||||||
|
|
||||||
|
- optional:
|
||||||
attributes: Table<DefIndex, LazyArray<ast::Attribute>>,
|
attributes: Table<DefIndex, LazyArray<ast::Attribute>>,
|
||||||
children: Table<DefIndex, LazyArray<DefIndex>>,
|
children: Table<DefIndex, LazyArray<DefIndex>>,
|
||||||
|
|
||||||
opt_def_kind: Table<DefIndex, DefKind>,
|
opt_def_kind: Table<DefIndex, DefKind>,
|
||||||
visibility: Table<DefIndex, LazyValue<ty::Visibility<DefIndex>>>,
|
visibility: Table<DefIndex, LazyValue<ty::Visibility<DefIndex>>>,
|
||||||
def_span: Table<DefIndex, LazyValue<Span>>,
|
def_span: Table<DefIndex, LazyValue<Span>>,
|
||||||
@ -370,7 +382,6 @@ define_tables! {
|
|||||||
impl_parent: Table<DefIndex, RawDefId>,
|
impl_parent: Table<DefIndex, RawDefId>,
|
||||||
impl_polarity: Table<DefIndex, ty::ImplPolarity>,
|
impl_polarity: Table<DefIndex, ty::ImplPolarity>,
|
||||||
constness: Table<DefIndex, hir::Constness>,
|
constness: Table<DefIndex, hir::Constness>,
|
||||||
is_intrinsic: Table<DefIndex, ()>,
|
|
||||||
impl_defaultness: Table<DefIndex, hir::Defaultness>,
|
impl_defaultness: Table<DefIndex, hir::Defaultness>,
|
||||||
// FIXME(eddyb) perhaps compute this on the fly if cheap enough?
|
// FIXME(eddyb) perhaps compute this on the fly if cheap enough?
|
||||||
coerce_unsized_info: Table<DefIndex, LazyValue<ty::adjustment::CoerceUnsizedInfo>>,
|
coerce_unsized_info: Table<DefIndex, LazyValue<ty::adjustment::CoerceUnsizedInfo>>,
|
||||||
@ -380,7 +391,6 @@ define_tables! {
|
|||||||
fn_arg_names: Table<DefIndex, LazyArray<Ident>>,
|
fn_arg_names: Table<DefIndex, LazyArray<Ident>>,
|
||||||
generator_kind: Table<DefIndex, LazyValue<hir::GeneratorKind>>,
|
generator_kind: Table<DefIndex, LazyValue<hir::GeneratorKind>>,
|
||||||
trait_def: Table<DefIndex, LazyValue<ty::TraitDef>>,
|
trait_def: Table<DefIndex, LazyValue<ty::TraitDef>>,
|
||||||
|
|
||||||
trait_item_def_id: Table<DefIndex, RawDefId>,
|
trait_item_def_id: Table<DefIndex, RawDefId>,
|
||||||
inherent_impls: Table<DefIndex, LazyArray<DefIndex>>,
|
inherent_impls: Table<DefIndex, LazyArray<DefIndex>>,
|
||||||
expn_that_defined: Table<DefIndex, LazyValue<ExpnId>>,
|
expn_that_defined: Table<DefIndex, LazyValue<ExpnId>>,
|
||||||
@ -395,18 +405,12 @@ define_tables! {
|
|||||||
def_path_hashes: Table<DefIndex, DefPathHash>,
|
def_path_hashes: Table<DefIndex, DefPathHash>,
|
||||||
proc_macro_quoted_spans: Table<usize, LazyValue<Span>>,
|
proc_macro_quoted_spans: Table<usize, LazyValue<Span>>,
|
||||||
generator_diagnostic_data: Table<DefIndex, LazyValue<GeneratorDiagnosticData<'static>>>,
|
generator_diagnostic_data: Table<DefIndex, LazyValue<GeneratorDiagnosticData<'static>>>,
|
||||||
attr_flags: Table<DefIndex, AttrFlags>,
|
|
||||||
variant_data: Table<DefIndex, LazyValue<VariantData>>,
|
variant_data: Table<DefIndex, LazyValue<VariantData>>,
|
||||||
assoc_container: Table<DefIndex, ty::AssocItemContainer>,
|
assoc_container: Table<DefIndex, ty::AssocItemContainer>,
|
||||||
// Slot is full when macro is macro_rules.
|
|
||||||
macro_rules: Table<DefIndex, ()>,
|
|
||||||
macro_definition: Table<DefIndex, LazyValue<ast::DelimArgs>>,
|
macro_definition: Table<DefIndex, LazyValue<ast::DelimArgs>>,
|
||||||
proc_macro: Table<DefIndex, MacroKind>,
|
proc_macro: Table<DefIndex, MacroKind>,
|
||||||
module_reexports: Table<DefIndex, LazyArray<ModChild>>,
|
module_reexports: Table<DefIndex, LazyArray<ModChild>>,
|
||||||
deduced_param_attrs: Table<DefIndex, LazyArray<DeducedParamAttrs>>,
|
deduced_param_attrs: Table<DefIndex, LazyArray<DeducedParamAttrs>>,
|
||||||
// Slot is full when opaque is TAIT.
|
|
||||||
is_type_alias_impl_trait: Table<DefIndex, ()>,
|
|
||||||
|
|
||||||
trait_impl_trait_tys: Table<DefIndex, LazyValue<FxHashMap<DefId, Ty<'static>>>>,
|
trait_impl_trait_tys: Table<DefIndex, LazyValue<FxHashMap<DefId, Ty<'static>>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -419,6 +423,7 @@ struct VariantData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bitflags::bitflags! {
|
bitflags::bitflags! {
|
||||||
|
#[derive(Default)]
|
||||||
pub struct AttrFlags: u8 {
|
pub struct AttrFlags: u8 {
|
||||||
const MAY_HAVE_DOC_LINKS = 1 << 0;
|
const MAY_HAVE_DOC_LINKS = 1 << 0;
|
||||||
const IS_DOC_HIDDEN = 1 << 1;
|
const IS_DOC_HIDDEN = 1 << 1;
|
||||||
|
@ -16,6 +16,7 @@ use std::num::NonZeroUsize;
|
|||||||
/// but this has no impact on safety.
|
/// but this has no impact on safety.
|
||||||
pub(super) trait FixedSizeEncoding: Default {
|
pub(super) trait FixedSizeEncoding: Default {
|
||||||
/// This should be `[u8; BYTE_LEN]`;
|
/// This should be `[u8; BYTE_LEN]`;
|
||||||
|
/// Cannot use an associated `const BYTE_LEN: usize` instead due to const eval limitations.
|
||||||
type ByteArray;
|
type ByteArray;
|
||||||
|
|
||||||
fn from_bytes(b: &Self::ByteArray) -> Self;
|
fn from_bytes(b: &Self::ByteArray) -> Self;
|
||||||
@ -199,31 +200,31 @@ impl FixedSizeEncoding for Option<RawDefId> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FixedSizeEncoding for Option<AttrFlags> {
|
impl FixedSizeEncoding for AttrFlags {
|
||||||
type ByteArray = [u8; 1];
|
type ByteArray = [u8; 1];
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_bytes(b: &[u8; 1]) -> Self {
|
fn from_bytes(b: &[u8; 1]) -> Self {
|
||||||
(b[0] != 0).then(|| AttrFlags::from_bits_truncate(b[0]))
|
AttrFlags::from_bits_truncate(b[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn write_to_bytes(self, b: &mut [u8; 1]) {
|
fn write_to_bytes(self, b: &mut [u8; 1]) {
|
||||||
b[0] = self.map_or(0, |flags| flags.bits())
|
b[0] = self.bits();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FixedSizeEncoding for Option<()> {
|
impl FixedSizeEncoding for bool {
|
||||||
type ByteArray = [u8; 1];
|
type ByteArray = [u8; 1];
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_bytes(b: &[u8; 1]) -> Self {
|
fn from_bytes(b: &[u8; 1]) -> Self {
|
||||||
(b[0] != 0).then(|| ())
|
b[0] != 0
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn write_to_bytes(self, b: &mut [u8; 1]) {
|
fn write_to_bytes(self, b: &mut [u8; 1]) {
|
||||||
b[0] = self.is_some() as u8
|
b[0] = self as u8
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -273,44 +274,38 @@ impl<T> FixedSizeEncoding for Option<LazyArray<T>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Helper for constructing a table's serialization (also see `Table`).
|
/// Helper for constructing a table's serialization (also see `Table`).
|
||||||
pub(super) struct TableBuilder<I: Idx, T>
|
pub(super) struct TableBuilder<I: Idx, T: FixedSizeEncoding> {
|
||||||
where
|
blocks: IndexVec<I, T::ByteArray>,
|
||||||
Option<T>: FixedSizeEncoding,
|
|
||||||
{
|
|
||||||
blocks: IndexVec<I, <Option<T> as FixedSizeEncoding>::ByteArray>,
|
|
||||||
_marker: PhantomData<T>,
|
_marker: PhantomData<T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<I: Idx, T> Default for TableBuilder<I, T>
|
impl<I: Idx, T: FixedSizeEncoding> Default for TableBuilder<I, T> {
|
||||||
where
|
|
||||||
Option<T>: FixedSizeEncoding,
|
|
||||||
{
|
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
TableBuilder { blocks: Default::default(), _marker: PhantomData }
|
TableBuilder { blocks: Default::default(), _marker: PhantomData }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<I: Idx, T> TableBuilder<I, T>
|
impl<I: Idx, const N: usize, T> TableBuilder<I, Option<T>>
|
||||||
where
|
where
|
||||||
Option<T>: FixedSizeEncoding,
|
Option<T>: FixedSizeEncoding<ByteArray = [u8; N]>,
|
||||||
{
|
{
|
||||||
pub(crate) fn set<const N: usize>(&mut self, i: I, value: T)
|
pub(crate) fn set(&mut self, i: I, value: T) {
|
||||||
where
|
self.set_nullable(i, Some(value))
|
||||||
Option<T>: FixedSizeEncoding<ByteArray = [u8; N]>,
|
}
|
||||||
{
|
}
|
||||||
|
|
||||||
|
impl<I: Idx, const N: usize, T: FixedSizeEncoding<ByteArray = [u8; N]>> TableBuilder<I, T> {
|
||||||
|
pub(crate) fn set_nullable(&mut self, i: I, value: T) {
|
||||||
// FIXME(eddyb) investigate more compact encodings for sparse tables.
|
// FIXME(eddyb) investigate more compact encodings for sparse tables.
|
||||||
// On the PR @michaelwoerister mentioned:
|
// On the PR @michaelwoerister mentioned:
|
||||||
// > Space requirements could perhaps be optimized by using the HAMT `popcnt`
|
// > Space requirements could perhaps be optimized by using the HAMT `popcnt`
|
||||||
// > trick (i.e. divide things into buckets of 32 or 64 items and then
|
// > trick (i.e. divide things into buckets of 32 or 64 items and then
|
||||||
// > store bit-masks of which item in each bucket is actually serialized).
|
// > store bit-masks of which item in each bucket is actually serialized).
|
||||||
self.blocks.ensure_contains_elem(i, || [0; N]);
|
self.blocks.ensure_contains_elem(i, || [0; N]);
|
||||||
Some(value).write_to_bytes(&mut self.blocks[i]);
|
value.write_to_bytes(&mut self.blocks[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn encode<const N: usize>(&self, buf: &mut FileEncoder) -> LazyTable<I, T>
|
pub(crate) fn encode(&self, buf: &mut FileEncoder) -> LazyTable<I, T> {
|
||||||
where
|
|
||||||
Option<T>: FixedSizeEncoding<ByteArray = [u8; N]>,
|
|
||||||
{
|
|
||||||
let pos = buf.position();
|
let pos = buf.position();
|
||||||
for block in &self.blocks {
|
for block in &self.blocks {
|
||||||
buf.emit_raw_bytes(block);
|
buf.emit_raw_bytes(block);
|
||||||
@ -323,34 +318,27 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<I: Idx, T: ParameterizedOverTcx> LazyTable<I, T>
|
impl<I: Idx, const N: usize, T: FixedSizeEncoding<ByteArray = [u8; N]> + ParameterizedOverTcx>
|
||||||
|
LazyTable<I, T>
|
||||||
where
|
where
|
||||||
Option<T>: FixedSizeEncoding,
|
for<'tcx> T::Value<'tcx>: FixedSizeEncoding<ByteArray = [u8; N]>,
|
||||||
{
|
{
|
||||||
/// Given the metadata, extract out the value at a particular index (if any).
|
/// Given the metadata, extract out the value at a particular index (if any).
|
||||||
#[inline(never)]
|
#[inline(never)]
|
||||||
pub(super) fn get<'a, 'tcx, M: Metadata<'a, 'tcx>, const N: usize>(
|
pub(super) fn get<'a, 'tcx, M: Metadata<'a, 'tcx>>(&self, metadata: M, i: I) -> T::Value<'tcx> {
|
||||||
&self,
|
|
||||||
metadata: M,
|
|
||||||
i: I,
|
|
||||||
) -> Option<T::Value<'tcx>>
|
|
||||||
where
|
|
||||||
Option<T::Value<'tcx>>: FixedSizeEncoding<ByteArray = [u8; N]>,
|
|
||||||
{
|
|
||||||
debug!("LazyTable::lookup: index={:?} len={:?}", i, self.encoded_size);
|
debug!("LazyTable::lookup: index={:?} len={:?}", i, self.encoded_size);
|
||||||
|
|
||||||
let start = self.position.get();
|
let start = self.position.get();
|
||||||
let bytes = &metadata.blob()[start..start + self.encoded_size];
|
let bytes = &metadata.blob()[start..start + self.encoded_size];
|
||||||
let (bytes, []) = bytes.as_chunks::<N>() else { panic!() };
|
let (bytes, []) = bytes.as_chunks::<N>() else { panic!() };
|
||||||
let bytes = bytes.get(i.index())?;
|
match bytes.get(i.index()) {
|
||||||
FixedSizeEncoding::from_bytes(bytes)
|
Some(bytes) => FixedSizeEncoding::from_bytes(bytes),
|
||||||
|
None => FixedSizeEncoding::from_bytes(&[0; N]),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Size of the table in entries, including possible gaps.
|
/// Size of the table in entries, including possible gaps.
|
||||||
pub(super) fn size<const N: usize>(&self) -> usize
|
pub(super) fn size(&self) -> usize {
|
||||||
where
|
|
||||||
for<'tcx> Option<T::Value<'tcx>>: FixedSizeEncoding<ByteArray = [u8; N]>,
|
|
||||||
{
|
|
||||||
self.encoded_size / N
|
self.encoded_size / N
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user