]> git.lizzy.rs Git - rust.git/blob - src/librustc/middle/cstore.rs
88fac105bf55a0f7e82d0697ed23e7043d595d64
[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<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
302                            -> Option<ty::AssociatedItem>;
303
304     // flags
305     fn is_const_fn(&self, did: DefId) -> bool;
306     fn is_defaulted_trait(&self, did: DefId) -> bool;
307     fn is_default_impl(&self, impl_did: DefId) -> bool;
308     fn is_foreign_item(&self, did: DefId) -> bool;
309     fn is_dllimport_foreign_item(&self, def: DefId) -> bool;
310     fn is_statically_included_foreign_item(&self, def_id: DefId) -> bool;
311
312     // crate metadata
313     fn dylib_dependency_formats(&self, cnum: CrateNum)
314                                     -> Vec<(CrateNum, LinkagePreference)>;
315     fn dep_kind(&self, cnum: CrateNum) -> DepKind;
316     fn export_macros(&self, cnum: CrateNum);
317     fn lang_items(&self, cnum: CrateNum) -> Vec<(DefIndex, usize)>;
318     fn missing_lang_items(&self, cnum: CrateNum) -> Vec<lang_items::LangItem>;
319     fn is_staged_api(&self, cnum: CrateNum) -> bool;
320     fn is_allocator(&self, cnum: CrateNum) -> bool;
321     fn is_panic_runtime(&self, cnum: CrateNum) -> bool;
322     fn is_compiler_builtins(&self, cnum: CrateNum) -> bool;
323     fn panic_strategy(&self, cnum: CrateNum) -> PanicStrategy;
324     fn extern_crate(&self, cnum: CrateNum) -> Option<ExternCrate>;
325     /// The name of the crate as it is referred to in source code of the current
326     /// crate.
327     fn crate_name(&self, cnum: CrateNum) -> Symbol;
328     /// The name of the crate as it is stored in the crate's metadata.
329     fn original_crate_name(&self, cnum: CrateNum) -> Symbol;
330     fn crate_hash(&self, cnum: CrateNum) -> Svh;
331     fn crate_disambiguator(&self, cnum: CrateNum) -> Symbol;
332     fn plugin_registrar_fn(&self, cnum: CrateNum) -> Option<DefId>;
333     fn derive_registrar_fn(&self, cnum: CrateNum) -> Option<DefId>;
334     fn native_libraries(&self, cnum: CrateNum) -> Vec<NativeLibrary>;
335     fn exported_symbols(&self, cnum: CrateNum) -> Vec<DefId>;
336     fn is_no_builtins(&self, cnum: CrateNum) -> bool;
337
338     // resolve
339     fn retrace_path(&self,
340                     cnum: CrateNum,
341                     path_data: &[DisambiguatedDefPathData])
342                     -> Option<DefId>;
343     fn def_key(&self, def: DefId) -> DefKey;
344     fn relative_def_path(&self, def: DefId) -> Option<hir_map::DefPath>;
345     fn struct_field_names(&self, def: DefId) -> Vec<ast::Name>;
346     fn item_children(&self, did: DefId) -> Vec<def::Export>;
347     fn load_macro(&self, did: DefId, sess: &Session) -> LoadedMacro;
348
349     // misc. metadata
350     fn maybe_get_item_ast<'a>(&'tcx self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
351                               -> Option<(&'tcx InlinedItem, ast::NodeId)>;
352     fn local_node_for_inlined_defid(&'tcx self, def_id: DefId) -> Option<ast::NodeId>;
353     fn defid_for_inlined_node(&'tcx self, node_id: ast::NodeId) -> Option<DefId>;
354
355     fn get_item_mir<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId) -> Mir<'tcx>;
356     fn is_item_mir_available(&self, def: DefId) -> bool;
357
358     /// Take a look if we need to inline or monomorphize this. If so, we
359     /// will emit code for this item in the local crate, and thus
360     /// create a translation item for it.
361     fn can_have_local_instance<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId) -> bool;
362
363     // This is basically a 1-based range of ints, which is a little
364     // silly - I may fix that.
365     fn crates(&self) -> Vec<CrateNum>;
366     fn used_libraries(&self) -> Vec<NativeLibrary>;
367     fn used_link_args(&self) -> Vec<String>;
368
369     // utility functions
370     fn metadata_filename(&self) -> &str;
371     fn metadata_section_name(&self, target: &Target) -> &str;
372     fn used_crates(&self, prefer: LinkagePreference) -> Vec<(CrateNum, LibSource)>;
373     fn used_crate_source(&self, cnum: CrateNum) -> CrateSource;
374     fn extern_mod_stmt_cnum(&self, emod_id: ast::NodeId) -> Option<CrateNum>;
375     fn encode_metadata<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>,
376                            reexports: &def::ExportMap,
377                            link_meta: &LinkMeta,
378                            reachable: &NodeSet) -> Vec<u8>;
379     fn metadata_encoding_version(&self) -> &[u8];
380 }
381
382 // FIXME: find a better place for this?
383 pub fn validate_crate_name(sess: Option<&Session>, s: &str, sp: Option<Span>) {
384     let mut err_count = 0;
385     {
386         let mut say = |s: &str| {
387             match (sp, sess) {
388                 (_, None) => bug!("{}", s),
389                 (Some(sp), Some(sess)) => sess.span_err(sp, s),
390                 (None, Some(sess)) => sess.err(s),
391             }
392             err_count += 1;
393         };
394         if s.is_empty() {
395             say("crate name must not be empty");
396         }
397         for c in s.chars() {
398             if c.is_alphanumeric() { continue }
399             if c == '_'  { continue }
400             say(&format!("invalid character `{}` in crate name: `{}`", c, s));
401         }
402     }
403
404     if err_count > 0 {
405         sess.unwrap().abort_if_errors();
406     }
407 }
408
409 /// A dummy crate store that does not support any non-local crates,
410 /// for test purposes.
411 pub struct DummyCrateStore;
412 #[allow(unused_variables)]
413 impl<'tcx> CrateStore<'tcx> for DummyCrateStore {
414     // item info
415     fn describe_def(&self, def: DefId) -> Option<Def> { bug!("describe_def") }
416     fn def_span(&self, sess: &Session, def: DefId) -> Span { bug!("def_span") }
417     fn stability(&self, def: DefId) -> Option<attr::Stability> { bug!("stability") }
418     fn deprecation(&self, def: DefId) -> Option<attr::Deprecation> { bug!("deprecation") }
419     fn visibility(&self, def: DefId) -> ty::Visibility { bug!("visibility") }
420     fn closure_kind(&self, def_id: DefId) -> ty::ClosureKind { bug!("closure_kind") }
421     fn closure_ty<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId)
422                       -> ty::ClosureTy<'tcx>  { bug!("closure_ty") }
423     fn item_variances(&self, def: DefId) -> Vec<ty::Variance> { bug!("item_variances") }
424     fn item_type<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
425                      -> Ty<'tcx> { bug!("item_type") }
426     fn visible_parent_map<'a>(&'a self) -> ::std::cell::RefMut<'a, DefIdMap<DefId>> {
427         bug!("visible_parent_map")
428     }
429     fn item_predicates<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
430                            -> ty::GenericPredicates<'tcx> { bug!("item_predicates") }
431     fn item_super_predicates<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
432                                  -> ty::GenericPredicates<'tcx> { bug!("item_super_predicates") }
433     fn item_generics<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
434                          -> ty::Generics<'tcx> { bug!("item_generics") }
435     fn item_attrs(&self, def_id: DefId) -> Vec<ast::Attribute> { bug!("item_attrs") }
436     fn trait_def<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)-> ty::TraitDef
437         { bug!("trait_def") }
438     fn adt_def<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId) -> &'tcx ty::AdtDef
439         { bug!("adt_def") }
440     fn fn_arg_names(&self, did: DefId) -> Vec<ast::Name> { bug!("fn_arg_names") }
441     fn inherent_implementations_for_type(&self, def_id: DefId) -> Vec<DefId> { vec![] }
442
443     // trait info
444     fn implementations_of_trait(&self, filter: Option<DefId>) -> Vec<DefId> { vec![] }
445
446     // impl info
447     fn associated_item_def_ids(&self, def_id: DefId) -> Vec<DefId>
448         { bug!("associated_items") }
449     fn impl_trait_ref<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
450                           -> Option<ty::TraitRef<'tcx>> { bug!("impl_trait_ref") }
451     fn impl_polarity(&self, def: DefId) -> hir::ImplPolarity { bug!("impl_polarity") }
452     fn custom_coerce_unsized_kind(&self, def: DefId)
453                                   -> Option<ty::adjustment::CustomCoerceUnsized>
454         { bug!("custom_coerce_unsized_kind") }
455     fn impl_parent(&self, def: DefId) -> Option<DefId> { bug!("impl_parent") }
456
457     // trait/impl-item info
458     fn trait_of_item(&self, def_id: DefId) -> Option<DefId> { bug!("trait_of_item") }
459     fn associated_item<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
460                            -> Option<ty::AssociatedItem> { bug!("associated_item") }
461
462     // flags
463     fn is_const_fn(&self, did: DefId) -> bool { bug!("is_const_fn") }
464     fn is_defaulted_trait(&self, did: DefId) -> bool { bug!("is_defaulted_trait") }
465     fn is_default_impl(&self, impl_did: DefId) -> bool { bug!("is_default_impl") }
466     fn is_foreign_item(&self, did: DefId) -> bool { bug!("is_foreign_item") }
467     fn is_dllimport_foreign_item(&self, id: DefId) -> bool { false }
468     fn is_statically_included_foreign_item(&self, def_id: DefId) -> bool { false }
469
470     // crate metadata
471     fn dylib_dependency_formats(&self, cnum: CrateNum)
472                                     -> Vec<(CrateNum, LinkagePreference)>
473         { bug!("dylib_dependency_formats") }
474     fn lang_items(&self, cnum: CrateNum) -> Vec<(DefIndex, usize)>
475         { bug!("lang_items") }
476     fn missing_lang_items(&self, cnum: CrateNum) -> Vec<lang_items::LangItem>
477         { bug!("missing_lang_items") }
478     fn is_staged_api(&self, cnum: CrateNum) -> bool { bug!("is_staged_api") }
479     fn dep_kind(&self, cnum: CrateNum) -> DepKind { bug!("is_explicitly_linked") }
480     fn export_macros(&self, cnum: CrateNum) { bug!("export_macros") }
481     fn is_allocator(&self, cnum: CrateNum) -> bool { bug!("is_allocator") }
482     fn is_panic_runtime(&self, cnum: CrateNum) -> bool { bug!("is_panic_runtime") }
483     fn is_compiler_builtins(&self, cnum: CrateNum) -> bool { bug!("is_compiler_builtins") }
484     fn panic_strategy(&self, cnum: CrateNum) -> PanicStrategy {
485         bug!("panic_strategy")
486     }
487     fn extern_crate(&self, cnum: CrateNum) -> Option<ExternCrate> { bug!("extern_crate") }
488     fn crate_name(&self, cnum: CrateNum) -> Symbol { bug!("crate_name") }
489     fn original_crate_name(&self, cnum: CrateNum) -> Symbol {
490         bug!("original_crate_name")
491     }
492     fn crate_hash(&self, cnum: CrateNum) -> Svh { bug!("crate_hash") }
493     fn crate_disambiguator(&self, cnum: CrateNum)
494                            -> Symbol { bug!("crate_disambiguator") }
495     fn plugin_registrar_fn(&self, cnum: CrateNum) -> Option<DefId>
496         { bug!("plugin_registrar_fn") }
497     fn derive_registrar_fn(&self, cnum: CrateNum) -> Option<DefId>
498         { bug!("derive_registrar_fn") }
499     fn native_libraries(&self, cnum: CrateNum) -> Vec<NativeLibrary>
500         { bug!("native_libraries") }
501     fn exported_symbols(&self, cnum: CrateNum) -> Vec<DefId> { bug!("exported_symbols") }
502     fn is_no_builtins(&self, cnum: CrateNum) -> bool { bug!("is_no_builtins") }
503
504     // resolve
505     fn retrace_path(&self,
506                     cnum: CrateNum,
507                     path_data: &[DisambiguatedDefPathData])
508                     -> Option<DefId> {
509         None
510     }
511
512     fn def_key(&self, def: DefId) -> DefKey { bug!("def_key") }
513     fn relative_def_path(&self, def: DefId) -> Option<hir_map::DefPath> {
514         bug!("relative_def_path")
515     }
516     fn struct_field_names(&self, def: DefId) -> Vec<ast::Name> { bug!("struct_field_names") }
517     fn item_children(&self, did: DefId) -> Vec<def::Export> { bug!("item_children") }
518     fn load_macro(&self, did: DefId, sess: &Session) -> LoadedMacro { bug!("load_macro") }
519
520     // misc. metadata
521     fn maybe_get_item_ast<'a>(&'tcx self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
522                               -> Option<(&'tcx InlinedItem, ast::NodeId)> {
523         bug!("maybe_get_item_ast")
524     }
525     fn local_node_for_inlined_defid(&'tcx self, def_id: DefId) -> Option<ast::NodeId> {
526         bug!("local_node_for_inlined_defid")
527     }
528     fn defid_for_inlined_node(&'tcx self, node_id: ast::NodeId) -> Option<DefId> {
529         bug!("defid_for_inlined_node")
530     }
531
532     fn get_item_mir<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
533                         -> Mir<'tcx> { bug!("get_item_mir") }
534     fn is_item_mir_available(&self, def: DefId) -> bool {
535         bug!("is_item_mir_available")
536     }
537     fn can_have_local_instance<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId) -> bool {
538         bug!("can_have_local_instance")
539     }
540
541     // This is basically a 1-based range of ints, which is a little
542     // silly - I may fix that.
543     fn crates(&self) -> Vec<CrateNum> { vec![] }
544     fn used_libraries(&self) -> Vec<NativeLibrary> { vec![] }
545     fn used_link_args(&self) -> Vec<String> { vec![] }
546
547     // utility functions
548     fn metadata_filename(&self) -> &str { bug!("metadata_filename") }
549     fn metadata_section_name(&self, target: &Target) -> &str { bug!("metadata_section_name") }
550     fn used_crates(&self, prefer: LinkagePreference) -> Vec<(CrateNum, LibSource)>
551         { vec![] }
552     fn used_crate_source(&self, cnum: CrateNum) -> CrateSource { bug!("used_crate_source") }
553     fn extern_mod_stmt_cnum(&self, emod_id: ast::NodeId) -> Option<CrateNum> { None }
554     fn encode_metadata<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>,
555                            reexports: &def::ExportMap,
556                            link_meta: &LinkMeta,
557                            reachable: &NodeSet) -> Vec<u8> { vec![] }
558     fn metadata_encoding_version(&self) -> &[u8] { bug!("metadata_encoding_version") }
559 }
560
561 pub trait CrateLoader {
562     fn process_item(&mut self, item: &ast::Item, defs: &Definitions);
563     fn postprocess(&mut self, krate: &ast::Crate);
564 }