Skip to content

Commit f1dfcab

Browse files
committed
refactor: Update 'fn allocate_bytes()' return type and restore comments
- Modify allocate_bytes() to return more appropriate pointer type - Revert dedup function documentation to original version per review Signed-off-by: shamb0 <r.raajey@gmail.com>
1 parent ae50d52 commit f1dfcab

File tree

1 file changed

+9
-12
lines changed
  • compiler/rustc_const_eval/src/interpret

1 file changed

+9
-12
lines changed

compiler/rustc_const_eval/src/interpret/place.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,22 +1027,19 @@ where
10271027
align: Align,
10281028
kind: MemoryKind<M::MemoryKind>,
10291029
mutbl: Mutability,
1030-
) -> InterpResult<'tcx, MPlaceTy<'tcx, M::Provenance>> {
1031-
let ptr = if mutbl.is_not() {
1032-
// Deduplicate immutable allocations using a salted hash
1030+
) -> InterpResult<'tcx, Pointer<M::Provenance>> {
1031+
// Use cache for immutable strings.
1032+
if mutbl.is_not() {
1033+
// Use dedup'd allocation function.
10331034
let salt = M::get_global_alloc_salt(self, None);
10341035
let id = self.tcx.allocate_bytes_dedup(bytes, salt);
10351036

10361037
// Transform allocation ID to a machine-specific pointer with proper provenance
1037-
M::adjust_alloc_root_pointer(&self, Pointer::from(id), Some(kind))?
1038+
M::adjust_alloc_root_pointer(&self, Pointer::from(id), Some(kind))
10381039
} else {
10391040
// Allocate new memory for mutable data
1040-
self.allocate_bytes_ptr(bytes, align, kind, mutbl)?
1041-
};
1042-
1043-
let layout = self.layout_of(self.tcx.types.u8).unwrap();
1044-
1045-
interp_ok(self.ptr_to_mplace(ptr.into(), layout))
1041+
self.allocate_bytes_ptr(bytes, align, kind, mutbl)
1042+
}
10461043
}
10471044

10481045
/// Allocates a string in the interpreter's memory with metadata for length.
@@ -1054,7 +1051,7 @@ where
10541051
mutbl: Mutability,
10551052
) -> InterpResult<'tcx, MPlaceTy<'tcx, M::Provenance>> {
10561053
let bytes = str.as_bytes();
1057-
let mplace_type = self.allocate_bytes(bytes, Align::ONE, kind, mutbl)?;
1054+
let ptr = self.allocate_bytes(bytes, Align::ONE, kind, mutbl)?;
10581055

10591056
// Create length metadata for the string
10601057
let meta = Scalar::from_target_usize(u64::try_from(bytes.len()).unwrap(), self);
@@ -1064,7 +1061,7 @@ where
10641061

10651062
// Combine pointer and metadata into a wide pointer
10661063
interp_ok(self.ptr_with_meta_to_mplace(
1067-
mplace_type.ptr().into(),
1064+
ptr.into(),
10681065
MemPlaceMeta::Meta(meta),
10691066
layout,
10701067
/*unaligned*/ false,

0 commit comments

Comments
 (0)