|
5 | 5 | use std::assert_matches::assert_matches; |
6 | 6 |
|
7 | 7 | use either::{Either, Left, Right}; |
8 | | -use rustc_abi::{Align, BackendRepr, HasDataLayout, Size}; |
9 | | -use rustc_ast::Mutability; |
| 8 | +use rustc_abi::{BackendRepr, HasDataLayout, Size}; |
10 | 9 | use rustc_middle::ty::Ty; |
11 | 10 | use rustc_middle::ty::layout::{LayoutOf, TyAndLayout}; |
12 | 11 | use rustc_middle::{bug, mir, span_bug}; |
@@ -1018,40 +1017,31 @@ where |
1018 | 1017 | self.allocate_dyn(layout, kind, MemPlaceMeta::None) |
1019 | 1018 | } |
1020 | 1019 |
|
1021 | | - /// Allocates a sequence of bytes in the interpreter's memory. |
1022 | | - /// For immutable allocations, uses deduplication to reuse existing memory. |
1023 | | - /// For mutable allocations, creates a new unique allocation. |
1024 | | - pub fn allocate_bytes( |
| 1020 | + /// Allocates a sequence of bytes in the interpreter's memory with alignment 1. |
| 1021 | + /// This is allocated in immutable global memory and deduplicated. |
| 1022 | + pub fn allocate_bytes_dedup( |
1025 | 1023 | &mut self, |
1026 | 1024 | bytes: &[u8], |
1027 | | - align: Align, |
1028 | | - kind: MemoryKind<M::MemoryKind>, |
1029 | | - mutbl: Mutability, |
1030 | 1025 | ) -> InterpResult<'tcx, Pointer<M::Provenance>> { |
1031 | | - // Use cache for immutable strings. |
1032 | | - if mutbl.is_not() { |
1033 | | - // Use dedup'd allocation function. |
1034 | | - let salt = M::get_global_alloc_salt(self, None); |
1035 | | - let id = self.tcx.allocate_bytes_dedup(bytes, salt); |
1036 | | - |
1037 | | - // Turn untagged "global" pointers (obtained via `tcx`) into the machine pointer to the allocation. |
1038 | | - M::adjust_alloc_root_pointer(&self, Pointer::from(id), Some(kind)) |
1039 | | - } else { |
1040 | | - // Allocate new memory for mutable data. |
1041 | | - self.allocate_bytes_ptr(bytes, align, kind, mutbl) |
1042 | | - } |
| 1026 | + let salt = M::get_global_alloc_salt(self, None); |
| 1027 | + let id = self.tcx.allocate_bytes_dedup(bytes, salt); |
| 1028 | + |
| 1029 | + // Turn untagged "global" pointers (obtained via `tcx`) into the machine pointer to the allocation. |
| 1030 | + M::adjust_alloc_root_pointer( |
| 1031 | + &self, |
| 1032 | + Pointer::from(id), |
| 1033 | + M::GLOBAL_KIND.map(MemoryKind::Machine), |
| 1034 | + ) |
1043 | 1035 | } |
1044 | 1036 |
|
1045 | | - /// Allocates a string in the interpreter's memory with metadata for length. |
1046 | | - /// Uses `allocate_bytes` internally but adds string-specific metadata handling. |
1047 | | - pub fn allocate_str( |
| 1037 | + /// Allocates a string in the interpreter's memory, returning it as a (wide) place. |
| 1038 | + /// This is allocated in immutable global memory and deduplicated. |
| 1039 | + pub fn allocate_str_dedup( |
1048 | 1040 | &mut self, |
1049 | 1041 | str: &str, |
1050 | | - kind: MemoryKind<M::MemoryKind>, |
1051 | | - mutbl: Mutability, |
1052 | 1042 | ) -> InterpResult<'tcx, MPlaceTy<'tcx, M::Provenance>> { |
1053 | 1043 | let bytes = str.as_bytes(); |
1054 | | - let ptr = self.allocate_bytes(bytes, Align::ONE, kind, mutbl)?; |
| 1044 | + let ptr = self.allocate_bytes_dedup(bytes)?; |
1055 | 1045 |
|
1056 | 1046 | // Create length metadata for the string. |
1057 | 1047 | let meta = Scalar::from_target_usize(u64::try_from(bytes.len()).unwrap(), self); |
|
0 commit comments