Skip to content

Commit

Permalink
Extract Decoder::entry_unless_proc_macro()
Browse files Browse the repository at this point in the history
  • Loading branch information
wesleywiser committed Aug 28, 2019
1 parent 30b29ab commit 009cce8
Showing 1 changed file with 20 additions and 22 deletions.
42 changes: 20 additions & 22 deletions src/librustc_metadata/decoder.rs
Expand Up @@ -450,11 +450,19 @@ impl<'a, 'tcx> CrateMetadata {
pub fn is_proc_macro_crate(&self) -> bool {
self.root.proc_macro_decls_static.is_some()
}

fn is_proc_macro(&self, id: DefIndex) -> bool {
self.is_proc_macro_crate() &&
self.root.proc_macro_data.unwrap().decode(self).find(|x| *x == id).is_some()
}

fn entry_unless_proc_macro(&self, id: DefIndex) -> Option<Entry<'tcx>> {
match self.is_proc_macro(id) {
true => None,
false => Some(self.entry(id)),
}
}

fn maybe_entry(&self, item_id: DefIndex) -> Option<Lazy<Entry<'tcx>>> {
self.root.entries_index.lookup(self.blob.raw_bytes(), item_id)
}
Expand Down Expand Up @@ -704,10 +712,8 @@ impl<'a, 'tcx> CrateMetadata {
}

pub fn get_deprecation(&self, id: DefIndex) -> Option<attr::Deprecation> {
match self.is_proc_macro(id) {
true => None,
false => self.entry(id).deprecation.map(|depr| depr.decode(self)),
}
self.entry_unless_proc_macro(id)
.and_then(|entry| entry.deprecation.map(|depr| depr.decode(self)))
}

pub fn get_visibility(&self, id: DefIndex) -> ty::Visibility {
Expand Down Expand Up @@ -918,31 +924,23 @@ impl<'a, 'tcx> CrateMetadata {
}

pub fn get_optimized_mir(&self, tcx: TyCtxt<'tcx>, id: DefIndex) -> Body<'tcx> {
let mir =
match self.is_proc_macro(id) {
true => None,
false => self.entry(id).mir.map(|mir| mir.decode((self, tcx))),
};

mir.unwrap_or_else(|| {
bug!("get_optimized_mir: missing MIR for `{:?}`", self.local_def_id(id))
})
self.entry_unless_proc_macro(id)
.and_then(|entry| entry.mir.map(|mir| mir.decode((self, tcx))))
.unwrap_or_else(|| {
bug!("get_optimized_mir: missing MIR for `{:?}", self.local_def_id(id))
})
}

pub fn get_promoted_mir(
&self,
tcx: TyCtxt<'tcx>,
id: DefIndex,
) -> IndexVec<Promoted, Body<'tcx>> {
let promoted =
match self.is_proc_macro(id) {
true => None,
false => self.entry(id).promoted_mir.map(|promoted| promoted.decode((self, tcx)))
};

promoted.unwrap_or_else(|| {
bug!("get_promoted_mir: missing MIR for `{:?}`", self.local_def_id(id))
})
self.entry_unless_proc_macro(id)
.and_then(|entry| entry.promoted_mir.map(|promoted| promoted.decode((self, tcx))))
.unwrap_or_else(|| {
bug!("get_promoted_mir: missing MIR for `{:?}`", self.local_def_id(id))
})
}

pub fn mir_const_qualif(&self, id: DefIndex) -> u8 {
Expand Down

0 comments on commit 009cce8

Please sign in to comment.