Rollup merge of #124492 - Strophox:adjust-allocbytes, r=RalfJung
Generalize `adjust_from_tcx` for `Allocation` Previously, `adjust_from_tcx` would take an `Allocation` and "adjust allocation from the ones in `tcx` to a custom Machine instance [...]". This PR generalizes this so the Machine instance can also determine the `Bytes` type of the output `Allocation`. r? `@RalfJung`
This commit is contained in:
commit
eaca729e0b
1 changed files with 5 additions and 7 deletions
|
@ -29,9 +29,7 @@ use provenance_map::*;
|
||||||
pub use init_mask::{InitChunk, InitChunkIter};
|
pub use init_mask::{InitChunk, InitChunkIter};
|
||||||
|
|
||||||
/// Functionality required for the bytes of an `Allocation`.
|
/// Functionality required for the bytes of an `Allocation`.
|
||||||
pub trait AllocBytes:
|
pub trait AllocBytes: Clone + fmt::Debug + Deref<Target = [u8]> + DerefMut<Target = [u8]> {
|
||||||
Clone + fmt::Debug + Eq + PartialEq + Hash + Deref<Target = [u8]> + DerefMut<Target = [u8]>
|
|
||||||
{
|
|
||||||
/// Create an `AllocBytes` from a slice of `u8`.
|
/// Create an `AllocBytes` from a slice of `u8`.
|
||||||
fn from_bytes<'a>(slice: impl Into<Cow<'a, [u8]>>, _align: Align) -> Self;
|
fn from_bytes<'a>(slice: impl Into<Cow<'a, [u8]>>, _align: Align) -> Self;
|
||||||
|
|
||||||
|
@ -346,10 +344,10 @@ impl<Prov: Provenance, Bytes: AllocBytes> Allocation<Prov, (), Bytes> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Bytes: AllocBytes> Allocation<CtfeProvenance, (), Bytes> {
|
impl Allocation {
|
||||||
/// Adjust allocation from the ones in `tcx` to a custom Machine instance
|
/// Adjust allocation from the ones in `tcx` to a custom Machine instance
|
||||||
/// with a different `Provenance` and `Extra` type.
|
/// with a different `Provenance`, `Extra` and `Byte` type.
|
||||||
pub fn adjust_from_tcx<Prov: Provenance, Extra, Err>(
|
pub fn adjust_from_tcx<Prov: Provenance, Extra, Bytes: AllocBytes, Err>(
|
||||||
self,
|
self,
|
||||||
cx: &impl HasDataLayout,
|
cx: &impl HasDataLayout,
|
||||||
extra: Extra,
|
extra: Extra,
|
||||||
|
@ -371,7 +369,7 @@ impl<Bytes: AllocBytes> Allocation<CtfeProvenance, (), Bytes> {
|
||||||
}
|
}
|
||||||
// Create allocation.
|
// Create allocation.
|
||||||
Ok(Allocation {
|
Ok(Allocation {
|
||||||
bytes,
|
bytes: AllocBytes::from_bytes(Cow::Owned(Vec::from(bytes)), self.align),
|
||||||
provenance: ProvenanceMap::from_presorted_ptrs(new_provenance),
|
provenance: ProvenanceMap::from_presorted_ptrs(new_provenance),
|
||||||
init_mask: self.init_mask,
|
init_mask: self.init_mask,
|
||||||
align: self.align,
|
align: self.align,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue