Skip to content

Commit fc6d74d

Browse files
authored
Rollup merge of rust-lang#114466 - ouz-a:smir_allocation, r=oli-obk
Add Allocation to SMIR As it's discussed [here ](https://rust-lang.zulipchat.com/#narrow/stream/320896-project-stable-mir/topic/Representing.20Constants.20in.20smir)this is an attempt to cover Constants for smir in a different way compared to rust-lang#114342 cc rust-lang/project-stable-mir#15 r? `@oli-obk`
2 parents bc720ad + b9a539e commit fc6d74d

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

compiler/rustc_smir/src/rustc_smir/mod.rs

+31
Original file line numberDiff line numberDiff line change
@@ -1063,3 +1063,34 @@ impl<'tcx> Stable<'tcx> for rustc_middle::ty::BoundTy {
10631063
BoundTy { var: self.var.as_usize(), kind: self.kind.stable(tables) }
10641064
}
10651065
}
1066+
1067+
impl<'tcx> Stable<'tcx> for mir::interpret::Allocation {
1068+
type T = stable_mir::ty::Allocation;
1069+
1070+
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
1071+
let size = self.size();
1072+
let mut bytes: Vec<Option<u8>> = self
1073+
.inspect_with_uninit_and_ptr_outside_interpreter(0..size.bytes_usize())
1074+
.iter()
1075+
.copied()
1076+
.map(Some)
1077+
.collect();
1078+
for (i, b) in bytes.iter_mut().enumerate() {
1079+
if !self.init_mask().get(rustc_target::abi::Size::from_bytes(i)) {
1080+
*b = None;
1081+
}
1082+
}
1083+
stable_mir::ty::Allocation {
1084+
bytes: bytes,
1085+
provenance: {
1086+
let mut ptrs = Vec::new();
1087+
for (size, prov) in self.provenance().ptrs().iter() {
1088+
ptrs.push((size.bytes_usize(), opaque(prov)));
1089+
}
1090+
stable_mir::ty::ProvenanceMap { ptrs }
1091+
},
1092+
align: self.align.bytes(),
1093+
mutability: self.mutability.stable(tables),
1094+
}
1095+
}
1096+
}

compiler/rustc_smir/src/stable_mir/ty.rs

+22
Original file line numberDiff line numberDiff line change
@@ -242,3 +242,25 @@ pub struct BoundTy {
242242
pub var: usize,
243243
pub kind: BoundTyKind,
244244
}
245+
246+
pub type Bytes = Vec<Option<u8>>;
247+
pub type Size = usize;
248+
pub type Prov = Opaque;
249+
pub type Align = u64;
250+
pub type InitMaskMaterialized = Vec<u64>;
251+
252+
/// Stores the provenance information of pointers stored in memory.
253+
#[derive(Clone, Debug)]
254+
pub struct ProvenanceMap {
255+
/// Provenance in this map applies from the given offset for an entire pointer-size worth of
256+
/// bytes. Two entries in this map are always at least a pointer size apart.
257+
pub ptrs: Vec<(Size, Prov)>,
258+
}
259+
260+
#[derive(Clone, Debug)]
261+
pub struct Allocation {
262+
pub bytes: Bytes,
263+
pub provenance: ProvenanceMap,
264+
pub align: Align,
265+
pub mutability: Mutability,
266+
}

0 commit comments

Comments
 (0)