diff options
Diffstat (limited to 'src/librustc_metadata/decoder.rs')
| -rw-r--r-- | src/librustc_metadata/decoder.rs | 76 |
1 files changed, 20 insertions, 56 deletions
diff --git a/src/librustc_metadata/decoder.rs b/src/librustc_metadata/decoder.rs index 936d680380c..0147e8dc607 100644 --- a/src/librustc_metadata/decoder.rs +++ b/src/librustc_metadata/decoder.rs @@ -17,8 +17,7 @@ use rustc_data_structures::sync::{Lrc, ReadGuard}; use rustc::hir::map::{DefKey, DefPath, DefPathData, DefPathHash, DisambiguatedDefPathData}; use rustc::hir; -use rustc::middle::cstore::{LinkagePreference, ExternConstBody, - ExternBodyNestedBodies}; +use rustc::middle::cstore::LinkagePreference; use rustc::middle::exported_symbols::{ExportedSymbol, SymbolExportLevel}; use rustc::hir::def::{self, Def, CtorKind}; use rustc::hir::def_id::{CrateNum, DefId, DefIndex, @@ -33,7 +32,6 @@ use rustc::mir::Mir; use rustc::util::captures::Captures; use rustc::util::nodemap::FxHashMap; -use std::collections::BTreeMap; use std::io; use std::mem; use std::u32; @@ -433,7 +431,7 @@ impl<'a, 'tcx> MetadataBlob { impl<'tcx> EntryKind<'tcx> { fn to_def(&self, did: DefId) -> Option<Def> { Some(match *self { - EntryKind::Const(_) => Def::Const(did), + EntryKind::Const(..) => Def::Const(did), EntryKind::AssociatedConst(..) => Def::AssociatedConst(did), EntryKind::ImmStatic | EntryKind::ForeignImmStatic => Def::Static(did, false), @@ -794,54 +792,12 @@ impl<'a, 'tcx> CrateMetadata { } } - pub fn extern_const_body(&self, - tcx: TyCtxt<'a, 'tcx, 'tcx>, - id: DefIndex) - -> ExternConstBody<'tcx> { - assert!(!self.is_proc_macro(id)); - let ast = self.entry(id).ast.unwrap(); - let def_id = self.local_def_id(id); - let ast = ast.decode((self, tcx)); - let body = ast.body.decode((self, tcx)); - ExternConstBody { - body: tcx.hir.intern_inlined_body(def_id, body), - fingerprint: ast.stable_bodies_hash, - } - } - - pub fn item_body_tables(&self, - id: DefIndex, - tcx: TyCtxt<'a, 'tcx, 'tcx>) - -> &'tcx ty::TypeckTables<'tcx> { - let ast = self.entry(id).ast.unwrap().decode(self); - tcx.alloc_tables(ast.tables.decode((self, tcx))) - } - - pub fn item_body_nested_bodies(&self, - tcx: TyCtxt<'a, 'tcx, 'tcx>, - id: DefIndex) - -> ExternBodyNestedBodies { - if let Some(ref ast) = self.entry(id).ast { - let mut ast = ast.decode(self); - let nested_bodies: BTreeMap<_, _> = ast.nested_bodies - .decode((self, tcx.sess)) - .map(|body| (body.id(), body)) - .collect(); - ExternBodyNestedBodies { - nested_bodies: Lrc::new(nested_bodies), - fingerprint: ast.stable_bodies_hash, - } - } else { - ExternBodyNestedBodies { - nested_bodies: Lrc::new(BTreeMap::new()), - fingerprint: Fingerprint::ZERO, - } - } - } - pub fn const_is_rvalue_promotable_to_static(&self, id: DefIndex) -> bool { - self.entry(id).ast.expect("const item missing `ast`") - .decode(self).rvalue_promotable_to_static + match self.entry(id).kind { + EntryKind::AssociatedConst(_, data, _) | + EntryKind::Const(data, _) => data.ast_promotable, + _ => bug!(), + } } pub fn is_item_mir_available(&self, id: DefIndex) -> bool { @@ -861,10 +817,10 @@ impl<'a, 'tcx> CrateMetadata { pub fn mir_const_qualif(&self, id: DefIndex) -> u8 { match self.entry(id).kind { - EntryKind::Const(qualif) | - EntryKind::AssociatedConst(AssociatedContainer::ImplDefault, qualif) | - EntryKind::AssociatedConst(AssociatedContainer::ImplFinal, qualif) => { - qualif + EntryKind::Const(qualif, _) | + EntryKind::AssociatedConst(AssociatedContainer::ImplDefault, qualif, _) | + EntryKind::AssociatedConst(AssociatedContainer::ImplFinal, qualif, _) => { + qualif.mir } _ => bug!(), } @@ -877,7 +833,7 @@ impl<'a, 'tcx> CrateMetadata { let name = def_key.disambiguated_data.data.get_opt_name().unwrap(); let (kind, container, has_self) = match item.kind { - EntryKind::AssociatedConst(container, _) => { + EntryKind::AssociatedConst(container, _, _) => { (ty::AssociatedKind::Const, container, false) } EntryKind::Method(data) => { @@ -1076,6 +1032,14 @@ impl<'a, 'tcx> CrateMetadata { lazy_seq.decode((self, tcx)).collect() } + pub fn get_rendered_const(&self, id: DefIndex) -> String { + match self.entry(id).kind { + EntryKind::Const(_, data) | + EntryKind::AssociatedConst(_, _, data) => data.decode(self).0, + _ => bug!(), + } + } + pub fn wasm_custom_sections(&self) -> Vec<DefId> { let sections = self.root .wasm_custom_sections |
