2019-11-03 15:33:27 +01:00
|
|
|
use decoder::Metadata;
|
2019-11-14 03:42:21 +01:00
|
|
|
use table::{Table, TableBuilder};
|
2016-09-16 16:25:54 +02:00
|
|
|
|
2020-03-13 22:00:35 +01:00
|
|
|
use rustc_ast::ast::{self, MacroDef};
|
2020-01-11 13:15:20 +01:00
|
|
|
use rustc_attr as attr;
|
2018-08-03 20:22:22 +02:00
|
|
|
use rustc_data_structures::svh::Svh;
|
2019-11-17 11:47:30 +01:00
|
|
|
use rustc_data_structures::sync::MetadataRef;
|
2020-01-05 02:37:57 +01:00
|
|
|
use rustc_hir as hir;
|
|
|
|
use rustc_hir::def::CtorKind;
|
|
|
|
use rustc_hir::def_id::{DefId, DefIndex};
|
2020-03-31 21:38:14 +02:00
|
|
|
use rustc_hir::lang_items;
|
2020-07-17 13:28:23 +02:00
|
|
|
use rustc_index::{bit_set::FiniteBitSet, vec::IndexVec};
|
2020-03-29 17:19:48 +02:00
|
|
|
use rustc_middle::hir::exports::Export;
|
2020-08-02 14:24:22 +02:00
|
|
|
use rustc_middle::middle::cstore::{CrateDepKind, ForeignModule, LinkagePreference, NativeLib};
|
2020-03-29 17:19:48 +02:00
|
|
|
use rustc_middle::middle::exported_symbols::{ExportedSymbol, SymbolExportLevel};
|
|
|
|
use rustc_middle::mir;
|
|
|
|
use rustc_middle::ty::{self, ReprOptions, Ty};
|
2019-11-14 03:42:21 +01:00
|
|
|
use rustc_serialize::opaque::Encoder;
|
2020-03-11 12:49:08 +01:00
|
|
|
use rustc_session::config::SymbolManglingVersion;
|
|
|
|
use rustc_session::CrateDisambiguator;
|
2020-01-01 19:40:49 +01:00
|
|
|
use rustc_span::edition::Edition;
|
2020-06-11 19:42:22 +02:00
|
|
|
use rustc_span::symbol::{Ident, Symbol};
|
2020-03-17 16:45:02 +01:00
|
|
|
use rustc_span::{self, ExpnData, ExpnId, Span};
|
2019-12-22 23:42:04 +01:00
|
|
|
use rustc_target::spec::{PanicStrategy, TargetTriple};
|
2016-09-16 16:25:54 +02:00
|
|
|
|
|
|
|
use std::marker::PhantomData;
|
2019-04-11 17:24:38 +02:00
|
|
|
use std::num::NonZeroUsize;
|
2017-04-05 13:00:17 +02:00
|
|
|
|
2020-06-11 16:49:57 +02:00
|
|
|
use decoder::DecodeContext;
|
2019-11-03 15:36:16 +01:00
|
|
|
pub use decoder::{provide, provide_extern};
|
2019-11-17 14:50:46 +01:00
|
|
|
crate use decoder::{CrateMetadata, CrateNumMap, MetadataBlob};
|
2020-06-11 16:49:57 +02:00
|
|
|
use encoder::EncodeContext;
|
2020-03-17 16:45:02 +01:00
|
|
|
use rustc_span::hygiene::SyntaxContextData;
|
2019-11-03 13:56:11 +01:00
|
|
|
|
|
|
|
mod decoder;
|
|
|
|
mod encoder;
|
|
|
|
mod table;
|
|
|
|
|
2019-10-06 13:30:46 +02:00
|
|
|
crate fn rustc_version() -> String {
|
2019-12-22 23:42:04 +01:00
|
|
|
format!("rustc {}", option_env!("CFG_VERSION").unwrap_or("unknown version"))
|
2016-10-01 00:24:50 +02:00
|
|
|
}
|
2016-09-18 13:05:49 +02:00
|
|
|
|
2016-09-16 16:25:54 +02:00
|
|
|
/// Metadata encoding version.
|
2018-11-27 03:59:49 +01:00
|
|
|
/// N.B., increment this if you change the format of metadata such that
|
2016-11-22 13:51:55 +01:00
|
|
|
/// the rustc version can't be found to compare with `rustc_version()`.
|
2019-11-09 01:06:22 +01:00
|
|
|
const METADATA_VERSION: u8 = 5;
|
2016-09-16 16:25:54 +02:00
|
|
|
|
|
|
|
/// Metadata header which includes `METADATA_VERSION`.
|
|
|
|
///
|
2016-11-22 13:51:55 +01:00
|
|
|
/// This header is followed by the position of the `CrateRoot`,
|
|
|
|
/// which is encoded as a 32-bit big-endian unsigned integer,
|
|
|
|
/// and further followed by the rustc version string.
|
2019-12-22 23:42:04 +01:00
|
|
|
crate const METADATA_HEADER: &[u8; 8] = &[b'r', b'u', b's', b't', 0, 0, 0, METADATA_VERSION];
|
2016-09-16 16:25:54 +02:00
|
|
|
|
2019-05-22 12:30:07 +02:00
|
|
|
/// Additional metadata for a `Lazy<T>` where `T` may not be `Sized`,
|
|
|
|
/// e.g. for `Lazy<[T]>`, this is the length (count of `T` values).
|
2019-11-17 16:46:38 +01:00
|
|
|
trait LazyMeta {
|
2019-05-22 12:30:07 +02:00
|
|
|
type Meta: Copy + 'static;
|
|
|
|
|
|
|
|
/// Returns the minimum encoded size.
|
|
|
|
// FIXME(eddyb) Give better estimates for certain types.
|
|
|
|
fn min_size(meta: Self::Meta) -> usize;
|
|
|
|
}
|
|
|
|
|
2019-11-14 01:52:59 +01:00
|
|
|
impl<T> LazyMeta for T {
|
2019-05-22 12:30:07 +02:00
|
|
|
type Meta = ();
|
|
|
|
|
|
|
|
fn min_size(_: ()) -> usize {
|
|
|
|
assert_ne!(std::mem::size_of::<T>(), 0);
|
|
|
|
1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-14 01:52:59 +01:00
|
|
|
impl<T> LazyMeta for [T] {
|
2019-05-22 12:30:07 +02:00
|
|
|
type Meta = usize;
|
|
|
|
|
|
|
|
fn min_size(len: usize) -> usize {
|
|
|
|
len * T::min_size(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-16 16:25:54 +02:00
|
|
|
/// A value of type T referred to by its absolute position
|
|
|
|
/// in the metadata, and which can be decoded lazily.
|
2016-09-17 09:33:47 +02:00
|
|
|
///
|
|
|
|
/// Metadata is effective a tree, encoded in post-order,
|
|
|
|
/// and with the root's position written next to the header.
|
|
|
|
/// That means every single `Lazy` points to some previous
|
|
|
|
/// location in the metadata and is part of a larger node.
|
|
|
|
///
|
|
|
|
/// The first `Lazy` in a node is encoded as the backwards
|
|
|
|
/// distance from the position where the containing node
|
|
|
|
/// starts and where the `Lazy` points to, while the rest
|
|
|
|
/// use the forward distance from the previous `Lazy`.
|
|
|
|
/// Distances start at 1, as 0-byte nodes are invalid.
|
|
|
|
/// Also invalid are nodes being referred in a different
|
|
|
|
/// order than they were encoded in.
|
2019-05-22 12:30:07 +02:00
|
|
|
///
|
|
|
|
/// # Sequences (`Lazy<[T]>`)
|
2016-09-16 16:25:54 +02:00
|
|
|
///
|
|
|
|
/// Unlike `Lazy<Vec<T>>`, the length is encoded next to the
|
|
|
|
/// position, not at the position, which means that the length
|
|
|
|
/// doesn't need to be known before encoding all the elements.
|
2016-09-17 09:33:47 +02:00
|
|
|
///
|
|
|
|
/// If the length is 0, no position is encoded, but otherwise,
|
|
|
|
/// the encoding is that of `Lazy`, with the distinction that
|
|
|
|
/// the minimal distance the length of the sequence, i.e.
|
|
|
|
/// it's assumed there's no 0-byte element in the sequence.
|
2016-09-16 16:25:54 +02:00
|
|
|
#[must_use]
|
2019-05-22 12:30:07 +02:00
|
|
|
// FIXME(#59875) the `Meta` parameter only exists to dodge
|
|
|
|
// invariance wrt `T` (coming from the `meta: T::Meta` field).
|
2019-11-17 16:46:38 +01:00
|
|
|
struct Lazy<T, Meta = <T as LazyMeta>::Meta>
|
2019-12-22 23:42:04 +01:00
|
|
|
where
|
|
|
|
T: ?Sized + LazyMeta<Meta = Meta>,
|
|
|
|
Meta: 'static + Copy,
|
2019-05-22 12:30:07 +02:00
|
|
|
{
|
2019-11-03 15:33:27 +01:00
|
|
|
position: NonZeroUsize,
|
|
|
|
meta: Meta,
|
2016-10-22 15:14:32 +02:00
|
|
|
_marker: PhantomData<T>,
|
2016-09-16 16:25:54 +02:00
|
|
|
}
|
|
|
|
|
2019-05-22 12:30:07 +02:00
|
|
|
impl<T: ?Sized + LazyMeta> Lazy<T> {
|
2019-12-22 23:42:04 +01:00
|
|
|
fn from_position_and_meta(position: NonZeroUsize, meta: T::Meta) -> Lazy<T> {
|
|
|
|
Lazy { position, meta, _marker: PhantomData }
|
2016-09-16 16:25:54 +02:00
|
|
|
}
|
2019-05-22 12:30:07 +02:00
|
|
|
}
|
|
|
|
|
2019-11-14 01:52:59 +01:00
|
|
|
impl<T> Lazy<T> {
|
2019-11-03 15:33:27 +01:00
|
|
|
fn from_position(position: NonZeroUsize) -> Lazy<T> {
|
2019-05-22 12:30:07 +02:00
|
|
|
Lazy::from_position_and_meta(position, ())
|
|
|
|
}
|
|
|
|
}
|
2016-09-17 09:33:47 +02:00
|
|
|
|
2019-11-14 01:52:59 +01:00
|
|
|
impl<T> Lazy<[T]> {
|
2019-11-03 15:33:27 +01:00
|
|
|
fn empty() -> Lazy<[T]> {
|
2019-04-11 17:24:38 +02:00
|
|
|
Lazy::from_position_and_meta(NonZeroUsize::new(1).unwrap(), 0)
|
2016-09-17 09:33:47 +02:00
|
|
|
}
|
2016-09-16 16:25:54 +02:00
|
|
|
}
|
|
|
|
|
2019-05-22 12:30:07 +02:00
|
|
|
impl<T: ?Sized + LazyMeta> Copy for Lazy<T> {}
|
|
|
|
impl<T: ?Sized + LazyMeta> Clone for Lazy<T> {
|
2016-10-22 15:14:32 +02:00
|
|
|
fn clone(&self) -> Self {
|
|
|
|
*self
|
|
|
|
}
|
2016-09-16 16:25:54 +02:00
|
|
|
}
|
|
|
|
|
2019-05-22 12:30:07 +02:00
|
|
|
/// Encoding / decoding state for `Lazy`.
|
2016-09-17 09:33:47 +02:00
|
|
|
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
2019-11-03 15:33:27 +01:00
|
|
|
enum LazyState {
|
2016-09-17 09:33:47 +02:00
|
|
|
/// Outside of a metadata node.
|
|
|
|
NoNode,
|
|
|
|
|
2019-05-22 12:30:07 +02:00
|
|
|
/// Inside a metadata node, and before any `Lazy`.
|
2016-09-17 09:33:47 +02:00
|
|
|
/// The position is that of the node itself.
|
2019-04-11 17:24:38 +02:00
|
|
|
NodeStart(NonZeroUsize),
|
2016-09-17 09:33:47 +02:00
|
|
|
|
2019-05-22 12:30:07 +02:00
|
|
|
/// Inside a metadata node, with a previous `Lazy`.
|
2016-09-17 09:33:47 +02:00
|
|
|
/// The position is a conservative estimate of where that
|
2019-05-22 12:30:07 +02:00
|
|
|
/// previous `Lazy` would end (see their comments).
|
2019-04-11 17:24:38 +02:00
|
|
|
Previous(NonZeroUsize),
|
2016-09-17 09:33:47 +02:00
|
|
|
}
|
|
|
|
|
2019-04-11 21:52:12 +02:00
|
|
|
// FIXME(#59875) `Lazy!(T)` replaces `Lazy<T>`, passing the `Meta` parameter
|
|
|
|
// manually, instead of relying on the default, to get the correct variance.
|
|
|
|
// Only needed when `T` itself contains a parameter (e.g. `'tcx`).
|
|
|
|
macro_rules! Lazy {
|
2019-11-13 21:10:58 +01:00
|
|
|
(Table<$I:ty, $T:ty>) => {Lazy<Table<$I, $T>, usize>};
|
2019-04-11 21:52:12 +02:00
|
|
|
([$T:ty]) => {Lazy<[$T], usize>};
|
|
|
|
($T:ty) => {Lazy<$T, ()>};
|
|
|
|
}
|
|
|
|
|
2020-03-17 16:45:02 +01:00
|
|
|
type SyntaxContextTable = Lazy<Table<u32, Lazy<SyntaxContextData>>>;
|
|
|
|
type ExpnDataTable = Lazy<Table<u32, Lazy<ExpnData>>>;
|
|
|
|
|
2020-06-11 16:49:57 +02:00
|
|
|
#[derive(MetadataEncodable, MetadataDecodable)]
|
2019-10-06 13:30:46 +02:00
|
|
|
crate struct CrateRoot<'tcx> {
|
2019-11-23 21:46:32 +01:00
|
|
|
name: Symbol,
|
|
|
|
triple: TargetTriple,
|
2019-11-03 16:27:24 +01:00
|
|
|
extra_filename: String,
|
2019-11-23 21:46:32 +01:00
|
|
|
hash: Svh,
|
|
|
|
disambiguator: CrateDisambiguator,
|
|
|
|
panic_strategy: PanicStrategy,
|
2019-11-03 16:27:24 +01:00
|
|
|
edition: Edition,
|
2019-11-23 21:46:32 +01:00
|
|
|
has_global_allocator: bool,
|
2019-11-03 16:27:24 +01:00
|
|
|
has_panic_handler: bool,
|
2019-11-23 21:46:32 +01:00
|
|
|
has_default_lib_allocator: bool,
|
2019-11-03 16:27:24 +01:00
|
|
|
plugin_registrar_fn: Option<DefIndex>,
|
|
|
|
proc_macro_decls_static: Option<DefIndex>,
|
2019-11-03 15:33:27 +01:00
|
|
|
proc_macro_stability: Option<attr::Stability>,
|
2016-09-16 16:25:54 +02:00
|
|
|
|
2019-11-17 16:46:38 +01:00
|
|
|
crate_deps: Lazy<[CrateDep]>,
|
2019-11-03 15:33:27 +01:00
|
|
|
dylib_dependency_formats: Lazy<[Option<LinkagePreference>]>,
|
|
|
|
lib_features: Lazy<[(Symbol, Option<Symbol>)]>,
|
|
|
|
lang_items: Lazy<[(DefIndex, usize)]>,
|
|
|
|
lang_items_missing: Lazy<[lang_items::LangItem]>,
|
|
|
|
diagnostic_items: Lazy<[(Symbol, DefIndex)]>,
|
2020-05-17 23:18:50 +02:00
|
|
|
native_libraries: Lazy<[NativeLib]>,
|
2019-11-03 15:33:27 +01:00
|
|
|
foreign_modules: Lazy<[ForeignModule]>,
|
2020-03-24 09:09:42 +01:00
|
|
|
def_path_table: Lazy<rustc_hir::definitions::DefPathTable>,
|
2019-11-17 14:50:46 +01:00
|
|
|
impls: Lazy<[TraitImpls]>,
|
|
|
|
interpret_alloc_index: Lazy<[u32]>,
|
2018-02-27 19:28:21 +01:00
|
|
|
|
2020-03-30 19:06:00 +02:00
|
|
|
tables: LazyTables<'tcx>,
|
2018-05-12 19:20:53 +02:00
|
|
|
|
2020-03-06 12:13:55 +01:00
|
|
|
/// The DefIndex's of any proc macros declared by this crate.
|
2019-11-17 16:46:38 +01:00
|
|
|
proc_macro_data: Option<Lazy<[DefIndex]>>,
|
2019-08-04 22:41:01 +02:00
|
|
|
|
2020-01-11 03:42:40 +01:00
|
|
|
exported_symbols: Lazy!([(ExportedSymbol<'tcx>, SymbolExportLevel)]),
|
2020-03-17 16:45:02 +01:00
|
|
|
|
|
|
|
syntax_contexts: SyntaxContextTable,
|
|
|
|
expn_data: ExpnDataTable,
|
|
|
|
|
2020-06-24 19:16:36 +02:00
|
|
|
source_map: Lazy<[rustc_span::SourceFile]>,
|
2020-01-11 03:42:40 +01:00
|
|
|
|
2019-11-03 16:27:24 +01:00
|
|
|
compiler_builtins: bool,
|
2019-11-23 21:46:32 +01:00
|
|
|
needs_allocator: bool,
|
|
|
|
needs_panic_runtime: bool,
|
2019-11-03 16:27:24 +01:00
|
|
|
no_builtins: bool,
|
2019-11-23 21:46:32 +01:00
|
|
|
panic_runtime: bool,
|
|
|
|
profiler_runtime: bool,
|
2019-11-03 16:27:24 +01:00
|
|
|
symbol_mangling_version: SymbolManglingVersion,
|
2016-09-16 16:25:54 +02:00
|
|
|
}
|
|
|
|
|
2020-06-11 16:49:57 +02:00
|
|
|
#[derive(Encodable, Decodable)]
|
2019-10-06 13:30:46 +02:00
|
|
|
crate struct CrateDep {
|
2020-04-19 13:00:18 +02:00
|
|
|
pub name: Symbol,
|
2018-08-03 20:22:22 +02:00
|
|
|
pub hash: Svh,
|
2019-10-22 10:47:07 +02:00
|
|
|
pub host_hash: Option<Svh>,
|
2020-08-02 14:24:22 +02:00
|
|
|
pub kind: CrateDepKind,
|
2018-03-13 19:58:53 +01:00
|
|
|
pub extra_filename: String,
|
2016-09-16 16:25:54 +02:00
|
|
|
}
|
|
|
|
|
2020-06-11 16:49:57 +02:00
|
|
|
#[derive(MetadataEncodable, MetadataDecodable)]
|
2019-10-06 13:30:46 +02:00
|
|
|
crate struct TraitImpls {
|
2019-11-17 14:50:46 +01:00
|
|
|
trait_id: (u32, DefIndex),
|
2020-08-01 15:14:22 +02:00
|
|
|
impls: Lazy<[(DefIndex, Option<ty::fast_reject::SimplifiedType>)]>,
|
2016-09-16 16:25:54 +02:00
|
|
|
}
|
|
|
|
|
2020-03-30 19:06:00 +02:00
|
|
|
/// Define `LazyTables` and `TableBuilders` at the same time.
|
|
|
|
macro_rules! define_tables {
|
2019-11-14 03:42:21 +01:00
|
|
|
($($name:ident: Table<DefIndex, $T:ty>),+ $(,)?) => {
|
2020-06-11 16:49:57 +02:00
|
|
|
#[derive(MetadataEncodable, MetadataDecodable)]
|
2020-03-30 19:06:00 +02:00
|
|
|
crate struct LazyTables<'tcx> {
|
2019-11-14 03:42:21 +01:00
|
|
|
$($name: Lazy!(Table<DefIndex, $T>)),+
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Default)]
|
2020-03-30 19:06:00 +02:00
|
|
|
struct TableBuilders<'tcx> {
|
2019-11-14 03:42:21 +01:00
|
|
|
$($name: TableBuilder<DefIndex, $T>),+
|
|
|
|
}
|
|
|
|
|
2020-03-30 19:06:00 +02:00
|
|
|
impl TableBuilders<'tcx> {
|
|
|
|
fn encode(&self, buf: &mut Encoder) -> LazyTables<'tcx> {
|
|
|
|
LazyTables {
|
2019-11-14 03:42:21 +01:00
|
|
|
$($name: self.$name.encode(buf)),+
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-30 19:06:00 +02:00
|
|
|
define_tables! {
|
2020-01-26 02:09:23 +01:00
|
|
|
kind: Table<DefIndex, Lazy<EntryKind>>,
|
2019-11-14 03:42:21 +01:00
|
|
|
visibility: Table<DefIndex, Lazy<ty::Visibility>>,
|
|
|
|
span: Table<DefIndex, Lazy<Span>>,
|
2020-03-17 16:45:02 +01:00
|
|
|
ident_span: Table<DefIndex, Lazy<Span>>,
|
2019-11-14 03:42:21 +01:00
|
|
|
attributes: Table<DefIndex, Lazy<[ast::Attribute]>>,
|
|
|
|
children: Table<DefIndex, Lazy<[DefIndex]>>,
|
|
|
|
stability: Table<DefIndex, Lazy<attr::Stability>>,
|
2019-12-08 01:43:10 +01:00
|
|
|
const_stability: Table<DefIndex, Lazy<attr::ConstStability>>,
|
2019-11-14 03:42:21 +01:00
|
|
|
deprecation: Table<DefIndex, Lazy<attr::Deprecation>>,
|
|
|
|
ty: Table<DefIndex, Lazy!(Ty<'tcx>)>,
|
|
|
|
fn_sig: Table<DefIndex, Lazy!(ty::PolyFnSig<'tcx>)>,
|
|
|
|
impl_trait_ref: Table<DefIndex, Lazy!(ty::TraitRef<'tcx>)>,
|
|
|
|
inherent_impls: Table<DefIndex, Lazy<[DefIndex]>>,
|
|
|
|
variances: Table<DefIndex, Lazy<[ty::Variance]>>,
|
|
|
|
generics: Table<DefIndex, Lazy<ty::Generics>>,
|
|
|
|
explicit_predicates: Table<DefIndex, Lazy!(ty::GenericPredicates<'tcx>)>,
|
2019-04-09 22:17:56 +02:00
|
|
|
// FIXME(eddyb) this would ideally be `Lazy<[...]>` but `ty::Predicate`
|
|
|
|
// doesn't handle shorthands in its own (de)serialization impls,
|
|
|
|
// as it's an `enum` for which we want to derive (de)serialization,
|
|
|
|
// so the `ty::codec` APIs handle the whole `&'tcx [...]` at once.
|
2019-04-10 22:27:39 +02:00
|
|
|
// Also, as an optimization, a missing entry indicates an empty `&[]`.
|
2019-11-14 03:42:21 +01:00
|
|
|
inferred_outlives: Table<DefIndex, Lazy!(&'tcx [(ty::Predicate<'tcx>, Span)])>,
|
|
|
|
super_predicates: Table<DefIndex, Lazy!(ty::GenericPredicates<'tcx>)>,
|
2020-04-12 19:31:00 +02:00
|
|
|
mir: Table<DefIndex, Lazy!(mir::Body<'tcx>)>,
|
|
|
|
promoted_mir: Table<DefIndex, Lazy!(IndexVec<mir::Promoted, mir::Body<'tcx>>)>,
|
2020-08-04 19:11:57 +02:00
|
|
|
unused_generic_params: Table<DefIndex, Lazy<FiniteBitSet<u32>>>,
|
2016-09-16 16:25:54 +02:00
|
|
|
}
|
|
|
|
|
2020-06-11 16:49:57 +02:00
|
|
|
#[derive(Copy, Clone, MetadataEncodable, MetadataDecodable)]
|
2020-01-26 02:09:23 +01:00
|
|
|
enum EntryKind {
|
2020-05-26 06:18:47 +02:00
|
|
|
AnonConst(mir::ConstQualifs, Lazy<RenderedConst>),
|
2019-11-14 21:07:35 +01:00
|
|
|
Const(mir::ConstQualifs, Lazy<RenderedConst>),
|
2016-09-16 16:25:54 +02:00
|
|
|
ImmStatic,
|
|
|
|
MutStatic,
|
|
|
|
ForeignImmStatic,
|
|
|
|
ForeignMutStatic,
|
|
|
|
ForeignMod,
|
2017-09-03 20:53:58 +02:00
|
|
|
ForeignType,
|
2017-03-16 03:27:40 +01:00
|
|
|
GlobalAsm,
|
2016-09-16 16:25:54 +02:00
|
|
|
Type,
|
2019-03-14 01:14:33 +01:00
|
|
|
TypeParam,
|
|
|
|
ConstParam,
|
2019-08-01 01:41:54 +02:00
|
|
|
OpaqueTy,
|
2017-02-05 06:01:48 +01:00
|
|
|
Enum(ReprOptions),
|
2016-09-16 16:25:54 +02:00
|
|
|
Field,
|
2019-10-18 21:15:14 +02:00
|
|
|
Variant(Lazy<VariantData>),
|
|
|
|
Struct(Lazy<VariantData>, ReprOptions),
|
|
|
|
Union(Lazy<VariantData>, ReprOptions),
|
|
|
|
Fn(Lazy<FnData>),
|
|
|
|
ForeignFn(Lazy<FnData>),
|
2016-09-16 16:25:54 +02:00
|
|
|
Mod(Lazy<ModData>),
|
2016-10-28 08:52:45 +02:00
|
|
|
MacroDef(Lazy<MacroDef>),
|
2019-10-18 21:15:14 +02:00
|
|
|
Closure,
|
2020-02-22 20:05:32 +01:00
|
|
|
Generator(hir::GeneratorKind),
|
2019-10-18 20:22:41 +02:00
|
|
|
Trait(Lazy<TraitData>),
|
2019-10-19 00:10:58 +02:00
|
|
|
Impl(Lazy<ImplData>),
|
2020-03-15 17:19:17 +01:00
|
|
|
AssocFn(Lazy<AssocFnData>),
|
2019-05-19 10:26:08 +02:00
|
|
|
AssocType(AssocContainer),
|
2019-11-14 21:07:35 +01:00
|
|
|
AssocConst(AssocContainer, mir::ConstQualifs, Lazy<RenderedConst>),
|
2019-10-18 20:22:41 +02:00
|
|
|
TraitAlias,
|
2016-09-16 16:25:54 +02:00
|
|
|
}
|
|
|
|
|
2018-04-16 01:41:33 +02:00
|
|
|
/// Contains a constant which has been rendered to a String.
|
|
|
|
/// Used by rustdoc.
|
2020-06-11 16:49:57 +02:00
|
|
|
#[derive(Encodable, Decodable)]
|
2019-11-03 15:33:27 +01:00
|
|
|
struct RenderedConst(String);
|
2018-04-16 01:41:33 +02:00
|
|
|
|
2020-06-11 16:49:57 +02:00
|
|
|
#[derive(MetadataEncodable, MetadataDecodable)]
|
2019-11-03 15:33:27 +01:00
|
|
|
struct ModData {
|
2020-01-02 04:53:12 +01:00
|
|
|
reexports: Lazy<[Export<hir::HirId>]>,
|
2020-03-17 16:45:02 +01:00
|
|
|
expansion: ExpnId,
|
2016-09-16 16:25:54 +02:00
|
|
|
}
|
|
|
|
|
2020-06-11 16:49:57 +02:00
|
|
|
#[derive(MetadataEncodable, MetadataDecodable)]
|
2019-11-03 15:33:27 +01:00
|
|
|
struct FnData {
|
|
|
|
asyncness: hir::IsAsync,
|
|
|
|
constness: hir::Constness,
|
2020-06-11 19:42:22 +02:00
|
|
|
param_names: Lazy<[Ident]>,
|
2016-09-16 16:25:54 +02:00
|
|
|
}
|
|
|
|
|
2020-06-11 16:49:57 +02:00
|
|
|
#[derive(TyEncodable, TyDecodable)]
|
2019-11-03 15:33:27 +01:00
|
|
|
struct VariantData {
|
|
|
|
ctor_kind: CtorKind,
|
|
|
|
discr: ty::VariantDiscr,
|
2019-03-21 23:38:50 +01:00
|
|
|
/// If this is unit or tuple-variant/struct, then this is the index of the ctor id.
|
2019-11-03 15:33:27 +01:00
|
|
|
ctor: Option<DefIndex>,
|
2020-07-28 19:31:48 +02:00
|
|
|
is_non_exhaustive: bool,
|
2016-09-16 16:25:54 +02:00
|
|
|
}
|
|
|
|
|
2020-06-11 16:49:57 +02:00
|
|
|
#[derive(TyEncodable, TyDecodable)]
|
2019-11-03 15:33:27 +01:00
|
|
|
struct TraitData {
|
|
|
|
unsafety: hir::Unsafety,
|
|
|
|
paren_sugar: bool,
|
|
|
|
has_auto_impl: bool,
|
|
|
|
is_marker: bool,
|
2020-02-08 18:56:25 +01:00
|
|
|
specialization_kind: ty::trait_def::TraitSpecializationKind,
|
2019-01-08 16:55:18 +01:00
|
|
|
}
|
|
|
|
|
2020-06-11 16:49:57 +02:00
|
|
|
#[derive(TyEncodable, TyDecodable)]
|
2019-11-03 15:33:27 +01:00
|
|
|
struct ImplData {
|
|
|
|
polarity: ty::ImplPolarity,
|
|
|
|
defaultness: hir::Defaultness,
|
|
|
|
parent_impl: Option<DefId>,
|
2017-03-17 21:17:45 +01:00
|
|
|
|
|
|
|
/// This is `Some` only for impls of `CoerceUnsized`.
|
2019-10-19 00:10:58 +02:00
|
|
|
// FIXME(eddyb) perhaps compute this on the fly if cheap enough?
|
2019-11-03 15:33:27 +01:00
|
|
|
coerce_unsized_info: Option<ty::adjustment::CoerceUnsizedInfo>,
|
2016-09-16 16:25:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Describes whether the container of an associated item
|
|
|
|
/// is a trait or an impl and whether, in a trait, it has
|
|
|
|
/// a default, or an in impl, whether it's marked "default".
|
2020-06-11 16:49:57 +02:00
|
|
|
#[derive(Copy, Clone, TyEncodable, TyDecodable)]
|
2019-11-03 15:33:27 +01:00
|
|
|
enum AssocContainer {
|
2016-09-16 16:25:54 +02:00
|
|
|
TraitRequired,
|
|
|
|
TraitWithDefault,
|
|
|
|
ImplDefault,
|
2016-10-22 15:14:32 +02:00
|
|
|
ImplFinal,
|
2016-09-16 16:25:54 +02:00
|
|
|
}
|
|
|
|
|
2019-05-19 10:26:08 +02:00
|
|
|
impl AssocContainer {
|
2019-11-03 15:33:27 +01:00
|
|
|
fn with_def_id(&self, def_id: DefId) -> ty::AssocItemContainer {
|
2016-09-16 16:25:54 +02:00
|
|
|
match *self {
|
2019-12-22 23:42:04 +01:00
|
|
|
AssocContainer::TraitRequired | AssocContainer::TraitWithDefault => {
|
|
|
|
ty::TraitContainer(def_id)
|
|
|
|
}
|
2016-09-16 16:25:54 +02:00
|
|
|
|
2019-12-22 23:42:04 +01:00
|
|
|
AssocContainer::ImplDefault | AssocContainer::ImplFinal => ty::ImplContainer(def_id),
|
2016-09-16 16:25:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-03 15:33:27 +01:00
|
|
|
fn defaultness(&self) -> hir::Defaultness {
|
2016-09-16 16:25:54 +02:00
|
|
|
match *self {
|
2019-12-22 23:42:04 +01:00
|
|
|
AssocContainer::TraitRequired => hir::Defaultness::Default { has_value: false },
|
|
|
|
|
|
|
|
AssocContainer::TraitWithDefault | AssocContainer::ImplDefault => {
|
|
|
|
hir::Defaultness::Default { has_value: true }
|
|
|
|
}
|
2016-09-16 16:25:54 +02:00
|
|
|
|
2019-05-19 10:26:08 +02:00
|
|
|
AssocContainer::ImplFinal => hir::Defaultness::Final,
|
2016-09-16 16:25:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-11 16:49:57 +02:00
|
|
|
#[derive(MetadataEncodable, MetadataDecodable)]
|
2020-03-15 17:19:17 +01:00
|
|
|
struct AssocFnData {
|
2019-11-03 15:33:27 +01:00
|
|
|
fn_data: FnData,
|
|
|
|
container: AssocContainer,
|
|
|
|
has_self: bool,
|
2016-09-16 16:25:54 +02:00
|
|
|
}
|
|
|
|
|
2020-06-11 16:49:57 +02:00
|
|
|
#[derive(TyEncodable, TyDecodable)]
|
2019-11-03 15:33:27 +01:00
|
|
|
struct GeneratorData<'tcx> {
|
|
|
|
layout: mir::GeneratorLayout<'tcx>,
|
2016-12-26 14:34:03 +01:00
|
|
|
}
|
2018-01-04 11:26:47 +01:00
|
|
|
|
|
|
|
// Tags used for encoding Spans:
|
2020-02-07 20:02:24 +01:00
|
|
|
const TAG_VALID_SPAN_LOCAL: u8 = 0;
|
|
|
|
const TAG_VALID_SPAN_FOREIGN: u8 = 1;
|
|
|
|
const TAG_INVALID_SPAN: u8 = 2;
|