Skip to content

Commit b6df827

Browse files
authored
Rollup merge of rust-lang#63933 - wesleywiser:cleanup_from_move_promoted, r=oli-obk
Resolve some small issues related to rust-lang#63580 This resolves some feedback left on rust-lang#63580 after it was merged: - Adds documentation to `mir::Static` and `mir::StaticKind` - Simplifies `maybe_get_optimized_mir()` and `maybe_get_promoted_mir()` cc @bjorn3 @RalfJung
2 parents 4cae33a + 009cce8 commit b6df827

File tree

3 files changed

+32
-33
lines changed

3 files changed

+32
-33
lines changed

src/librustc/mir/mod.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1733,13 +1733,20 @@ pub enum PlaceBase<'tcx> {
17331733
pub struct Static<'tcx> {
17341734
pub ty: Ty<'tcx>,
17351735
pub kind: StaticKind<'tcx>,
1736+
/// The `DefId` of the item this static was declared in. For promoted values, usually, this is
1737+
/// the same as the `DefId` of the `mir::Body` containing the `Place` this promoted appears in.
1738+
/// However, after inlining, that might no longer be the case as inlined `Place`s are copied
1739+
/// into the calling frame.
17361740
pub def_id: DefId,
17371741
}
17381742

17391743
#[derive(
17401744
Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, HashStable, RustcEncodable, RustcDecodable,
17411745
)]
17421746
pub enum StaticKind<'tcx> {
1747+
/// Promoted references consist of an id (`Promoted`) and the substs necessary to monomorphize
1748+
/// it. Usually, these substs are just the identity substs for the item. However, the inliner
1749+
/// will adjust these substs when it inlines a function based on the substs at the callsite.
17431750
Promoted(Promoted, SubstsRef<'tcx>),
17441751
Static,
17451752
}

src/librustc_metadata/cstore_impl.rs

+2-18
Original file line numberDiff line numberDiff line change
@@ -125,24 +125,8 @@ provide! { <'tcx> tcx, def_id, other, cdata,
125125
bug!("coerce_unsized_info: `{:?}` is missing its info", def_id);
126126
})
127127
}
128-
optimized_mir => {
129-
let mir = cdata.maybe_get_optimized_mir(tcx, def_id.index).unwrap_or_else(|| {
130-
bug!("get_optimized_mir: missing MIR for `{:?}`", def_id)
131-
});
132-
133-
let mir = tcx.arena.alloc(mir);
134-
135-
mir
136-
}
137-
promoted_mir => {
138-
let promoted = cdata.maybe_get_promoted_mir(tcx, def_id.index).unwrap_or_else(|| {
139-
bug!("get_promoted_mir: missing promoted MIR for `{:?}`", def_id)
140-
});
141-
142-
let promoted = tcx.arena.alloc(promoted);
143-
144-
promoted
145-
}
128+
optimized_mir => { tcx.arena.alloc(cdata.get_optimized_mir(tcx, def_id.index)) }
129+
promoted_mir => { tcx.arena.alloc(cdata.get_promoted_mir(tcx, def_id.index)) }
146130
mir_const_qualif => {
147131
(cdata.mir_const_qualif(def_id.index), tcx.arena.alloc(BitSet::new_empty(0)))
148132
}

src/librustc_metadata/decoder.rs

+23-15
Original file line numberDiff line numberDiff line change
@@ -450,11 +450,19 @@ impl<'a, 'tcx> CrateMetadata {
450450
pub fn is_proc_macro_crate(&self) -> bool {
451451
self.root.proc_macro_decls_static.is_some()
452452
}
453+
453454
fn is_proc_macro(&self, id: DefIndex) -> bool {
454455
self.is_proc_macro_crate() &&
455456
self.root.proc_macro_data.unwrap().decode(self).find(|x| *x == id).is_some()
456457
}
457458

459+
fn entry_unless_proc_macro(&self, id: DefIndex) -> Option<Entry<'tcx>> {
460+
match self.is_proc_macro(id) {
461+
true => None,
462+
false => Some(self.entry(id)),
463+
}
464+
}
465+
458466
fn maybe_entry(&self, item_id: DefIndex) -> Option<Lazy<Entry<'tcx>>> {
459467
self.root.entries_index.lookup(self.blob.raw_bytes(), item_id)
460468
}
@@ -689,10 +697,8 @@ impl<'a, 'tcx> CrateMetadata {
689697
}
690698

691699
pub fn get_deprecation(&self, id: DefIndex) -> Option<attr::Deprecation> {
692-
match self.is_proc_macro(id) {
693-
true => None,
694-
false => self.entry(id).deprecation.map(|depr| depr.decode(self)),
695-
}
700+
self.entry_unless_proc_macro(id)
701+
.and_then(|entry| entry.deprecation.map(|depr| depr.decode(self)))
696702
}
697703

698704
pub fn get_visibility(&self, id: DefIndex) -> ty::Visibility {
@@ -902,22 +908,24 @@ impl<'a, 'tcx> CrateMetadata {
902908
self.maybe_entry(id).and_then(|item| item.decode(self).mir).is_some()
903909
}
904910

905-
pub fn maybe_get_optimized_mir(&self, tcx: TyCtxt<'tcx>, id: DefIndex) -> Option<Body<'tcx>> {
906-
match self.is_proc_macro(id) {
907-
true => None,
908-
false => self.entry(id).mir.map(|mir| mir.decode((self, tcx))),
909-
}
911+
pub fn get_optimized_mir(&self, tcx: TyCtxt<'tcx>, id: DefIndex) -> Body<'tcx> {
912+
self.entry_unless_proc_macro(id)
913+
.and_then(|entry| entry.mir.map(|mir| mir.decode((self, tcx))))
914+
.unwrap_or_else(|| {
915+
bug!("get_optimized_mir: missing MIR for `{:?}", self.local_def_id(id))
916+
})
910917
}
911918

912-
pub fn maybe_get_promoted_mir(
919+
pub fn get_promoted_mir(
913920
&self,
914921
tcx: TyCtxt<'tcx>,
915922
id: DefIndex,
916-
) -> Option<IndexVec<Promoted, Body<'tcx>>> {
917-
match self.is_proc_macro(id) {
918-
true => None,
919-
false => self.entry(id).promoted_mir.map(|promoted| promoted.decode((self, tcx)),)
920-
}
923+
) -> IndexVec<Promoted, Body<'tcx>> {
924+
self.entry_unless_proc_macro(id)
925+
.and_then(|entry| entry.promoted_mir.map(|promoted| promoted.decode((self, tcx))))
926+
.unwrap_or_else(|| {
927+
bug!("get_promoted_mir: missing MIR for `{:?}`", self.local_def_id(id))
928+
})
921929
}
922930

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

0 commit comments

Comments
 (0)