]>
Commit | Line | Data |
---|---|---|
9e0c209e SL |
1 | // Copyright 2012-2016 The Rust Project Developers. See the COPYRIGHT |
2 | // file at the top-level directory of this distribution and at | |
3 | // http://rust-lang.org/COPYRIGHT. | |
4 | // | |
5 | // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | |
6 | // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | |
7 | // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | |
8 | // option. This file may not be copied, modified, or distributed | |
9 | // except according to those terms. | |
10 | ||
9e0c209e SL |
11 | use index; |
12 | ||
13 | use rustc::hir; | |
c30ab7b3 | 14 | use rustc::hir::def::{self, CtorKind}; |
7cac9316 | 15 | use rustc::hir::def_id::{DefIndex, DefId, CrateNum}; |
cc61c64b | 16 | use rustc::ich::StableHashingContext; |
0531ce1d | 17 | use rustc::middle::cstore::{DepKind, LinkagePreference, NativeLibrary, ForeignModule}; |
9e0c209e SL |
18 | use rustc::middle::lang_items; |
19 | use rustc::mir; | |
abe05a73 | 20 | use rustc::session::CrateDisambiguator; |
8bb4bdeb | 21 | use rustc::ty::{self, Ty, ReprOptions}; |
83c7162d | 22 | use rustc_target::spec::{PanicStrategy, TargetTriple}; |
b7449926 | 23 | use rustc_data_structures::svh::Svh; |
9e0c209e SL |
24 | |
25 | use rustc_serialize as serialize; | |
26 | use syntax::{ast, attr}; | |
94b46f34 | 27 | use syntax::edition::Edition; |
476ff2be | 28 | use syntax::symbol::Symbol; |
9e0c209e SL |
29 | use syntax_pos::{self, Span}; |
30 | ||
31 | use std::marker::PhantomData; | |
cc61c64b XL |
32 | use std::mem; |
33 | ||
34 | use rustc_data_structures::stable_hasher::{StableHasher, HashStable, | |
35 | StableHasherResult}; | |
9e0c209e | 36 | |
c30ab7b3 SL |
37 | pub fn rustc_version() -> String { |
38 | format!("rustc {}", | |
39 | option_env!("CFG_VERSION").unwrap_or("unknown version")) | |
40 | } | |
9e0c209e SL |
41 | |
42 | /// Metadata encoding version. | |
43 | /// NB: increment this if you change the format of metadata such that | |
476ff2be SL |
44 | /// the rustc version can't be found to compare with `rustc_version()`. |
45 | pub const METADATA_VERSION: u8 = 4; | |
9e0c209e SL |
46 | |
47 | /// Metadata header which includes `METADATA_VERSION`. | |
48 | /// To get older versions of rustc to ignore this metadata, | |
49 | /// there are 4 zero bytes at the start, which are treated | |
50 | /// as a length of 0 by old compilers. | |
51 | /// | |
476ff2be SL |
52 | /// This header is followed by the position of the `CrateRoot`, |
53 | /// which is encoded as a 32-bit big-endian unsigned integer, | |
54 | /// and further followed by the rustc version string. | |
c30ab7b3 SL |
55 | pub const METADATA_HEADER: &'static [u8; 12] = |
56 | &[0, 0, 0, 0, b'r', b'u', b's', b't', 0, 0, 0, METADATA_VERSION]; | |
9e0c209e | 57 | |
9e0c209e SL |
58 | /// A value of type T referred to by its absolute position |
59 | /// in the metadata, and which can be decoded lazily. | |
60 | /// | |
61 | /// Metadata is effective a tree, encoded in post-order, | |
62 | /// and with the root's position written next to the header. | |
63 | /// That means every single `Lazy` points to some previous | |
64 | /// location in the metadata and is part of a larger node. | |
65 | /// | |
66 | /// The first `Lazy` in a node is encoded as the backwards | |
67 | /// distance from the position where the containing node | |
68 | /// starts and where the `Lazy` points to, while the rest | |
69 | /// use the forward distance from the previous `Lazy`. | |
70 | /// Distances start at 1, as 0-byte nodes are invalid. | |
71 | /// Also invalid are nodes being referred in a different | |
72 | /// order than they were encoded in. | |
73 | #[must_use] | |
74 | pub struct Lazy<T> { | |
75 | pub position: usize, | |
c30ab7b3 | 76 | _marker: PhantomData<T>, |
9e0c209e SL |
77 | } |
78 | ||
79 | impl<T> Lazy<T> { | |
80 | pub fn with_position(position: usize) -> Lazy<T> { | |
81 | Lazy { | |
3b2f2976 | 82 | position, |
c30ab7b3 | 83 | _marker: PhantomData, |
9e0c209e SL |
84 | } |
85 | } | |
86 | ||
87 | /// Returns the minimum encoded size of a value of type `T`. | |
88 | // FIXME(eddyb) Give better estimates for certain types. | |
89 | pub fn min_size() -> usize { | |
90 | 1 | |
91 | } | |
92 | } | |
93 | ||
94 | impl<T> Copy for Lazy<T> {} | |
95 | impl<T> Clone for Lazy<T> { | |
c30ab7b3 SL |
96 | fn clone(&self) -> Self { |
97 | *self | |
98 | } | |
9e0c209e SL |
99 | } |
100 | ||
101 | impl<T> serialize::UseSpecializedEncodable for Lazy<T> {} | |
102 | impl<T> serialize::UseSpecializedDecodable for Lazy<T> {} | |
103 | ||
cc61c64b XL |
104 | impl<CTX, T> HashStable<CTX> for Lazy<T> { |
105 | fn hash_stable<W: StableHasherResult>(&self, | |
106 | _: &mut CTX, | |
107 | _: &mut StableHasher<W>) { | |
108 | // There's nothing to do. Whatever got encoded within this Lazy<> | |
109 | // wrapper has already been hashed. | |
110 | } | |
111 | } | |
112 | ||
9e0c209e SL |
113 | /// A sequence of type T referred to by its absolute position |
114 | /// in the metadata and length, and which can be decoded lazily. | |
115 | /// The sequence is a single node for the purposes of `Lazy`. | |
116 | /// | |
117 | /// Unlike `Lazy<Vec<T>>`, the length is encoded next to the | |
118 | /// position, not at the position, which means that the length | |
119 | /// doesn't need to be known before encoding all the elements. | |
120 | /// | |
121 | /// If the length is 0, no position is encoded, but otherwise, | |
122 | /// the encoding is that of `Lazy`, with the distinction that | |
123 | /// the minimal distance the length of the sequence, i.e. | |
124 | /// it's assumed there's no 0-byte element in the sequence. | |
125 | #[must_use] | |
126 | pub struct LazySeq<T> { | |
127 | pub len: usize, | |
128 | pub position: usize, | |
c30ab7b3 | 129 | _marker: PhantomData<T>, |
9e0c209e SL |
130 | } |
131 | ||
132 | impl<T> LazySeq<T> { | |
133 | pub fn empty() -> LazySeq<T> { | |
134 | LazySeq::with_position_and_length(0, 0) | |
135 | } | |
136 | ||
137 | pub fn with_position_and_length(position: usize, len: usize) -> LazySeq<T> { | |
138 | LazySeq { | |
3b2f2976 XL |
139 | len, |
140 | position, | |
c30ab7b3 | 141 | _marker: PhantomData, |
9e0c209e SL |
142 | } |
143 | } | |
144 | ||
145 | /// Returns the minimum encoded size of `length` values of type `T`. | |
146 | pub fn min_size(length: usize) -> usize { | |
147 | length | |
148 | } | |
149 | } | |
150 | ||
151 | impl<T> Copy for LazySeq<T> {} | |
152 | impl<T> Clone for LazySeq<T> { | |
c30ab7b3 SL |
153 | fn clone(&self) -> Self { |
154 | *self | |
155 | } | |
9e0c209e SL |
156 | } |
157 | ||
158 | impl<T> serialize::UseSpecializedEncodable for LazySeq<T> {} | |
159 | impl<T> serialize::UseSpecializedDecodable for LazySeq<T> {} | |
160 | ||
cc61c64b XL |
161 | impl<CTX, T> HashStable<CTX> for LazySeq<T> { |
162 | fn hash_stable<W: StableHasherResult>(&self, | |
163 | _: &mut CTX, | |
164 | _: &mut StableHasher<W>) { | |
165 | // There's nothing to do. Whatever got encoded within this Lazy<> | |
166 | // wrapper has already been hashed. | |
167 | } | |
168 | } | |
169 | ||
9e0c209e SL |
170 | /// Encoding / decoding state for `Lazy` and `LazySeq`. |
171 | #[derive(Copy, Clone, PartialEq, Eq, Debug)] | |
172 | pub enum LazyState { | |
173 | /// Outside of a metadata node. | |
174 | NoNode, | |
175 | ||
176 | /// Inside a metadata node, and before any `Lazy` or `LazySeq`. | |
177 | /// The position is that of the node itself. | |
178 | NodeStart(usize), | |
179 | ||
180 | /// Inside a metadata node, with a previous `Lazy` or `LazySeq`. | |
181 | /// The position is a conservative estimate of where that | |
182 | /// previous `Lazy` / `LazySeq` would end (see their comments). | |
c30ab7b3 | 183 | Previous(usize), |
9e0c209e SL |
184 | } |
185 | ||
186 | #[derive(RustcEncodable, RustcDecodable)] | |
187 | pub struct CrateRoot { | |
476ff2be | 188 | pub name: Symbol, |
0531ce1d | 189 | pub triple: TargetTriple, |
83c7162d | 190 | pub extra_filename: String, |
b7449926 | 191 | pub hash: Svh, |
abe05a73 | 192 | pub disambiguator: CrateDisambiguator, |
ea8adc8c | 193 | pub panic_strategy: PanicStrategy, |
94b46f34 | 194 | pub edition: Edition, |
ea8adc8c | 195 | pub has_global_allocator: bool, |
b7449926 | 196 | pub has_panic_handler: bool, |
ea8adc8c | 197 | pub has_default_lib_allocator: bool, |
9e0c209e | 198 | pub plugin_registrar_fn: Option<DefIndex>, |
a1dfa0c6 | 199 | pub proc_macro_decls_static: Option<DefIndex>, |
9e0c209e | 200 | |
ea8adc8c XL |
201 | pub crate_deps: LazySeq<CrateDep>, |
202 | pub dylib_dependency_formats: LazySeq<Option<LinkagePreference>>, | |
b7449926 | 203 | pub lib_features: LazySeq<(Symbol, Option<Symbol>)>, |
ea8adc8c XL |
204 | pub lang_items: LazySeq<(DefIndex, usize)>, |
205 | pub lang_items_missing: LazySeq<lang_items::LangItem>, | |
206 | pub native_libraries: LazySeq<NativeLibrary>, | |
0531ce1d | 207 | pub foreign_modules: LazySeq<ForeignModule>, |
b7449926 | 208 | pub source_map: LazySeq<syntax_pos::SourceFile>, |
32a655c1 | 209 | pub def_path_table: Lazy<hir::map::definitions::DefPathTable>, |
ea8adc8c | 210 | pub impls: LazySeq<TraitImpls>, |
83c7162d | 211 | pub exported_symbols: EncodedExportedSymbols, |
0531ce1d XL |
212 | pub interpret_alloc_index: LazySeq<u32>, |
213 | ||
9e0c209e | 214 | pub index: LazySeq<index::Index>, |
94b46f34 XL |
215 | |
216 | pub compiler_builtins: bool, | |
217 | pub needs_allocator: bool, | |
218 | pub needs_panic_runtime: bool, | |
219 | pub no_builtins: bool, | |
220 | pub panic_runtime: bool, | |
221 | pub profiler_runtime: bool, | |
222 | pub sanitizer_runtime: bool, | |
9e0c209e SL |
223 | } |
224 | ||
225 | #[derive(RustcEncodable, RustcDecodable)] | |
226 | pub struct CrateDep { | |
227 | pub name: ast::Name, | |
b7449926 | 228 | pub hash: Svh, |
476ff2be | 229 | pub kind: DepKind, |
83c7162d | 230 | pub extra_filename: String, |
9e0c209e SL |
231 | } |
232 | ||
7cac9316 XL |
233 | impl_stable_hash_for!(struct CrateDep { |
234 | name, | |
235 | hash, | |
83c7162d XL |
236 | kind, |
237 | extra_filename | |
7cac9316 XL |
238 | }); |
239 | ||
9e0c209e SL |
240 | #[derive(RustcEncodable, RustcDecodable)] |
241 | pub struct TraitImpls { | |
242 | pub trait_id: (u32, DefIndex), | |
c30ab7b3 | 243 | pub impls: LazySeq<DefIndex>, |
9e0c209e SL |
244 | } |
245 | ||
0531ce1d | 246 | impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for TraitImpls { |
7cac9316 | 247 | fn hash_stable<W: StableHasherResult>(&self, |
0531ce1d | 248 | hcx: &mut StableHashingContext<'a>, |
7cac9316 XL |
249 | hasher: &mut StableHasher<W>) { |
250 | let TraitImpls { | |
251 | trait_id: (krate, def_index), | |
252 | ref impls, | |
253 | } = *self; | |
254 | ||
255 | DefId { | |
256 | krate: CrateNum::from_u32(krate), | |
257 | index: def_index | |
258 | }.hash_stable(hcx, hasher); | |
259 | impls.hash_stable(hcx, hasher); | |
260 | } | |
261 | } | |
262 | ||
9e0c209e SL |
263 | #[derive(RustcEncodable, RustcDecodable)] |
264 | pub struct Entry<'tcx> { | |
265 | pub kind: EntryKind<'tcx>, | |
32a655c1 | 266 | pub visibility: Lazy<ty::Visibility>, |
476ff2be | 267 | pub span: Lazy<Span>, |
9e0c209e SL |
268 | pub attributes: LazySeq<ast::Attribute>, |
269 | pub children: LazySeq<DefIndex>, | |
270 | pub stability: Option<Lazy<attr::Stability>>, | |
271 | pub deprecation: Option<Lazy<attr::Deprecation>>, | |
272 | ||
273 | pub ty: Option<Lazy<Ty<'tcx>>>, | |
274 | pub inherent_impls: LazySeq<DefIndex>, | |
275 | pub variances: LazySeq<ty::Variance>, | |
8bb4bdeb | 276 | pub generics: Option<Lazy<ty::Generics>>, |
9e0c209e | 277 | pub predicates: Option<Lazy<ty::GenericPredicates<'tcx>>>, |
8faf50e0 | 278 | pub predicates_defined_on: Option<Lazy<ty::GenericPredicates<'tcx>>>, |
9e0c209e | 279 | |
c30ab7b3 | 280 | pub mir: Option<Lazy<mir::Mir<'tcx>>>, |
9e0c209e SL |
281 | } |
282 | ||
cc61c64b XL |
283 | impl_stable_hash_for!(struct Entry<'tcx> { |
284 | kind, | |
285 | visibility, | |
286 | span, | |
287 | attributes, | |
288 | children, | |
289 | stability, | |
290 | deprecation, | |
291 | ty, | |
292 | inherent_impls, | |
293 | variances, | |
294 | generics, | |
295 | predicates, | |
8faf50e0 | 296 | predicates_defined_on, |
cc61c64b XL |
297 | mir |
298 | }); | |
299 | ||
9e0c209e SL |
300 | #[derive(Copy, Clone, RustcEncodable, RustcDecodable)] |
301 | pub enum EntryKind<'tcx> { | |
83c7162d | 302 | Const(ConstQualif, Lazy<RenderedConst>), |
9e0c209e SL |
303 | ImmStatic, |
304 | MutStatic, | |
305 | ForeignImmStatic, | |
306 | ForeignMutStatic, | |
307 | ForeignMod, | |
abe05a73 | 308 | ForeignType, |
cc61c64b | 309 | GlobalAsm, |
9e0c209e | 310 | Type, |
94b46f34 | 311 | Existential, |
8bb4bdeb | 312 | Enum(ReprOptions), |
9e0c209e | 313 | Field, |
041b39d2 XL |
314 | Variant(Lazy<VariantData<'tcx>>), |
315 | Struct(Lazy<VariantData<'tcx>>, ReprOptions), | |
316 | Union(Lazy<VariantData<'tcx>>, ReprOptions), | |
317 | Fn(Lazy<FnData<'tcx>>), | |
318 | ForeignFn(Lazy<FnData<'tcx>>), | |
9e0c209e | 319 | Mod(Lazy<ModData>), |
476ff2be | 320 | MacroDef(Lazy<MacroDef>), |
9e0c209e | 321 | Closure(Lazy<ClosureData<'tcx>>), |
ea8adc8c | 322 | Generator(Lazy<GeneratorData<'tcx>>), |
9e0c209e SL |
323 | Trait(Lazy<TraitData<'tcx>>), |
324 | Impl(Lazy<ImplData<'tcx>>), | |
041b39d2 | 325 | Method(Lazy<MethodData<'tcx>>), |
9e0c209e | 326 | AssociatedType(AssociatedContainer), |
8faf50e0 | 327 | AssociatedExistential(AssociatedContainer), |
83c7162d | 328 | AssociatedConst(AssociatedContainer, ConstQualif, Lazy<RenderedConst>), |
32a655c1 SL |
329 | } |
330 | ||
0531ce1d | 331 | impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for EntryKind<'gcx> { |
cc61c64b | 332 | fn hash_stable<W: StableHasherResult>(&self, |
0531ce1d | 333 | hcx: &mut StableHashingContext<'a>, |
cc61c64b XL |
334 | hasher: &mut StableHasher<W>) { |
335 | mem::discriminant(self).hash_stable(hcx, hasher); | |
336 | match *self { | |
337 | EntryKind::ImmStatic | | |
338 | EntryKind::MutStatic | | |
339 | EntryKind::ForeignImmStatic | | |
340 | EntryKind::ForeignMutStatic | | |
341 | EntryKind::ForeignMod | | |
342 | EntryKind::GlobalAsm | | |
abe05a73 | 343 | EntryKind::ForeignType | |
cc61c64b | 344 | EntryKind::Field | |
94b46f34 | 345 | EntryKind::Existential | |
cc61c64b XL |
346 | EntryKind::Type => { |
347 | // Nothing else to hash here. | |
348 | } | |
83c7162d | 349 | EntryKind::Const(qualif, ref const_data) => { |
cc61c64b | 350 | qualif.hash_stable(hcx, hasher); |
83c7162d | 351 | const_data.hash_stable(hcx, hasher); |
cc61c64b XL |
352 | } |
353 | EntryKind::Enum(ref repr_options) => { | |
354 | repr_options.hash_stable(hcx, hasher); | |
355 | } | |
356 | EntryKind::Variant(ref variant_data) => { | |
357 | variant_data.hash_stable(hcx, hasher); | |
358 | } | |
359 | EntryKind::Struct(ref variant_data, ref repr_options) | | |
360 | EntryKind::Union(ref variant_data, ref repr_options) => { | |
361 | variant_data.hash_stable(hcx, hasher); | |
362 | repr_options.hash_stable(hcx, hasher); | |
363 | } | |
364 | EntryKind::Fn(ref fn_data) | | |
365 | EntryKind::ForeignFn(ref fn_data) => { | |
366 | fn_data.hash_stable(hcx, hasher); | |
367 | } | |
368 | EntryKind::Mod(ref mod_data) => { | |
369 | mod_data.hash_stable(hcx, hasher); | |
370 | } | |
371 | EntryKind::MacroDef(ref macro_def) => { | |
372 | macro_def.hash_stable(hcx, hasher); | |
373 | } | |
ea8adc8c XL |
374 | EntryKind::Generator(data) => { |
375 | data.hash_stable(hcx, hasher); | |
376 | } | |
cc61c64b XL |
377 | EntryKind::Closure(closure_data) => { |
378 | closure_data.hash_stable(hcx, hasher); | |
379 | } | |
380 | EntryKind::Trait(ref trait_data) => { | |
381 | trait_data.hash_stable(hcx, hasher); | |
382 | } | |
cc61c64b XL |
383 | EntryKind::Impl(ref impl_data) => { |
384 | impl_data.hash_stable(hcx, hasher); | |
385 | } | |
386 | EntryKind::Method(ref method_data) => { | |
387 | method_data.hash_stable(hcx, hasher); | |
388 | } | |
8faf50e0 | 389 | EntryKind::AssociatedExistential(associated_container) | |
cc61c64b XL |
390 | EntryKind::AssociatedType(associated_container) => { |
391 | associated_container.hash_stable(hcx, hasher); | |
392 | } | |
83c7162d | 393 | EntryKind::AssociatedConst(associated_container, qualif, ref const_data) => { |
cc61c64b XL |
394 | associated_container.hash_stable(hcx, hasher); |
395 | qualif.hash_stable(hcx, hasher); | |
83c7162d | 396 | const_data.hash_stable(hcx, hasher); |
cc61c64b XL |
397 | } |
398 | } | |
399 | } | |
400 | } | |
401 | ||
83c7162d XL |
402 | /// Additional data for EntryKind::Const and EntryKind::AssociatedConst |
403 | #[derive(Clone, Copy, RustcEncodable, RustcDecodable)] | |
404 | pub struct ConstQualif { | |
405 | pub mir: u8, | |
406 | pub ast_promotable: bool, | |
407 | } | |
408 | ||
409 | impl_stable_hash_for!(struct ConstQualif { mir, ast_promotable }); | |
410 | ||
411 | /// Contains a constant which has been rendered to a String. | |
412 | /// Used by rustdoc. | |
413 | #[derive(RustcEncodable, RustcDecodable)] | |
414 | pub struct RenderedConst(pub String); | |
415 | ||
416 | impl<'a> HashStable<StableHashingContext<'a>> for RenderedConst { | |
417 | #[inline] | |
418 | fn hash_stable<W: StableHasherResult>(&self, | |
419 | hcx: &mut StableHashingContext<'a>, | |
420 | hasher: &mut StableHasher<W>) { | |
421 | self.0.hash_stable(hcx, hasher); | |
422 | } | |
423 | } | |
424 | ||
9e0c209e SL |
425 | #[derive(RustcEncodable, RustcDecodable)] |
426 | pub struct ModData { | |
c30ab7b3 | 427 | pub reexports: LazySeq<def::Export>, |
9e0c209e SL |
428 | } |
429 | ||
cc61c64b XL |
430 | impl_stable_hash_for!(struct ModData { reexports }); |
431 | ||
476ff2be SL |
432 | #[derive(RustcEncodable, RustcDecodable)] |
433 | pub struct MacroDef { | |
434 | pub body: String, | |
7cac9316 | 435 | pub legacy: bool, |
476ff2be SL |
436 | } |
437 | ||
7cac9316 | 438 | impl_stable_hash_for!(struct MacroDef { body, legacy }); |
cc61c64b | 439 | |
9e0c209e | 440 | #[derive(RustcEncodable, RustcDecodable)] |
041b39d2 | 441 | pub struct FnData<'tcx> { |
9e0c209e | 442 | pub constness: hir::Constness, |
c30ab7b3 | 443 | pub arg_names: LazySeq<ast::Name>, |
041b39d2 | 444 | pub sig: Lazy<ty::PolyFnSig<'tcx>>, |
9e0c209e SL |
445 | } |
446 | ||
041b39d2 | 447 | impl_stable_hash_for!(struct FnData<'tcx> { constness, arg_names, sig }); |
cc61c64b | 448 | |
9e0c209e | 449 | #[derive(RustcEncodable, RustcDecodable)] |
041b39d2 | 450 | pub struct VariantData<'tcx> { |
c30ab7b3 | 451 | pub ctor_kind: CtorKind, |
8bb4bdeb | 452 | pub discr: ty::VariantDiscr, |
9e0c209e SL |
453 | |
454 | /// If this is a struct's only variant, this | |
455 | /// is the index of the "struct ctor" item. | |
c30ab7b3 | 456 | pub struct_ctor: Option<DefIndex>, |
041b39d2 XL |
457 | |
458 | /// If this is a tuple struct or variant | |
459 | /// ctor, this is its "function" signature. | |
460 | pub ctor_sig: Option<Lazy<ty::PolyFnSig<'tcx>>>, | |
9e0c209e SL |
461 | } |
462 | ||
041b39d2 | 463 | impl_stable_hash_for!(struct VariantData<'tcx> { |
cc61c64b XL |
464 | ctor_kind, |
465 | discr, | |
041b39d2 XL |
466 | struct_ctor, |
467 | ctor_sig | |
cc61c64b XL |
468 | }); |
469 | ||
9e0c209e SL |
470 | #[derive(RustcEncodable, RustcDecodable)] |
471 | pub struct TraitData<'tcx> { | |
472 | pub unsafety: hir::Unsafety, | |
473 | pub paren_sugar: bool, | |
abe05a73 | 474 | pub has_auto_impl: bool, |
0bf4aa26 | 475 | pub is_marker: bool, |
c30ab7b3 | 476 | pub super_predicates: Lazy<ty::GenericPredicates<'tcx>>, |
9e0c209e SL |
477 | } |
478 | ||
cc61c64b XL |
479 | impl_stable_hash_for!(struct TraitData<'tcx> { |
480 | unsafety, | |
481 | paren_sugar, | |
abe05a73 | 482 | has_auto_impl, |
0bf4aa26 | 483 | is_marker, |
cc61c64b XL |
484 | super_predicates |
485 | }); | |
486 | ||
9e0c209e SL |
487 | #[derive(RustcEncodable, RustcDecodable)] |
488 | pub struct ImplData<'tcx> { | |
489 | pub polarity: hir::ImplPolarity, | |
7cac9316 | 490 | pub defaultness: hir::Defaultness, |
9e0c209e | 491 | pub parent_impl: Option<DefId>, |
cc61c64b XL |
492 | |
493 | /// This is `Some` only for impls of `CoerceUnsized`. | |
494 | pub coerce_unsized_info: Option<ty::adjustment::CoerceUnsizedInfo>, | |
c30ab7b3 | 495 | pub trait_ref: Option<Lazy<ty::TraitRef<'tcx>>>, |
9e0c209e SL |
496 | } |
497 | ||
cc61c64b XL |
498 | impl_stable_hash_for!(struct ImplData<'tcx> { |
499 | polarity, | |
7cac9316 | 500 | defaultness, |
cc61c64b XL |
501 | parent_impl, |
502 | coerce_unsized_info, | |
503 | trait_ref | |
504 | }); | |
505 | ||
506 | ||
9e0c209e SL |
507 | /// Describes whether the container of an associated item |
508 | /// is a trait or an impl and whether, in a trait, it has | |
509 | /// a default, or an in impl, whether it's marked "default". | |
510 | #[derive(Copy, Clone, RustcEncodable, RustcDecodable)] | |
511 | pub enum AssociatedContainer { | |
512 | TraitRequired, | |
513 | TraitWithDefault, | |
514 | ImplDefault, | |
c30ab7b3 | 515 | ImplFinal, |
9e0c209e SL |
516 | } |
517 | ||
cc61c64b XL |
518 | impl_stable_hash_for!(enum ::schema::AssociatedContainer { |
519 | TraitRequired, | |
520 | TraitWithDefault, | |
521 | ImplDefault, | |
522 | ImplFinal | |
523 | }); | |
524 | ||
9e0c209e | 525 | impl AssociatedContainer { |
476ff2be | 526 | pub fn with_def_id(&self, def_id: DefId) -> ty::AssociatedItemContainer { |
9e0c209e SL |
527 | match *self { |
528 | AssociatedContainer::TraitRequired | | |
c30ab7b3 | 529 | AssociatedContainer::TraitWithDefault => ty::TraitContainer(def_id), |
9e0c209e SL |
530 | |
531 | AssociatedContainer::ImplDefault | | |
c30ab7b3 | 532 | AssociatedContainer::ImplFinal => ty::ImplContainer(def_id), |
9e0c209e SL |
533 | } |
534 | } | |
535 | ||
9e0c209e SL |
536 | pub fn defaultness(&self) -> hir::Defaultness { |
537 | match *self { | |
476ff2be SL |
538 | AssociatedContainer::TraitRequired => hir::Defaultness::Default { |
539 | has_value: false, | |
540 | }, | |
541 | ||
9e0c209e | 542 | AssociatedContainer::TraitWithDefault | |
476ff2be SL |
543 | AssociatedContainer::ImplDefault => hir::Defaultness::Default { |
544 | has_value: true, | |
545 | }, | |
9e0c209e | 546 | |
c30ab7b3 | 547 | AssociatedContainer::ImplFinal => hir::Defaultness::Final, |
9e0c209e SL |
548 | } |
549 | } | |
550 | } | |
551 | ||
552 | #[derive(RustcEncodable, RustcDecodable)] | |
041b39d2 XL |
553 | pub struct MethodData<'tcx> { |
554 | pub fn_data: FnData<'tcx>, | |
9e0c209e | 555 | pub container: AssociatedContainer, |
476ff2be | 556 | pub has_self: bool, |
9e0c209e | 557 | } |
041b39d2 | 558 | impl_stable_hash_for!(struct MethodData<'tcx> { fn_data, container, has_self }); |
9e0c209e SL |
559 | |
560 | #[derive(RustcEncodable, RustcDecodable)] | |
561 | pub struct ClosureData<'tcx> { | |
041b39d2 | 562 | pub sig: Lazy<ty::PolyFnSig<'tcx>>, |
9e0c209e | 563 | } |
ff7c6d11 | 564 | impl_stable_hash_for!(struct ClosureData<'tcx> { sig }); |
ea8adc8c XL |
565 | |
566 | #[derive(RustcEncodable, RustcDecodable)] | |
567 | pub struct GeneratorData<'tcx> { | |
ea8adc8c XL |
568 | pub layout: mir::GeneratorLayout<'tcx>, |
569 | } | |
ff7c6d11 | 570 | impl_stable_hash_for!(struct GeneratorData<'tcx> { layout }); |
2c00a5a8 XL |
571 | |
572 | // Tags used for encoding Spans: | |
573 | pub const TAG_VALID_SPAN: u8 = 0; | |
574 | pub const TAG_INVALID_SPAN: u8 = 1; | |
83c7162d XL |
575 | |
576 | #[derive(RustcEncodable, RustcDecodable)] | |
577 | pub struct EncodedExportedSymbols { | |
578 | pub position: usize, | |
579 | pub len: usize, | |
580 | } |