]> git.lizzy.rs Git - rust.git/blob - src/librustc/middle/cstore.rs
Auto merge of #38616 - pnkfelix:refactor-mir-dataflow-remove-ctxt, r=arielb1
[rust.git] / src / librustc / middle / cstore.rs
1 // Copyright 2015 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
11 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
12 // file at the top-level directory of this distribution and at
13 // http://rust-lang.org/COPYRIGHT.
14 //
15 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
16 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
17 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
18 // option. This file may not be copied, modified, or distributed
19 // except according to those terms.
20
21 // the rustc crate store interface. This also includes types that
22 // are *mostly* used as a part of that interface, but these should
23 // probably get a better home if someone can find one.
24
25 use hir::def::{self, Def};
26 use hir::def_id::{CrateNum, DefId, DefIndex};
27 use hir::map as hir_map;
28 use hir::map::definitions::{Definitions, DefKey, DisambiguatedDefPathData};
29 use hir::svh::Svh;
30 use middle::lang_items;
31 use ty::{self, Ty, TyCtxt};
32 use mir::Mir;
33 use session::Session;
34 use session::search_paths::PathKind;
35 use util::nodemap::{NodeSet, DefIdMap};
36 use std::path::PathBuf;
37 use std::rc::Rc;
38 use syntax::ast;
39 use syntax::attr;
40 use syntax::ext::base::SyntaxExtension;
41 use syntax::ptr::P;
42 use syntax::symbol::Symbol;
43 use syntax_pos::Span;
44 use rustc_back::target::Target;
45 use hir;
46 use hir::intravisit::Visitor;
47 use rustc_back::PanicStrategy;
48
49 pub use self::NativeLibraryKind::{NativeStatic, NativeFramework, NativeUnknown};
50
51 // lonely orphan structs and enums looking for a better home
52
53 #[derive(Clone, Debug)]
54 pub struct LinkMeta {
55     pub crate_name: Symbol,
56     pub crate_hash: Svh,
57 }
58
59 // Where a crate came from on the local filesystem. One of these three options
60 // must be non-None.
61 #[derive(PartialEq, Clone, Debug)]
62 pub struct CrateSource {
63     pub dylib: Option<(PathBuf, PathKind)>,
64     pub rlib: Option<(PathBuf, PathKind)>,
65     pub rmeta: Option<(PathBuf, PathKind)>,
66 }
67
68 #[derive(RustcEncodable, RustcDecodable, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Debug)]
69 pub enum DepKind {
70     /// A dependency that is only used for its macros, none of which are visible from other crates.
71     /// These are included in the metadata only as placeholders and are ignored when decoding.
72     UnexportedMacrosOnly,
73     /// A dependency that is only used for its macros.
74     MacrosOnly,
75     /// A dependency that is always injected into the dependency list and so
76     /// doesn't need to be linked to an rlib, e.g. the injected allocator.
77     Implicit,
78     /// A dependency that is required by an rlib version of this crate.
79     /// Ordinary `extern crate`s result in `Explicit` dependencies.
80     Explicit,
81 }
82
83 impl DepKind {
84     pub fn macros_only(self) -> bool {
85         match self {
86             DepKind::UnexportedMacrosOnly | DepKind::MacrosOnly => true,
87             DepKind::Implicit | DepKind::Explicit => false,
88         }
89     }
90 }
91
92 #[derive(PartialEq, Clone, Debug)]
93 pub enum LibSource {
94     Some(PathBuf),
95     MetadataOnly,
96     None,
97 }
98
99 impl LibSource {
100     pub fn is_some(&self) -> bool {
101         if let LibSource::Some(_) = *self {
102             true
103         } else {
104             false
105         }
106     }
107
108     pub fn option(&self) -> Option<PathBuf> {
109         match *self {
110             LibSource::Some(ref p) => Some(p.clone()),
111             LibSource::MetadataOnly | LibSource::None => None,
112         }
113     }
114 }
115
116 #[derive(Copy, Debug, PartialEq, Clone, RustcEncodable, RustcDecodable)]
117 pub enum LinkagePreference {
118     RequireDynamic,
119     RequireStatic,
120 }
121
122 #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)]
123 pub enum NativeLibraryKind {
124     NativeStatic,    // native static library (.a archive)
125     NativeFramework, // OSX-specific
126     NativeUnknown,   // default way to specify a dynamic library
127 }
128
129 #[derive(Clone, Hash, RustcEncodable, RustcDecodable)]
130 pub struct NativeLibrary {
131     pub kind: NativeLibraryKind,
132     pub name: Symbol,
133     pub cfg: Option<ast::MetaItem>,
134     pub foreign_items: Vec<DefIndex>,
135 }
136
137 /// The data we save and restore about an inlined item or method.  This is not
138 /// part of the AST that we parse from a file, but it becomes part of the tree
139 /// that we trans.
140 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
141 pub struct InlinedItem {
142     pub def_id: DefId,
143     pub body: P<hir::Expr>,
144     pub const_fn_args: Vec<Option<DefId>>,
145 }
146
147 /// A borrowed version of `hir::InlinedItem`. This is what's encoded when saving
148 /// a crate; it then gets read as an InlinedItem.
149 #[derive(Clone, PartialEq, Eq, RustcEncodable, Hash, Debug)]
150 pub struct InlinedItemRef<'a> {
151     pub def_id: DefId,
152     pub body: &'a hir::Expr,
153     pub const_fn_args: Vec<Option<DefId>>,
154 }
155
156 fn get_fn_args(decl: &hir::FnDecl) -> Vec<Option<DefId>> {
157     decl.inputs.iter().map(|arg| match arg.pat.node {
158         hir::PatKind::Binding(_, def_id, _, _) => Some(def_id),
159         _ => None
160     }).collect()
161 }
162
163 impl<'a> InlinedItemRef<'a> {
164     pub fn from_item<'b, 'tcx>(def_id: DefId,
165                                item: &'a hir::Item,
166                                tcx: TyCtxt<'b, 'a, 'tcx>)
167                                -> InlinedItemRef<'a> {
168         let (body, args) = match item.node {
169             hir::ItemFn(ref decl, _, _, _, _, body_id) =>
170                 (tcx.map.expr(body_id), get_fn_args(decl)),
171             hir::ItemConst(_, ref body) => (&**body, Vec::new()),
172             _ => bug!("InlinedItemRef::from_item wrong kind")
173         };
174         InlinedItemRef {
175             def_id: def_id,
176             body: body,
177             const_fn_args: args
178         }
179     }
180
181     pub fn from_trait_item(def_id: DefId,
182                            item: &'a hir::TraitItem,
183                            _tcx: TyCtxt)
184                            -> InlinedItemRef<'a> {
185         let (body, args) = match item.node {
186             hir::ConstTraitItem(_, Some(ref body)) =>
187                 (&**body, Vec::new()),
188             hir::ConstTraitItem(_, None) => {
189                 bug!("InlinedItemRef::from_trait_item called for const without body")
190             },
191             _ => bug!("InlinedItemRef::from_trait_item wrong kind")
192         };
193         InlinedItemRef {
194             def_id: def_id,
195             body: body,
196             const_fn_args: args
197         }
198     }
199
200     pub fn from_impl_item<'b, 'tcx>(def_id: DefId,
201                                     item: &'a hir::ImplItem,
202                                     tcx: TyCtxt<'b, 'a, 'tcx>)
203                                     -> InlinedItemRef<'a> {
204         let (body, args) = match item.node {
205             hir::ImplItemKind::Method(ref sig, body_id) =>
206                 (tcx.map.expr(body_id), get_fn_args(&sig.decl)),
207             hir::ImplItemKind::Const(_, ref body) =>
208                 (&**body, Vec::new()),
209             _ => bug!("InlinedItemRef::from_impl_item wrong kind")
210         };
211         InlinedItemRef {
212             def_id: def_id,
213             body: body,
214             const_fn_args: args
215         }
216     }
217
218     pub fn visit<V>(&self, visitor: &mut V)
219         where V: Visitor<'a>
220     {
221         visitor.visit_expr(&self.body);
222     }
223 }
224
225 impl InlinedItem {
226     pub fn visit<'ast,V>(&'ast self, visitor: &mut V)
227         where V: Visitor<'ast>
228     {
229         visitor.visit_expr(&self.body);
230     }
231 }
232
233 pub enum LoadedMacro {
234     MacroRules(ast::MacroDef),
235     ProcMacro(Rc<SyntaxExtension>),
236 }
237
238 #[derive(Copy, Clone, Debug)]
239 pub struct ExternCrate {
240     /// def_id of an `extern crate` in the current crate that caused
241     /// this crate to be loaded; note that there could be multiple
242     /// such ids
243     pub def_id: DefId,
244
245     /// span of the extern crate that caused this to be loaded
246     pub span: Span,
247
248     /// If true, then this crate is the crate named by the extern
249     /// crate referenced above. If false, then this crate is a dep
250     /// of the crate.
251     pub direct: bool,
252
253     /// Number of links to reach the extern crate `def_id`
254     /// declaration; used to select the extern crate with the shortest
255     /// path
256     pub path_len: usize,
257 }
258
259 /// A store of Rust crates, through with their metadata
260 /// can be accessed.
261 pub trait CrateStore<'tcx> {
262     // item info
263     fn describe_def(&self, def: DefId) -> Option<Def>;
264     fn def_span(&self, sess: &Session, def: DefId) -> Span;
265     fn stability(&self, def: DefId) -> Option<attr::Stability>;
266     fn deprecation(&self, def: DefId) -> Option<attr::Deprecation>;
267     fn visibility(&self, def: DefId) -> ty::Visibility;
268     fn closure_kind(&self, def_id: DefId) -> ty::ClosureKind;
269     fn closure_ty<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId)
270                       -> ty::ClosureTy<'tcx>;
271     fn item_variances(&self, def: DefId) -> Vec<ty::Variance>;
272     fn item_type<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
273                      -> Ty<'tcx>;
274     fn visible_parent_map<'a>(&'a self) -> ::std::cell::RefMut<'a, DefIdMap<DefId>>;
275     fn item_predicates<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
276                            -> ty::GenericPredicates<'tcx>;
277     fn item_super_predicates<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
278                                  -> ty::GenericPredicates<'tcx>;
279     fn item_generics<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
280                          -> ty::Generics<'tcx>;
281     fn item_attrs(&self, def_id: DefId) -> Vec<ast::Attribute>;
282     fn trait_def<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)-> ty::TraitDef;
283     fn adt_def<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId) -> &'tcx ty::AdtDef;
284     fn fn_arg_names(&self, did: DefId) -> Vec<ast::Name>;
285     fn inherent_implementations_for_type(&self, def_id: DefId) -> Vec<DefId>;
286
287     // trait info
288     fn implementations_of_trait(&self, filter: Option<DefId>) -> Vec<DefId>;
289
290     // impl info
291     fn associated_item_def_ids(&self, def_id: DefId) -> Vec<DefId>;
292     fn impl_trait_ref<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
293                           -> Option<ty::TraitRef<'tcx>>;
294     fn impl_polarity(&self, def: DefId) -> hir::ImplPolarity;
295     fn custom_coerce_unsized_kind(&self, def: DefId)
296                                   -> Option<ty::adjustment::CustomCoerceUnsized>;
297     fn impl_parent(&self, impl_def_id: DefId) -> Option<DefId>;
298
299     // trait/impl-item info
300     fn trait_of_item(&self, def_id: DefId) -> Option<DefId>;
301     fn associated_item(&self, def: DefId) -> Option<ty::AssociatedItem>;
302
303     // flags
304     fn is_const_fn(&self, did: DefId) -> bool;
305     fn is_defaulted_trait(&self, did: DefId) -> bool;
306     fn is_default_impl(&self, impl_did: DefId) -> bool;
307     fn is_foreign_item(&self, did: DefId) -> bool;
308     fn is_dllimport_foreign_item(&self, def: DefId) -> bool;
309     fn is_statically_included_foreign_item(&self, def_id: DefId) -> bool;
310
311     // crate metadata
312     fn dylib_dependency_formats(&self, cnum: CrateNum)
313                                     -> Vec<(CrateNum, LinkagePreference)>;
314     fn dep_kind(&self, cnum: CrateNum) -> DepKind;
315     fn export_macros(&self, cnum: CrateNum);
316     fn lang_items(&self, cnum: CrateNum) -> Vec<(DefIndex, usize)>;
317     fn missing_lang_items(&self, cnum: CrateNum) -> Vec<lang_items::LangItem>;
318     fn is_staged_api(&self, cnum: CrateNum) -> bool;
319     fn is_allocator(&self, cnum: CrateNum) -> bool;
320     fn is_panic_runtime(&self, cnum: CrateNum) -> bool;
321     fn is_compiler_builtins(&self, cnum: CrateNum) -> bool;
322     fn panic_strategy(&self, cnum: CrateNum) -> PanicStrategy;
323     fn extern_crate(&self, cnum: CrateNum) -> Option<ExternCrate>;
324     /// The name of the crate as it is referred to in source code of the current
325     /// crate.
326     fn crate_name(&self, cnum: CrateNum) -> Symbol;
327     /// The name of the crate as it is stored in the crate's metadata.
328     fn original_crate_name(&self, cnum: CrateNum) -> Symbol;
329     fn crate_hash(&self, cnum: CrateNum) -> Svh;
330     fn crate_disambiguator(&self, cnum: CrateNum) -> Symbol;
331     fn plugin_registrar_fn(&self, cnum: CrateNum) -> Option<DefId>;
332     fn derive_registrar_fn(&self, cnum: CrateNum) -> Option<DefId>;
333     fn native_libraries(&self, cnum: CrateNum) -> Vec<NativeLibrary>;
334     fn exported_symbols(&self, cnum: CrateNum) -> Vec<DefId>;
335     fn is_no_builtins(&self, cnum: CrateNum) -> bool;
336
337     // resolve
338     fn retrace_path(&self,
339                     cnum: CrateNum,
340                     path_data: &[DisambiguatedDefPathData])
341                     -> Option<DefId>;
342     fn def_key(&self, def: DefId) -> DefKey;
343     fn def_path(&self, def: DefId) -> hir_map::DefPath;
344     fn struct_field_names(&self, def: DefId) -> Vec<ast::Name>;
345     fn item_children(&self, did: DefId) -> Vec<def::Export>;
346     fn load_macro(&self, did: DefId, sess: &Session) -> LoadedMacro;
347
348     // misc. metadata
349     fn maybe_get_item_ast<'a>(&'tcx self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
350                               -> Option<(&'tcx InlinedItem, ast::NodeId)>;
351     fn local_node_for_inlined_defid(&'tcx self, def_id: DefId) -> Option<ast::NodeId>;
352     fn defid_for_inlined_node(&'tcx self, node_id: ast::NodeId) -> Option<DefId>;
353
354     fn get_item_mir<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId) -> Mir<'tcx>;
355     fn is_item_mir_available(&self, def: DefId) -> bool;
356
357     /// Take a look if we need to inline or monomorphize this. If so, we
358     /// will emit code for this item in the local crate, and thus
359     /// create a translation item for it.
360     fn can_have_local_instance<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId) -> bool;
361
362     // This is basically a 1-based range of ints, which is a little
363     // silly - I may fix that.
364     fn crates(&self) -> Vec<CrateNum>;
365     fn used_libraries(&self) -> Vec<NativeLibrary>;
366     fn used_link_args(&self) -> Vec<String>;
367
368     // utility functions
369     fn metadata_filename(&self) -> &str;
370     fn metadata_section_name(&self, target: &Target) -> &str;
371     fn used_crates(&self, prefer: LinkagePreference) -> Vec<(CrateNum, LibSource)>;
372     fn used_crate_source(&self, cnum: CrateNum) -> CrateSource;
373     fn extern_mod_stmt_cnum(&self, emod_id: ast::NodeId) -> Option<CrateNum>;
374     fn encode_metadata<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>,
375                            reexports: &def::ExportMap,
376                            link_meta: &LinkMeta,
377                            reachable: &NodeSet) -> Vec<u8>;
378     fn metadata_encoding_version(&self) -> &[u8];
379 }
380
381 // FIXME: find a better place for this?
382 pub fn validate_crate_name(sess: Option<&Session>, s: &str, sp: Option<Span>) {
383     let mut err_count = 0;
384     {
385         let mut say = |s: &str| {
386             match (sp, sess) {
387                 (_, None) => bug!("{}", s),
388                 (Some(sp), Some(sess)) => sess.span_err(sp, s),
389                 (None, Some(sess)) => sess.err(s),
390             }
391             err_count += 1;
392         };
393         if s.is_empty() {
394             say("crate name must not be empty");
395         }
396         for c in s.chars() {
397             if c.is_alphanumeric() { continue }
398             if c == '_'  { continue }
399             say(&format!("invalid character `{}` in crate name: `{}`", c, s));
400         }
401     }
402
403     if err_count > 0 {
404         sess.unwrap().abort_if_errors();
405     }
406 }
407
408 /// A dummy crate store that does not support any non-local crates,
409 /// for test purposes.
410 pub struct DummyCrateStore;
411 #[allow(unused_variables)]
412 impl<'tcx> CrateStore<'tcx> for DummyCrateStore {
413     // item info
414     fn describe_def(&self, def: DefId) -> Option<Def> { bug!("describe_def") }
415     fn def_span(&self, sess: &Session, def: DefId) -> Span { bug!("def_span") }
416     fn stability(&self, def: DefId) -> Option<attr::Stability> { bug!("stability") }
417     fn deprecation(&self, def: DefId) -> Option<attr::Deprecation> { bug!("deprecation") }
418     fn visibility(&self, def: DefId) -> ty::Visibility { bug!("visibility") }
419     fn closure_kind(&self, def_id: DefId) -> ty::ClosureKind { bug!("closure_kind") }
420     fn closure_ty<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId)
421                       -> ty::ClosureTy<'tcx>  { bug!("closure_ty") }
422     fn item_variances(&self, def: DefId) -> Vec<ty::Variance> { bug!("item_variances") }
423     fn item_type<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
424                      -> Ty<'tcx> { bug!("item_type") }
425     fn visible_parent_map<'a>(&'a self) -> ::std::cell::RefMut<'a, DefIdMap<DefId>> {
426         bug!("visible_parent_map")
427     }
428     fn item_predicates<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
429                            -> ty::GenericPredicates<'tcx> { bug!("item_predicates") }
430     fn item_super_predicates<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
431                                  -> ty::GenericPredicates<'tcx> { bug!("item_super_predicates") }
432     fn item_generics<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
433                          -> ty::Generics<'tcx> { bug!("item_generics") }
434     fn item_attrs(&self, def_id: DefId) -> Vec<ast::Attribute> { bug!("item_attrs") }
435     fn trait_def<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)-> ty::TraitDef
436         { bug!("trait_def") }
437     fn adt_def<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId) -> &'tcx ty::AdtDef
438         { bug!("adt_def") }
439     fn fn_arg_names(&self, did: DefId) -> Vec<ast::Name> { bug!("fn_arg_names") }
440     fn inherent_implementations_for_type(&self, def_id: DefId) -> Vec<DefId> { vec![] }
441
442     // trait info
443     fn implementations_of_trait(&self, filter: Option<DefId>) -> Vec<DefId> { vec![] }
444
445     // impl info
446     fn associated_item_def_ids(&self, def_id: DefId) -> Vec<DefId>
447         { bug!("associated_items") }
448     fn impl_trait_ref<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
449                           -> Option<ty::TraitRef<'tcx>> { bug!("impl_trait_ref") }
450     fn impl_polarity(&self, def: DefId) -> hir::ImplPolarity { bug!("impl_polarity") }
451     fn custom_coerce_unsized_kind(&self, def: DefId)
452                                   -> Option<ty::adjustment::CustomCoerceUnsized>
453         { bug!("custom_coerce_unsized_kind") }
454     fn impl_parent(&self, def: DefId) -> Option<DefId> { bug!("impl_parent") }
455
456     // trait/impl-item info
457     fn trait_of_item(&self, def_id: DefId) -> Option<DefId> { bug!("trait_of_item") }
458     fn associated_item(&self, def: DefId) -> Option<ty::AssociatedItem> { bug!("associated_item") }
459
460     // flags
461     fn is_const_fn(&self, did: DefId) -> bool { bug!("is_const_fn") }
462     fn is_defaulted_trait(&self, did: DefId) -> bool { bug!("is_defaulted_trait") }
463     fn is_default_impl(&self, impl_did: DefId) -> bool { bug!("is_default_impl") }
464     fn is_foreign_item(&self, did: DefId) -> bool { bug!("is_foreign_item") }
465     fn is_dllimport_foreign_item(&self, id: DefId) -> bool { false }
466     fn is_statically_included_foreign_item(&self, def_id: DefId) -> bool { false }
467
468     // crate metadata
469     fn dylib_dependency_formats(&self, cnum: CrateNum)
470                                     -> Vec<(CrateNum, LinkagePreference)>
471         { bug!("dylib_dependency_formats") }
472     fn lang_items(&self, cnum: CrateNum) -> Vec<(DefIndex, usize)>
473         { bug!("lang_items") }
474     fn missing_lang_items(&self, cnum: CrateNum) -> Vec<lang_items::LangItem>
475         { bug!("missing_lang_items") }
476     fn is_staged_api(&self, cnum: CrateNum) -> bool { bug!("is_staged_api") }
477     fn dep_kind(&self, cnum: CrateNum) -> DepKind { bug!("is_explicitly_linked") }
478     fn export_macros(&self, cnum: CrateNum) { bug!("export_macros") }
479     fn is_allocator(&self, cnum: CrateNum) -> bool { bug!("is_allocator") }
480     fn is_panic_runtime(&self, cnum: CrateNum) -> bool { bug!("is_panic_runtime") }
481     fn is_compiler_builtins(&self, cnum: CrateNum) -> bool { bug!("is_compiler_builtins") }
482     fn panic_strategy(&self, cnum: CrateNum) -> PanicStrategy {
483         bug!("panic_strategy")
484     }
485     fn extern_crate(&self, cnum: CrateNum) -> Option<ExternCrate> { bug!("extern_crate") }
486     fn crate_name(&self, cnum: CrateNum) -> Symbol { bug!("crate_name") }
487     fn original_crate_name(&self, cnum: CrateNum) -> Symbol {
488         bug!("original_crate_name")
489     }
490     fn crate_hash(&self, cnum: CrateNum) -> Svh { bug!("crate_hash") }
491     fn crate_disambiguator(&self, cnum: CrateNum)
492                            -> Symbol { bug!("crate_disambiguator") }
493     fn plugin_registrar_fn(&self, cnum: CrateNum) -> Option<DefId>
494         { bug!("plugin_registrar_fn") }
495     fn derive_registrar_fn(&self, cnum: CrateNum) -> Option<DefId>
496         { bug!("derive_registrar_fn") }
497     fn native_libraries(&self, cnum: CrateNum) -> Vec<NativeLibrary>
498         { bug!("native_libraries") }
499     fn exported_symbols(&self, cnum: CrateNum) -> Vec<DefId> { bug!("exported_symbols") }
500     fn is_no_builtins(&self, cnum: CrateNum) -> bool { bug!("is_no_builtins") }
501
502     // resolve
503     fn retrace_path(&self,
504                     cnum: CrateNum,
505                     path_data: &[DisambiguatedDefPathData])
506                     -> Option<DefId> {
507         None
508     }
509
510     fn def_key(&self, def: DefId) -> DefKey { bug!("def_key") }
511     fn def_path(&self, def: DefId) -> hir_map::DefPath {
512         bug!("relative_def_path")
513     }
514     fn struct_field_names(&self, def: DefId) -> Vec<ast::Name> { bug!("struct_field_names") }
515     fn item_children(&self, did: DefId) -> Vec<def::Export> { bug!("item_children") }
516     fn load_macro(&self, did: DefId, sess: &Session) -> LoadedMacro { bug!("load_macro") }
517
518     // misc. metadata
519     fn maybe_get_item_ast<'a>(&'tcx self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
520                               -> Option<(&'tcx InlinedItem, ast::NodeId)> {
521         bug!("maybe_get_item_ast")
522     }
523     fn local_node_for_inlined_defid(&'tcx self, def_id: DefId) -> Option<ast::NodeId> {
524         bug!("local_node_for_inlined_defid")
525     }
526     fn defid_for_inlined_node(&'tcx self, node_id: ast::NodeId) -> Option<DefId> {
527         bug!("defid_for_inlined_node")
528     }
529
530     fn get_item_mir<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
531                         -> Mir<'tcx> { bug!("get_item_mir") }
532     fn is_item_mir_available(&self, def: DefId) -> bool {
533         bug!("is_item_mir_available")
534     }
535     fn can_have_local_instance<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId) -> bool {
536         bug!("can_have_local_instance")
537     }
538
539     // This is basically a 1-based range of ints, which is a little
540     // silly - I may fix that.
541     fn crates(&self) -> Vec<CrateNum> { vec![] }
542     fn used_libraries(&self) -> Vec<NativeLibrary> { vec![] }
543     fn used_link_args(&self) -> Vec<String> { vec![] }
544
545     // utility functions
546     fn metadata_filename(&self) -> &str { bug!("metadata_filename") }
547     fn metadata_section_name(&self, target: &Target) -> &str { bug!("metadata_section_name") }
548     fn used_crates(&self, prefer: LinkagePreference) -> Vec<(CrateNum, LibSource)>
549         { vec![] }
550     fn used_crate_source(&self, cnum: CrateNum) -> CrateSource { bug!("used_crate_source") }
551     fn extern_mod_stmt_cnum(&self, emod_id: ast::NodeId) -> Option<CrateNum> { None }
552     fn encode_metadata<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>,
553                            reexports: &def::ExportMap,
554                            link_meta: &LinkMeta,
555                            reachable: &NodeSet) -> Vec<u8> { vec![] }
556     fn metadata_encoding_version(&self) -> &[u8] { bug!("metadata_encoding_version") }
557 }
558
559 pub trait CrateLoader {
560     fn process_item(&mut self, item: &ast::Item, defs: &Definitions);
561     fn postprocess(&mut self, krate: &ast::Crate);
562 }