Skip to content

Commit 7cc5ac2

Browse files
committed
Auto merge of rust-lang#115470 - ericmarkmartin:stable-prov, r=oli-obk
add stable provenance r? `@spastorino` implements rust-lang/project-stable-mir#22
2 parents a989e25 + cb7d020 commit 7cc5ac2

File tree

5 files changed

+28
-7
lines changed

5 files changed

+28
-7
lines changed

compiler/rustc_smir/src/rustc_internal/mod.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use crate::{
1313
};
1414
use rustc_driver::{Callbacks, Compilation, RunCompiler};
1515
use rustc_interface::{interface, Queries};
16+
use rustc_middle::mir::interpret::AllocId;
1617
use rustc_middle::ty::TyCtxt;
1718
use rustc_session::EarlyErrorHandler;
1819
pub use rustc_span::def_id::{CrateNum, DefId};
@@ -133,6 +134,10 @@ impl<'tcx> Tables<'tcx> {
133134
stable_mir::ty::ImplDef(self.create_def_id(did))
134135
}
135136

137+
pub fn prov(&mut self, aid: AllocId) -> stable_mir::ty::Prov {
138+
stable_mir::ty::Prov(self.create_alloc_id(aid))
139+
}
140+
136141
fn create_def_id(&mut self, did: DefId) -> stable_mir::DefId {
137142
// FIXME: this becomes inefficient when we have too many ids
138143
for (i, &d) in self.def_ids.iter().enumerate() {
@@ -144,14 +149,24 @@ impl<'tcx> Tables<'tcx> {
144149
self.def_ids.push(did);
145150
stable_mir::DefId(id)
146151
}
152+
153+
fn create_alloc_id(&mut self, aid: AllocId) -> stable_mir::AllocId {
154+
// FIXME: this becomes inefficient when we have too many ids
155+
if let Some(i) = self.alloc_ids.iter().position(|a| *a == aid) {
156+
return stable_mir::AllocId(i);
157+
};
158+
let id = self.def_ids.len();
159+
self.alloc_ids.push(aid);
160+
stable_mir::AllocId(id)
161+
}
147162
}
148163

149164
pub fn crate_num(item: &stable_mir::Crate) -> CrateNum {
150165
item.id.into()
151166
}
152167

153168
pub fn run(tcx: TyCtxt<'_>, f: impl FnOnce()) {
154-
crate::stable_mir::run(Tables { tcx, def_ids: vec![], types: vec![] }, f);
169+
crate::stable_mir::run(Tables { tcx, def_ids: vec![], alloc_ids: vec![], types: vec![] }, f);
155170
}
156171

157172
/// A type that provides internal information but that can still be used for debug purpose.

compiler/rustc_smir/src/rustc_smir/alloc.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use rustc_middle::mir::interpret::{alloc_range, AllocRange, ConstValue, Pointer};
22

33
use crate::{
4-
rustc_internal::opaque,
54
rustc_smir::{Stable, Tables},
65
stable_mir::mir::Mutability,
76
stable_mir::ty::{Allocation, ProvenanceMap},
@@ -113,7 +112,7 @@ pub(super) fn allocation_filter<'tcx>(
113112
.iter()
114113
.filter(|a| a.0 >= alloc_range.start && a.0 <= alloc_range.end())
115114
{
116-
ptrs.push((offset.bytes_usize() - alloc_range.start.bytes_usize(), opaque(prov)));
115+
ptrs.push((offset.bytes_usize() - alloc_range.start.bytes_usize(), tables.prov(*prov)));
117116
}
118117
Allocation {
119118
bytes: bytes,

compiler/rustc_smir/src/rustc_smir/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! Module that implements what will become the rustc side of Stable MIR.
2-
//!
2+
33
//! This module is responsible for building Stable MIR components from internal components.
44
//!
55
//! This module is not intended to be invoked directly by users. It will eventually
@@ -12,7 +12,7 @@ use crate::stable_mir::mir::{CopyNonOverlapping, UserTypeProjection, VariantIdx}
1212
use crate::stable_mir::ty::{FloatTy, GenericParamDef, IntTy, Movability, RigidTy, TyKind, UintTy};
1313
use crate::stable_mir::{self, Context};
1414
use rustc_hir as hir;
15-
use rustc_middle::mir::interpret::alloc_range;
15+
use rustc_middle::mir::interpret::{alloc_range, AllocId};
1616
use rustc_middle::mir::{self, ConstantKind};
1717
use rustc_middle::ty::{self, Ty, TyCtxt, Variance};
1818
use rustc_span::def_id::{CrateNum, DefId, LOCAL_CRATE};
@@ -125,6 +125,7 @@ impl<'tcx> Context for Tables<'tcx> {
125125
pub struct Tables<'tcx> {
126126
pub tcx: TyCtxt<'tcx>,
127127
pub def_ids: Vec<DefId>,
128+
pub alloc_ids: Vec<AllocId>,
128129
pub types: Vec<Ty<'tcx>>,
129130
}
130131

compiler/rustc_smir/src/stable_mir/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ pub type CrateNum = usize;
3232
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
3333
pub struct DefId(pub(crate) usize);
3434

35+
/// A unique identification number for each provenance
36+
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
37+
pub struct AllocId(pub(crate) usize);
38+
3539
/// A list of crate items.
3640
pub type CrateItems = Vec<CrateItem>;
3741

compiler/rustc_smir/src/stable_mir/ty.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::{mir::Mutability, mir::Safety, with, DefId};
1+
use super::{mir::Mutability, mir::Safety, with, AllocId, DefId};
22
use crate::rustc_internal::Opaque;
33

44
#[derive(Copy, Clone, Debug)]
@@ -260,7 +260,9 @@ pub struct BoundTy {
260260

261261
pub type Bytes = Vec<Option<u8>>;
262262
pub type Size = usize;
263-
pub type Prov = Opaque;
263+
264+
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
265+
pub struct Prov(pub(crate) AllocId);
264266
pub type Align = u64;
265267
pub type Promoted = u32;
266268
pub type InitMaskMaterialized = Vec<u64>;

0 commit comments

Comments
 (0)