Skip to content

Commit

Permalink
Simplify maybe_get_optimized_mir and maybe_get_promoted_mir
Browse files Browse the repository at this point in the history
Since both functions are always unwrapped, don't wrap the return value
in an `Option`.
  • Loading branch information
wesleywiser committed Aug 28, 2019
1 parent cca64e7 commit 30b29ab
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 29 deletions.
20 changes: 2 additions & 18 deletions src/librustc_metadata/cstore_impl.rs
Expand Up @@ -127,24 +127,8 @@ provide! { <'tcx> tcx, def_id, other, cdata,
bug!("coerce_unsized_info: `{:?}` is missing its info", def_id);
})
}
optimized_mir => {
let mir = cdata.maybe_get_optimized_mir(tcx, def_id.index).unwrap_or_else(|| {
bug!("get_optimized_mir: missing MIR for `{:?}`", def_id)
});

let mir = tcx.arena.alloc(mir);

mir
}
promoted_mir => {
let promoted = cdata.maybe_get_promoted_mir(tcx, def_id.index).unwrap_or_else(|| {
bug!("get_promoted_mir: missing promoted MIR for `{:?}`", def_id)
});

let promoted = tcx.arena.alloc(promoted);

promoted
}
optimized_mir => { tcx.arena.alloc(cdata.get_optimized_mir(tcx, def_id.index)) }
promoted_mir => { tcx.arena.alloc(cdata.get_promoted_mir(tcx, def_id.index)) }
mir_const_qualif => {
(cdata.mir_const_qualif(def_id.index), tcx.arena.alloc(BitSet::new_empty(0)))
}
Expand Down
32 changes: 21 additions & 11 deletions src/librustc_metadata/decoder.rs
Expand Up @@ -917,22 +917,32 @@ impl<'a, 'tcx> CrateMetadata {
self.maybe_entry(id).and_then(|item| item.decode(self).mir).is_some()
}

pub fn maybe_get_optimized_mir(&self, tcx: TyCtxt<'tcx>, id: DefIndex) -> Option<Body<'tcx>> {
match self.is_proc_macro(id) {
true => None,
false => self.entry(id).mir.map(|mir| mir.decode((self, tcx))),
}
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))
})
}

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

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

0 comments on commit 30b29ab

Please sign in to comment.