diff options
Diffstat (limited to 'compiler/rustc_metadata/src/rmeta/mod.rs')
-rw-r--r-- | compiler/rustc_metadata/src/rmeta/mod.rs | 78 |
1 files changed, 47 insertions, 31 deletions
diff --git a/compiler/rustc_metadata/src/rmeta/mod.rs b/compiler/rustc_metadata/src/rmeta/mod.rs index 5066dbbb9..a7ec2d790 100644 --- a/compiler/rustc_metadata/src/rmeta/mod.rs +++ b/compiler/rustc_metadata/src/rmeta/mod.rs @@ -9,7 +9,7 @@ use rustc_attr as attr; use rustc_data_structures::svh::Svh; use rustc_data_structures::sync::MetadataRef; use rustc_hir as hir; -use rustc_hir::def::{CtorKind, DefKind}; +use rustc_hir::def::{CtorKind, DefKind, DocLinkResMap}; use rustc_hir::def_id::{CrateNum, DefId, DefIndex, DefPathHash, StableCrateId}; use rustc_hir::definitions::DefKey; use rustc_hir::lang_items::LangItem; @@ -18,7 +18,7 @@ use rustc_index::vec::IndexVec; use rustc_middle::metadata::ModChild; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs; use rustc_middle::middle::exported_symbols::{ExportedSymbol, SymbolExportInfo}; -use rustc_middle::middle::resolve_lifetime::ObjectLifetimeDefault; +use rustc_middle::middle::resolve_bound_vars::ObjectLifetimeDefault; use rustc_middle::mir; use rustc_middle::ty::fast_reject::SimplifiedType; use rustc_middle::ty::query::Providers; @@ -115,14 +115,16 @@ impl<T: ParameterizedOverTcx> ParameterizedOverTcx for LazyArray<T> { type Value<'tcx> = LazyArray<T::Value<'tcx>>; } +impl<T> Default for LazyArray<T> { + fn default() -> LazyArray<T> { + LazyArray::from_position_and_num_elems(NonZeroUsize::new(1).unwrap(), 0) + } +} + impl<T> LazyArray<T> { fn from_position_and_num_elems(position: NonZeroUsize, num_elems: usize) -> LazyArray<T> { LazyArray { position, num_elems, _marker: PhantomData } } - - fn empty() -> LazyArray<T> { - LazyArray::from_position_and_num_elems(NonZeroUsize::new(1).unwrap(), 0) - } } /// A list of lazily-decoded values, with the added capability of random access. @@ -185,9 +187,9 @@ enum LazyState { Previous(NonZeroUsize), } -type SyntaxContextTable = LazyTable<u32, LazyValue<SyntaxContextData>>; -type ExpnDataTable = LazyTable<ExpnIndex, LazyValue<ExpnData>>; -type ExpnHashTable = LazyTable<ExpnIndex, LazyValue<ExpnHash>>; +type SyntaxContextTable = LazyTable<u32, Option<LazyValue<SyntaxContextData>>>; +type ExpnDataTable = LazyTable<ExpnIndex, Option<LazyValue<ExpnData>>>; +type ExpnHashTable = LazyTable<ExpnIndex, Option<LazyValue<ExpnHash>>>; #[derive(MetadataEncodable, MetadataDecodable)] pub(crate) struct ProcMacroData { @@ -253,7 +255,7 @@ pub(crate) struct CrateRoot { 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, needs_allocator: bool, @@ -315,21 +317,27 @@ pub(crate) struct IncoherentImpls { /// Define `LazyTables` and `TableBuilders` at the same time. macro_rules! define_tables { - ($($name:ident: Table<$IDX:ty, $T:ty>),+ $(,)?) => { + ( + - defaulted: $($name1:ident: Table<$IDX1:ty, $T1:ty>,)+ + - optional: $($name2:ident: Table<$IDX2:ty, $T2:ty>,)+ + ) => { #[derive(MetadataEncodable, MetadataDecodable)] pub(crate) struct LazyTables { - $($name: LazyTable<$IDX, $T>),+ + $($name1: LazyTable<$IDX1, $T1>,)+ + $($name2: LazyTable<$IDX2, Option<$T2>>,)+ } #[derive(Default)] struct TableBuilders { - $($name: TableBuilder<$IDX, $T>),+ + $($name1: TableBuilder<$IDX1, $T1>,)+ + $($name2: TableBuilder<$IDX2, Option<$T2>>,)+ } impl TableBuilders { fn encode(&self, buf: &mut FileEncoder) -> LazyTables { LazyTables { - $($name: self.$name.encode(buf)),+ + $($name1: self.$name1.encode(buf),)+ + $($name2: self.$name2.encode(buf),)+ } } } @@ -337,9 +345,20 @@ macro_rules! define_tables { } define_tables! { +- defaulted: + is_intrinsic: Table<DefIndex, bool>, + is_macro_rules: Table<DefIndex, bool>, + is_type_alias_impl_trait: Table<DefIndex, bool>, + attr_flags: Table<DefIndex, AttrFlags>, + def_path_hashes: Table<DefIndex, DefPathHash>, + explicit_item_bounds: Table<DefIndex, LazyArray<(ty::Predicate<'static>, Span)>>, + inferred_outlives_of: Table<DefIndex, LazyArray<(ty::Clause<'static>, Span)>>, + inherent_impls: Table<DefIndex, LazyArray<DefIndex>>, + associated_items_for_impl_trait_in_trait: Table<DefIndex, LazyArray<DefId>>, + +- optional: attributes: Table<DefIndex, LazyArray<ast::Attribute>>, children: Table<DefIndex, LazyArray<DefIndex>>, - opt_def_kind: Table<DefIndex, DefKind>, visibility: Table<DefIndex, LazyValue<ty::Visibility<DefIndex>>>, def_span: Table<DefIndex, LazyValue<Span>>, @@ -348,29 +367,25 @@ define_tables! { lookup_const_stability: Table<DefIndex, LazyValue<attr::ConstStability>>, lookup_default_body_stability: Table<DefIndex, LazyValue<attr::DefaultBodyStability>>, lookup_deprecation_entry: Table<DefIndex, LazyValue<attr::Deprecation>>, - // As an optimization, a missing entry indicates an empty `&[]`. - explicit_item_bounds: Table<DefIndex, LazyArray<(ty::Predicate<'static>, Span)>>, explicit_predicates_of: Table<DefIndex, LazyValue<ty::GenericPredicates<'static>>>, generics_of: Table<DefIndex, LazyValue<ty::Generics>>, - // As an optimization, a missing entry indicates an empty `&[]`. - inferred_outlives_of: Table<DefIndex, LazyArray<(ty::Clause<'static>, Span)>>, super_predicates_of: Table<DefIndex, LazyValue<ty::GenericPredicates<'static>>>, - type_of: Table<DefIndex, LazyValue<Ty<'static>>>, + type_of: Table<DefIndex, LazyValue<ty::EarlyBinder<Ty<'static>>>>, variances_of: Table<DefIndex, LazyArray<ty::Variance>>, - fn_sig: Table<DefIndex, LazyValue<ty::PolyFnSig<'static>>>, + fn_sig: Table<DefIndex, LazyValue<ty::EarlyBinder<ty::PolyFnSig<'static>>>>, codegen_fn_attrs: Table<DefIndex, LazyValue<CodegenFnAttrs>>, impl_trait_ref: Table<DefIndex, LazyValue<ty::EarlyBinder<ty::TraitRef<'static>>>>, const_param_default: Table<DefIndex, LazyValue<ty::EarlyBinder<rustc_middle::ty::Const<'static>>>>, object_lifetime_default: Table<DefIndex, LazyValue<ObjectLifetimeDefault>>, optimized_mir: Table<DefIndex, LazyValue<mir::Body<'static>>>, mir_for_ctfe: Table<DefIndex, LazyValue<mir::Body<'static>>>, + mir_generator_witnesses: Table<DefIndex, LazyValue<mir::GeneratorLayout<'static>>>, promoted_mir: Table<DefIndex, LazyValue<IndexVec<mir::Promoted, mir::Body<'static>>>>, // FIXME(compiler-errors): Why isn't this a LazyArray? thir_abstract_const: Table<DefIndex, LazyValue<ty::Const<'static>>>, impl_parent: Table<DefIndex, RawDefId>, impl_polarity: Table<DefIndex, ty::ImplPolarity>, constness: Table<DefIndex, hir::Constness>, - is_intrinsic: Table<DefIndex, ()>, impl_defaultness: Table<DefIndex, hir::Defaultness>, // FIXME(eddyb) perhaps compute this on the fly if cheap enough? coerce_unsized_info: Table<DefIndex, LazyValue<ty::adjustment::CoerceUnsizedInfo>>, @@ -380,9 +395,7 @@ define_tables! { fn_arg_names: Table<DefIndex, LazyArray<Ident>>, generator_kind: Table<DefIndex, LazyValue<hir::GeneratorKind>>, trait_def: Table<DefIndex, LazyValue<ty::TraitDef>>, - trait_item_def_id: Table<DefIndex, RawDefId>, - inherent_impls: Table<DefIndex, LazyArray<DefIndex>>, expn_that_defined: Table<DefIndex, LazyValue<ExpnId>>, unused_generic_params: Table<DefIndex, LazyValue<UnusedGenericParams>>, params_in_repr: Table<DefIndex, LazyValue<BitSet<u32>>>, @@ -392,22 +405,17 @@ define_tables! { // `DefPathTable` up front, since we may only ever use a few // definitions from any given crate. def_keys: Table<DefIndex, LazyValue<DefKey>>, - def_path_hashes: Table<DefIndex, DefPathHash>, proc_macro_quoted_spans: Table<usize, LazyValue<Span>>, generator_diagnostic_data: Table<DefIndex, LazyValue<GeneratorDiagnosticData<'static>>>, - may_have_doc_links: Table<DefIndex, ()>, variant_data: Table<DefIndex, LazyValue<VariantData>>, 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>>, proc_macro: Table<DefIndex, MacroKind>, module_reexports: Table<DefIndex, LazyArray<ModChild>>, 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>>>>, + doc_link_resolutions: Table<DefIndex, LazyValue<DocLinkResMap>>, + doc_link_traits_in_scope: Table<DefIndex, LazyArray<DefId>>, } #[derive(TyEncodable, TyDecodable)] @@ -418,6 +426,13 @@ struct VariantData { is_non_exhaustive: bool, } +bitflags::bitflags! { + #[derive(Default)] + pub struct AttrFlags: u8 { + const IS_DOC_HIDDEN = 1 << 0; + } +} + // Tags used for encoding Spans: const TAG_VALID_SPAN_LOCAL: u8 = 0; const TAG_VALID_SPAN_FOREIGN: u8 = 1; @@ -440,4 +455,5 @@ trivially_parameterized_over_tcx! { IncoherentImpls, CrateRoot, CrateDep, + AttrFlags, } |