2016-09-16 17:25:54 +03:00
|
|
|
// Copyright 2012-2016 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
use astencode;
|
|
|
|
use index;
|
|
|
|
|
|
|
|
use rustc::hir;
|
2016-09-15 00:51:46 +03:00
|
|
|
use rustc::hir::def::{self, CtorKind};
|
2017-04-27 16:12:57 +02:00
|
|
|
use rustc::hir::def_id::{DefIndex, DefId, CrateNum};
|
2017-10-24 17:49:58 +02:00
|
|
|
use rustc::ich::StableHashingContext;
|
2018-02-27 19:28:21 +01:00
|
|
|
use rustc::middle::exported_symbols::{ExportedSymbol, SymbolExportLevel};
|
2018-02-10 14:28:17 -08:00
|
|
|
use rustc::middle::cstore::{DepKind, LinkagePreference, NativeLibrary, ForeignModule};
|
2016-09-16 17:25:54 +03:00
|
|
|
use rustc::middle::lang_items;
|
|
|
|
use rustc::mir;
|
2017-10-24 17:49:58 +02:00
|
|
|
use rustc::session::CrateDisambiguator;
|
2017-02-06 15:26:32 -05:00
|
|
|
use rustc::ty::{self, Ty, ReprOptions};
|
2016-09-27 21:26:08 -05:00
|
|
|
use rustc_back::PanicStrategy;
|
2016-09-16 17:25:54 +03:00
|
|
|
|
|
|
|
use rustc_serialize as serialize;
|
|
|
|
use syntax::{ast, attr};
|
2016-11-16 10:52:37 +00:00
|
|
|
use syntax::symbol::Symbol;
|
2016-09-16 17:25:54 +03:00
|
|
|
use syntax_pos::{self, Span};
|
|
|
|
|
|
|
|
use std::marker::PhantomData;
|
2017-04-05 23:39:02 +02:00
|
|
|
use std::mem;
|
2016-09-16 17:25:54 +03:00
|
|
|
|
2017-04-05 13:00:17 +02:00
|
|
|
use rustc_data_structures::stable_hasher::{StableHasher, HashStable,
|
|
|
|
StableHasherResult};
|
|
|
|
|
2016-09-30 16:24:50 -06:00
|
|
|
pub fn rustc_version() -> String {
|
2016-10-22 18:44:32 +05:30
|
|
|
format!("rustc {}",
|
|
|
|
option_env!("CFG_VERSION").unwrap_or("unknown version"))
|
2016-09-30 16:24:50 -06:00
|
|
|
}
|
2016-09-18 14:05:49 +03:00
|
|
|
|
2016-09-16 17:25:54 +03:00
|
|
|
/// Metadata encoding version.
|
|
|
|
/// NB: increment this if you change the format of metadata such that
|
2016-11-22 14:51:55 +02:00
|
|
|
/// the rustc version can't be found to compare with `rustc_version()`.
|
|
|
|
pub const METADATA_VERSION: u8 = 4;
|
2016-09-16 17:25:54 +03:00
|
|
|
|
|
|
|
/// Metadata header which includes `METADATA_VERSION`.
|
|
|
|
/// To get older versions of rustc to ignore this metadata,
|
|
|
|
/// there are 4 zero bytes at the start, which are treated
|
|
|
|
/// as a length of 0 by old compilers.
|
|
|
|
///
|
2016-11-22 14:51:55 +02: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.
|
2016-10-22 18:44:32 +05:30
|
|
|
pub const METADATA_HEADER: &'static [u8; 12] =
|
|
|
|
&[0, 0, 0, 0, b'r', b'u', b's', b't', 0, 0, 0, METADATA_VERSION];
|
2016-09-16 17:25:54 +03:00
|
|
|
|
|
|
|
/// A value of type T referred to by its absolute position
|
|
|
|
/// in the metadata, and which can be decoded lazily.
|
2016-09-17 10:33:47 +03: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.
|
2016-09-16 17:25:54 +03:00
|
|
|
#[must_use]
|
|
|
|
pub struct Lazy<T> {
|
|
|
|
pub position: usize,
|
2016-10-22 18:44:32 +05:30
|
|
|
_marker: PhantomData<T>,
|
2016-09-16 17:25:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<T> Lazy<T> {
|
|
|
|
pub fn with_position(position: usize) -> Lazy<T> {
|
|
|
|
Lazy {
|
2017-08-06 22:54:09 -07:00
|
|
|
position,
|
2016-10-22 18:44:32 +05:30
|
|
|
_marker: PhantomData,
|
2016-09-16 17:25:54 +03:00
|
|
|
}
|
|
|
|
}
|
2016-09-17 10:33:47 +03:00
|
|
|
|
|
|
|
/// Returns the minimum encoded size of a value of type `T`.
|
|
|
|
// FIXME(eddyb) Give better estimates for certain types.
|
|
|
|
pub fn min_size() -> usize {
|
|
|
|
1
|
|
|
|
}
|
2016-09-16 17:25:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<T> Copy for Lazy<T> {}
|
|
|
|
impl<T> Clone for Lazy<T> {
|
2016-10-22 18:44:32 +05:30
|
|
|
fn clone(&self) -> Self {
|
|
|
|
*self
|
|
|
|
}
|
2016-09-16 17:25:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<T> serialize::UseSpecializedEncodable for Lazy<T> {}
|
|
|
|
impl<T> serialize::UseSpecializedDecodable for Lazy<T> {}
|
|
|
|
|
2017-04-05 13:00:17 +02:00
|
|
|
impl<CTX, T> HashStable<CTX> for Lazy<T> {
|
|
|
|
fn hash_stable<W: StableHasherResult>(&self,
|
|
|
|
_: &mut CTX,
|
|
|
|
_: &mut StableHasher<W>) {
|
2017-04-05 23:39:02 +02:00
|
|
|
// There's nothing to do. Whatever got encoded within this Lazy<>
|
|
|
|
// wrapper has already been hashed.
|
2017-04-05 13:00:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-16 17:25:54 +03:00
|
|
|
/// A sequence of type T referred to by its absolute position
|
|
|
|
/// in the metadata and length, and which can be decoded lazily.
|
2016-09-17 10:33:47 +03:00
|
|
|
/// The sequence is a single node for the purposes of `Lazy`.
|
2016-09-16 17:25:54 +03: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 10:33:47 +03: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 17:25:54 +03:00
|
|
|
#[must_use]
|
|
|
|
pub struct LazySeq<T> {
|
|
|
|
pub len: usize,
|
|
|
|
pub position: usize,
|
2016-10-22 18:44:32 +05:30
|
|
|
_marker: PhantomData<T>,
|
2016-09-16 17:25:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<T> LazySeq<T> {
|
|
|
|
pub fn empty() -> LazySeq<T> {
|
|
|
|
LazySeq::with_position_and_length(0, 0)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn with_position_and_length(position: usize, len: usize) -> LazySeq<T> {
|
|
|
|
LazySeq {
|
2017-08-06 22:54:09 -07:00
|
|
|
len,
|
|
|
|
position,
|
2016-10-22 18:44:32 +05:30
|
|
|
_marker: PhantomData,
|
2016-09-16 17:25:54 +03:00
|
|
|
}
|
|
|
|
}
|
2016-09-17 10:33:47 +03:00
|
|
|
|
|
|
|
/// Returns the minimum encoded size of `length` values of type `T`.
|
|
|
|
pub fn min_size(length: usize) -> usize {
|
|
|
|
length
|
|
|
|
}
|
2016-09-16 17:25:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<T> Copy for LazySeq<T> {}
|
|
|
|
impl<T> Clone for LazySeq<T> {
|
2016-10-22 18:44:32 +05:30
|
|
|
fn clone(&self) -> Self {
|
|
|
|
*self
|
|
|
|
}
|
2016-09-16 17:25:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<T> serialize::UseSpecializedEncodable for LazySeq<T> {}
|
|
|
|
impl<T> serialize::UseSpecializedDecodable for LazySeq<T> {}
|
|
|
|
|
2017-04-05 13:00:17 +02:00
|
|
|
impl<CTX, T> HashStable<CTX> for LazySeq<T> {
|
|
|
|
fn hash_stable<W: StableHasherResult>(&self,
|
|
|
|
_: &mut CTX,
|
|
|
|
_: &mut StableHasher<W>) {
|
2017-04-05 23:39:02 +02:00
|
|
|
// There's nothing to do. Whatever got encoded within this Lazy<>
|
|
|
|
// wrapper has already been hashed.
|
2017-04-05 13:00:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-17 10:33:47 +03:00
|
|
|
/// Encoding / decoding state for `Lazy` and `LazySeq`.
|
|
|
|
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
|
|
|
pub enum LazyState {
|
|
|
|
/// Outside of a metadata node.
|
|
|
|
NoNode,
|
|
|
|
|
|
|
|
/// Inside a metadata node, and before any `Lazy` or `LazySeq`.
|
|
|
|
/// The position is that of the node itself.
|
|
|
|
NodeStart(usize),
|
|
|
|
|
|
|
|
/// Inside a metadata node, with a previous `Lazy` or `LazySeq`.
|
|
|
|
/// The position is a conservative estimate of where that
|
|
|
|
/// previous `Lazy` / `LazySeq` would end (see their comments).
|
2016-10-22 18:44:32 +05:30
|
|
|
Previous(usize),
|
2016-09-17 10:33:47 +03:00
|
|
|
}
|
|
|
|
|
2016-09-16 17:25:54 +03:00
|
|
|
#[derive(RustcEncodable, RustcDecodable)]
|
|
|
|
pub struct CrateRoot {
|
2016-11-16 10:52:37 +00:00
|
|
|
pub name: Symbol,
|
2016-09-16 17:25:54 +03:00
|
|
|
pub triple: String,
|
|
|
|
pub hash: hir::svh::Svh,
|
2017-10-24 17:49:58 +02:00
|
|
|
pub disambiguator: CrateDisambiguator,
|
2017-09-07 12:35:21 -07:00
|
|
|
pub panic_strategy: PanicStrategy,
|
|
|
|
pub has_global_allocator: bool,
|
|
|
|
pub has_default_lib_allocator: bool,
|
2016-09-16 17:25:54 +03:00
|
|
|
pub plugin_registrar_fn: Option<DefIndex>,
|
|
|
|
pub macro_derive_registrar: Option<DefIndex>,
|
|
|
|
|
2017-09-07 12:35:21 -07:00
|
|
|
pub crate_deps: LazySeq<CrateDep>,
|
|
|
|
pub dylib_dependency_formats: LazySeq<Option<LinkagePreference>>,
|
|
|
|
pub lang_items: LazySeq<(DefIndex, usize)>,
|
|
|
|
pub lang_items_missing: LazySeq<lang_items::LangItem>,
|
|
|
|
pub native_libraries: LazySeq<NativeLibrary>,
|
2018-02-10 14:28:17 -08:00
|
|
|
pub foreign_modules: LazySeq<ForeignModule>,
|
2016-09-17 10:33:47 +03:00
|
|
|
pub codemap: LazySeq<syntax_pos::FileMap>,
|
2016-12-16 12:51:36 -05:00
|
|
|
pub def_path_table: Lazy<hir::map::definitions::DefPathTable>,
|
2017-09-07 12:35:21 -07:00
|
|
|
pub impls: LazySeq<TraitImpls>,
|
2018-02-27 19:28:21 +01:00
|
|
|
pub exported_symbols: LazySeq<(ExportedSymbol, SymbolExportLevel)>,
|
2018-03-09 09:26:15 -08:00
|
|
|
pub wasm_custom_sections: LazySeq<DefIndex>,
|
2018-02-27 19:28:21 +01:00
|
|
|
|
2016-09-17 10:33:47 +03:00
|
|
|
pub index: LazySeq<index::Index>,
|
2016-09-16 17:25:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(RustcEncodable, RustcDecodable)]
|
|
|
|
pub struct CrateDep {
|
|
|
|
pub name: ast::Name,
|
|
|
|
pub hash: hir::svh::Svh,
|
2016-10-27 09:18:45 +00:00
|
|
|
pub kind: DepKind,
|
2016-09-16 17:25:54 +03:00
|
|
|
}
|
|
|
|
|
2017-04-27 16:12:57 +02:00
|
|
|
impl_stable_hash_for!(struct CrateDep {
|
|
|
|
name,
|
|
|
|
hash,
|
|
|
|
kind
|
|
|
|
});
|
|
|
|
|
2016-09-16 17:25:54 +03:00
|
|
|
#[derive(RustcEncodable, RustcDecodable)]
|
|
|
|
pub struct TraitImpls {
|
|
|
|
pub trait_id: (u32, DefIndex),
|
2016-10-22 18:44:32 +05:30
|
|
|
pub impls: LazySeq<DefIndex>,
|
2016-09-16 17:25:54 +03:00
|
|
|
}
|
|
|
|
|
2018-01-16 10:16:38 +01:00
|
|
|
impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for TraitImpls {
|
2017-04-27 16:12:57 +02:00
|
|
|
fn hash_stable<W: StableHasherResult>(&self,
|
2018-01-16 10:16:38 +01:00
|
|
|
hcx: &mut StableHashingContext<'a>,
|
2017-04-27 16:12:57 +02:00
|
|
|
hasher: &mut StableHasher<W>) {
|
|
|
|
let TraitImpls {
|
|
|
|
trait_id: (krate, def_index),
|
|
|
|
ref impls,
|
|
|
|
} = *self;
|
|
|
|
|
|
|
|
DefId {
|
|
|
|
krate: CrateNum::from_u32(krate),
|
|
|
|
index: def_index
|
|
|
|
}.hash_stable(hcx, hasher);
|
|
|
|
impls.hash_stable(hcx, hasher);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-16 17:25:54 +03:00
|
|
|
#[derive(RustcEncodable, RustcDecodable)]
|
|
|
|
pub struct Entry<'tcx> {
|
|
|
|
pub kind: EntryKind<'tcx>,
|
2016-12-20 08:32:15 +00:00
|
|
|
pub visibility: Lazy<ty::Visibility>,
|
2016-11-24 01:39:13 +02:00
|
|
|
pub span: Lazy<Span>,
|
2016-09-16 17:25:54 +03:00
|
|
|
pub attributes: LazySeq<ast::Attribute>,
|
|
|
|
pub children: LazySeq<DefIndex>,
|
|
|
|
pub stability: Option<Lazy<attr::Stability>>,
|
|
|
|
pub deprecation: Option<Lazy<attr::Deprecation>>,
|
|
|
|
|
|
|
|
pub ty: Option<Lazy<Ty<'tcx>>>,
|
|
|
|
pub inherent_impls: LazySeq<DefIndex>,
|
|
|
|
pub variances: LazySeq<ty::Variance>,
|
2017-01-25 22:01:11 +02:00
|
|
|
pub generics: Option<Lazy<ty::Generics>>,
|
2016-09-16 17:25:54 +03:00
|
|
|
pub predicates: Option<Lazy<ty::GenericPredicates<'tcx>>>,
|
|
|
|
|
|
|
|
pub ast: Option<Lazy<astencode::Ast<'tcx>>>,
|
2016-09-19 23:50:00 +03:00
|
|
|
pub mir: Option<Lazy<mir::Mir<'tcx>>>,
|
2016-09-16 17:25:54 +03:00
|
|
|
}
|
|
|
|
|
2017-04-05 23:39:02 +02:00
|
|
|
impl_stable_hash_for!(struct Entry<'tcx> {
|
|
|
|
kind,
|
|
|
|
visibility,
|
|
|
|
span,
|
|
|
|
attributes,
|
|
|
|
children,
|
|
|
|
stability,
|
|
|
|
deprecation,
|
|
|
|
ty,
|
|
|
|
inherent_impls,
|
|
|
|
variances,
|
|
|
|
generics,
|
|
|
|
predicates,
|
|
|
|
ast,
|
|
|
|
mir
|
|
|
|
});
|
|
|
|
|
2016-09-16 17:25:54 +03:00
|
|
|
#[derive(Copy, Clone, RustcEncodable, RustcDecodable)]
|
|
|
|
pub enum EntryKind<'tcx> {
|
2017-02-20 03:55:28 +02:00
|
|
|
Const(u8),
|
2016-09-16 17:25:54 +03:00
|
|
|
ImmStatic,
|
|
|
|
MutStatic,
|
|
|
|
ForeignImmStatic,
|
|
|
|
ForeignMutStatic,
|
|
|
|
ForeignMod,
|
2017-09-03 19:53:58 +01:00
|
|
|
ForeignType,
|
2017-03-15 21:27:40 -05:00
|
|
|
GlobalAsm,
|
2016-09-16 17:25:54 +03:00
|
|
|
Type,
|
2017-02-05 07:01:48 +02:00
|
|
|
Enum(ReprOptions),
|
2016-09-16 17:25:54 +03:00
|
|
|
Field,
|
2017-05-13 17:11:52 +03:00
|
|
|
Variant(Lazy<VariantData<'tcx>>),
|
|
|
|
Struct(Lazy<VariantData<'tcx>>, ReprOptions),
|
|
|
|
Union(Lazy<VariantData<'tcx>>, ReprOptions),
|
|
|
|
Fn(Lazy<FnData<'tcx>>),
|
|
|
|
ForeignFn(Lazy<FnData<'tcx>>),
|
2016-09-16 17:25:54 +03:00
|
|
|
Mod(Lazy<ModData>),
|
2016-10-28 06:52:45 +00:00
|
|
|
MacroDef(Lazy<MacroDef>),
|
2016-09-16 17:25:54 +03:00
|
|
|
Closure(Lazy<ClosureData<'tcx>>),
|
2016-12-26 14:34:03 +01:00
|
|
|
Generator(Lazy<GeneratorData<'tcx>>),
|
2016-09-16 17:25:54 +03:00
|
|
|
Trait(Lazy<TraitData<'tcx>>),
|
|
|
|
Impl(Lazy<ImplData<'tcx>>),
|
2017-05-13 17:11:52 +03:00
|
|
|
Method(Lazy<MethodData<'tcx>>),
|
2016-09-16 17:25:54 +03:00
|
|
|
AssociatedType(AssociatedContainer),
|
2017-02-20 03:55:28 +02:00
|
|
|
AssociatedConst(AssociatedContainer, u8),
|
2016-09-16 17:25:54 +03:00
|
|
|
}
|
|
|
|
|
2018-01-16 10:16:38 +01:00
|
|
|
impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for EntryKind<'gcx> {
|
2017-04-05 23:39:02 +02:00
|
|
|
fn hash_stable<W: StableHasherResult>(&self,
|
2018-01-16 10:16:38 +01:00
|
|
|
hcx: &mut StableHashingContext<'a>,
|
2017-04-05 23:39:02 +02:00
|
|
|
hasher: &mut StableHasher<W>) {
|
|
|
|
mem::discriminant(self).hash_stable(hcx, hasher);
|
|
|
|
match *self {
|
|
|
|
EntryKind::ImmStatic |
|
|
|
|
EntryKind::MutStatic |
|
|
|
|
EntryKind::ForeignImmStatic |
|
|
|
|
EntryKind::ForeignMutStatic |
|
|
|
|
EntryKind::ForeignMod |
|
2017-04-07 09:46:34 -05:00
|
|
|
EntryKind::GlobalAsm |
|
2017-09-03 19:53:58 +01:00
|
|
|
EntryKind::ForeignType |
|
2017-04-05 23:39:02 +02:00
|
|
|
EntryKind::Field |
|
|
|
|
EntryKind::Type => {
|
|
|
|
// Nothing else to hash here.
|
|
|
|
}
|
|
|
|
EntryKind::Const(qualif) => {
|
|
|
|
qualif.hash_stable(hcx, hasher);
|
|
|
|
}
|
|
|
|
EntryKind::Enum(ref repr_options) => {
|
|
|
|
repr_options.hash_stable(hcx, hasher);
|
|
|
|
}
|
|
|
|
EntryKind::Variant(ref variant_data) => {
|
|
|
|
variant_data.hash_stable(hcx, hasher);
|
|
|
|
}
|
|
|
|
EntryKind::Struct(ref variant_data, ref repr_options) |
|
|
|
|
EntryKind::Union(ref variant_data, ref repr_options) => {
|
|
|
|
variant_data.hash_stable(hcx, hasher);
|
|
|
|
repr_options.hash_stable(hcx, hasher);
|
|
|
|
}
|
|
|
|
EntryKind::Fn(ref fn_data) |
|
|
|
|
EntryKind::ForeignFn(ref fn_data) => {
|
|
|
|
fn_data.hash_stable(hcx, hasher);
|
|
|
|
}
|
|
|
|
EntryKind::Mod(ref mod_data) => {
|
|
|
|
mod_data.hash_stable(hcx, hasher);
|
|
|
|
}
|
|
|
|
EntryKind::MacroDef(ref macro_def) => {
|
|
|
|
macro_def.hash_stable(hcx, hasher);
|
|
|
|
}
|
2016-12-26 14:34:03 +01:00
|
|
|
EntryKind::Generator(data) => {
|
|
|
|
data.hash_stable(hcx, hasher);
|
|
|
|
}
|
2017-04-05 23:39:02 +02:00
|
|
|
EntryKind::Closure(closure_data) => {
|
|
|
|
closure_data.hash_stable(hcx, hasher);
|
|
|
|
}
|
|
|
|
EntryKind::Trait(ref trait_data) => {
|
|
|
|
trait_data.hash_stable(hcx, hasher);
|
|
|
|
}
|
|
|
|
EntryKind::Impl(ref impl_data) => {
|
|
|
|
impl_data.hash_stable(hcx, hasher);
|
|
|
|
}
|
|
|
|
EntryKind::Method(ref method_data) => {
|
|
|
|
method_data.hash_stable(hcx, hasher);
|
|
|
|
}
|
|
|
|
EntryKind::AssociatedType(associated_container) => {
|
|
|
|
associated_container.hash_stable(hcx, hasher);
|
|
|
|
}
|
|
|
|
EntryKind::AssociatedConst(associated_container, qualif) => {
|
|
|
|
associated_container.hash_stable(hcx, hasher);
|
|
|
|
qualif.hash_stable(hcx, hasher);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-16 17:25:54 +03:00
|
|
|
#[derive(RustcEncodable, RustcDecodable)]
|
|
|
|
pub struct ModData {
|
2016-10-22 18:44:32 +05:30
|
|
|
pub reexports: LazySeq<def::Export>,
|
2016-09-16 17:25:54 +03:00
|
|
|
}
|
|
|
|
|
2017-04-05 13:00:17 +02:00
|
|
|
impl_stable_hash_for!(struct ModData { reexports });
|
|
|
|
|
2016-11-24 01:39:13 +02:00
|
|
|
#[derive(RustcEncodable, RustcDecodable)]
|
|
|
|
pub struct MacroDef {
|
|
|
|
pub body: String,
|
2017-03-22 08:39:51 +00:00
|
|
|
pub legacy: bool,
|
2016-11-24 01:39:13 +02:00
|
|
|
}
|
|
|
|
|
2017-03-22 08:39:51 +00:00
|
|
|
impl_stable_hash_for!(struct MacroDef { body, legacy });
|
2017-04-05 13:00:17 +02:00
|
|
|
|
2016-09-16 17:25:54 +03:00
|
|
|
#[derive(RustcEncodable, RustcDecodable)]
|
2017-05-13 17:11:52 +03:00
|
|
|
pub struct FnData<'tcx> {
|
2016-09-16 17:25:54 +03:00
|
|
|
pub constness: hir::Constness,
|
2016-10-22 18:44:32 +05:30
|
|
|
pub arg_names: LazySeq<ast::Name>,
|
2017-05-13 17:11:52 +03:00
|
|
|
pub sig: Lazy<ty::PolyFnSig<'tcx>>,
|
2016-09-16 17:25:54 +03:00
|
|
|
}
|
|
|
|
|
2017-05-13 17:11:52 +03:00
|
|
|
impl_stable_hash_for!(struct FnData<'tcx> { constness, arg_names, sig });
|
2017-04-05 13:00:17 +02:00
|
|
|
|
2016-09-16 17:25:54 +03:00
|
|
|
#[derive(RustcEncodable, RustcDecodable)]
|
2017-05-13 17:11:52 +03:00
|
|
|
pub struct VariantData<'tcx> {
|
2016-09-15 00:51:46 +03:00
|
|
|
pub ctor_kind: CtorKind,
|
2017-02-05 07:01:48 +02:00
|
|
|
pub discr: ty::VariantDiscr,
|
2016-09-16 17:25:54 +03:00
|
|
|
|
|
|
|
/// If this is a struct's only variant, this
|
|
|
|
/// is the index of the "struct ctor" item.
|
2016-10-22 18:44:32 +05:30
|
|
|
pub struct_ctor: Option<DefIndex>,
|
2017-05-13 17:11:52 +03:00
|
|
|
|
|
|
|
/// If this is a tuple struct or variant
|
|
|
|
/// ctor, this is its "function" signature.
|
|
|
|
pub ctor_sig: Option<Lazy<ty::PolyFnSig<'tcx>>>,
|
2016-09-16 17:25:54 +03:00
|
|
|
}
|
|
|
|
|
2017-05-13 17:11:52 +03:00
|
|
|
impl_stable_hash_for!(struct VariantData<'tcx> {
|
2017-04-05 13:00:17 +02:00
|
|
|
ctor_kind,
|
|
|
|
discr,
|
2017-05-13 17:11:52 +03:00
|
|
|
struct_ctor,
|
|
|
|
ctor_sig
|
2017-04-05 13:00:17 +02:00
|
|
|
});
|
|
|
|
|
2016-09-16 17:25:54 +03:00
|
|
|
#[derive(RustcEncodable, RustcDecodable)]
|
|
|
|
pub struct TraitData<'tcx> {
|
|
|
|
pub unsafety: hir::Unsafety,
|
|
|
|
pub paren_sugar: bool,
|
2017-10-09 13:59:20 -03:00
|
|
|
pub has_auto_impl: bool,
|
2016-10-22 18:44:32 +05:30
|
|
|
pub super_predicates: Lazy<ty::GenericPredicates<'tcx>>,
|
2016-09-16 17:25:54 +03:00
|
|
|
}
|
|
|
|
|
2017-04-05 13:00:17 +02:00
|
|
|
impl_stable_hash_for!(struct TraitData<'tcx> {
|
|
|
|
unsafety,
|
|
|
|
paren_sugar,
|
2017-10-09 13:59:20 -03:00
|
|
|
has_auto_impl,
|
2017-04-05 13:00:17 +02:00
|
|
|
super_predicates
|
|
|
|
});
|
|
|
|
|
2016-09-16 17:25:54 +03:00
|
|
|
#[derive(RustcEncodable, RustcDecodable)]
|
|
|
|
pub struct ImplData<'tcx> {
|
|
|
|
pub polarity: hir::ImplPolarity,
|
2016-11-18 17:14:42 +01:00
|
|
|
pub defaultness: hir::Defaultness,
|
2016-09-16 17:25:54 +03:00
|
|
|
pub parent_impl: Option<DefId>,
|
2017-03-17 16:17:45 -04:00
|
|
|
|
|
|
|
/// This is `Some` only for impls of `CoerceUnsized`.
|
|
|
|
pub coerce_unsized_info: Option<ty::adjustment::CoerceUnsizedInfo>,
|
2016-10-22 18:44:32 +05:30
|
|
|
pub trait_ref: Option<Lazy<ty::TraitRef<'tcx>>>,
|
2016-09-16 17:25:54 +03:00
|
|
|
}
|
|
|
|
|
2017-04-05 13:00:17 +02:00
|
|
|
impl_stable_hash_for!(struct ImplData<'tcx> {
|
|
|
|
polarity,
|
2017-04-24 09:56:54 +00:00
|
|
|
defaultness,
|
2017-04-05 13:00:17 +02:00
|
|
|
parent_impl,
|
|
|
|
coerce_unsized_info,
|
|
|
|
trait_ref
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2016-09-16 17:25:54 +03: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".
|
|
|
|
#[derive(Copy, Clone, RustcEncodable, RustcDecodable)]
|
|
|
|
pub enum AssociatedContainer {
|
|
|
|
TraitRequired,
|
|
|
|
TraitWithDefault,
|
|
|
|
ImplDefault,
|
2016-10-22 18:44:32 +05:30
|
|
|
ImplFinal,
|
2016-09-16 17:25:54 +03:00
|
|
|
}
|
|
|
|
|
2017-04-05 13:00:17 +02:00
|
|
|
impl_stable_hash_for!(enum ::schema::AssociatedContainer {
|
|
|
|
TraitRequired,
|
|
|
|
TraitWithDefault,
|
|
|
|
ImplDefault,
|
|
|
|
ImplFinal
|
|
|
|
});
|
|
|
|
|
2016-09-16 17:25:54 +03:00
|
|
|
impl AssociatedContainer {
|
2016-11-10 02:06:34 +02:00
|
|
|
pub fn with_def_id(&self, def_id: DefId) -> ty::AssociatedItemContainer {
|
2016-09-16 17:25:54 +03:00
|
|
|
match *self {
|
|
|
|
AssociatedContainer::TraitRequired |
|
2016-10-22 18:44:32 +05:30
|
|
|
AssociatedContainer::TraitWithDefault => ty::TraitContainer(def_id),
|
2016-09-16 17:25:54 +03:00
|
|
|
|
|
|
|
AssociatedContainer::ImplDefault |
|
2016-10-22 18:44:32 +05:30
|
|
|
AssociatedContainer::ImplFinal => ty::ImplContainer(def_id),
|
2016-09-16 17:25:54 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn defaultness(&self) -> hir::Defaultness {
|
|
|
|
match *self {
|
2016-11-14 11:00:02 -05:00
|
|
|
AssociatedContainer::TraitRequired => hir::Defaultness::Default {
|
|
|
|
has_value: false,
|
|
|
|
},
|
|
|
|
|
2016-09-16 17:25:54 +03:00
|
|
|
AssociatedContainer::TraitWithDefault |
|
2016-11-14 11:00:02 -05:00
|
|
|
AssociatedContainer::ImplDefault => hir::Defaultness::Default {
|
|
|
|
has_value: true,
|
|
|
|
},
|
2016-09-16 17:25:54 +03:00
|
|
|
|
2016-10-22 18:44:32 +05:30
|
|
|
AssociatedContainer::ImplFinal => hir::Defaultness::Final,
|
2016-09-16 17:25:54 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(RustcEncodable, RustcDecodable)]
|
2017-05-13 17:11:52 +03:00
|
|
|
pub struct MethodData<'tcx> {
|
|
|
|
pub fn_data: FnData<'tcx>,
|
2016-09-16 17:25:54 +03:00
|
|
|
pub container: AssociatedContainer,
|
2016-11-10 02:06:34 +02:00
|
|
|
pub has_self: bool,
|
2016-09-16 17:25:54 +03:00
|
|
|
}
|
2017-05-13 17:11:52 +03:00
|
|
|
impl_stable_hash_for!(struct MethodData<'tcx> { fn_data, container, has_self });
|
2016-09-16 17:25:54 +03:00
|
|
|
|
|
|
|
#[derive(RustcEncodable, RustcDecodable)]
|
|
|
|
pub struct ClosureData<'tcx> {
|
2017-05-13 13:12:29 +03:00
|
|
|
pub sig: Lazy<ty::PolyFnSig<'tcx>>,
|
2016-09-16 17:25:54 +03:00
|
|
|
}
|
2017-11-08 12:30:13 -05:00
|
|
|
impl_stable_hash_for!(struct ClosureData<'tcx> { sig });
|
2016-12-26 14:34:03 +01:00
|
|
|
|
|
|
|
#[derive(RustcEncodable, RustcDecodable)]
|
|
|
|
pub struct GeneratorData<'tcx> {
|
|
|
|
pub layout: mir::GeneratorLayout<'tcx>,
|
|
|
|
}
|
2017-11-09 15:44:29 -05:00
|
|
|
impl_stable_hash_for!(struct GeneratorData<'tcx> { layout });
|
2018-01-04 11:26:47 +01:00
|
|
|
|
|
|
|
// Tags used for encoding Spans:
|
|
|
|
pub const TAG_VALID_SPAN: u8 = 0;
|
|
|
|
pub const TAG_INVALID_SPAN: u8 = 1;
|