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