Skip to content

Commit 3163962

Browse files
committed
make it more clear which functions create fresh AllocId
1 parent a53b101 commit 3163962

File tree

17 files changed

+31
-33
lines changed

17 files changed

+31
-33
lines changed

compiler/rustc_codegen_cranelift/src/constant.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ fn pointer_for_allocation<'tcx>(
259259
fx: &mut FunctionCx<'_, '_, 'tcx>,
260260
alloc: ConstAllocation<'tcx>,
261261
) -> crate::pointer::Pointer {
262-
let alloc_id = fx.tcx.create_memory_alloc(alloc);
262+
let alloc_id = fx.tcx.reserve_and_set_memory_alloc(alloc);
263263
let data_id = data_id_for_alloc_id(
264264
&mut fx.constants_cx,
265265
&mut *fx.module,

compiler/rustc_const_eval/src/interpret/cast.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
8484
)
8585
.ok_or_else(|| err_inval!(TooGeneric))?;
8686

87-
let fn_ptr = self.create_fn_alloc_ptr(FnVal::Instance(instance));
87+
let fn_ptr = self.fn_ptr(FnVal::Instance(instance));
8888
self.write_pointer(fn_ptr, dest)?;
8989
}
9090
_ => span_bug!(self.cur_span(), "reify fn pointer on {:?}", src.layout.ty),
@@ -116,7 +116,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
116116
ty::ClosureKind::FnOnce,
117117
)
118118
.ok_or_else(|| err_inval!(TooGeneric))?;
119-
let fn_ptr = self.create_fn_alloc_ptr(FnVal::Instance(instance));
119+
let fn_ptr = self.fn_ptr(FnVal::Instance(instance));
120120
self.write_pointer(fn_ptr, dest)?;
121121
}
122122
_ => span_bug!(self.cur_span(), "closure fn pointer on {:?}", src.layout.ty),

compiler/rustc_const_eval/src/interpret/intrinsics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub(crate) fn eval_nullary_intrinsic<'tcx>(
5757
let path = crate::util::type_name(tcx, tp_ty);
5858
let alloc = Allocation::from_bytes_byte_aligned_immutable(path.into_bytes());
5959
let alloc = tcx.mk_const_alloc(alloc);
60-
let alloc_id = tcx.create_memory_alloc(alloc);
60+
let alloc_id = tcx.reserve_and_set_memory_alloc(alloc);
6161
ConstValue::Slice { alloc_id: Some(alloc_id), start: 0, end: alloc.inner().len() }
6262
}
6363
sym::needs_drop => {

compiler/rustc_const_eval/src/interpret/machine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ pub macro compile_time_machine(<$mir: lifetime, $tcx: lifetime>) {
552552
def_id: DefId,
553553
) -> InterpResult<$tcx, Pointer> {
554554
// Use the `AllocId` associated with the `DefId`. Any actual *access* will fail.
555-
Ok(Pointer::new(ecx.tcx.create_static_alloc(def_id), Size::ZERO))
555+
Ok(Pointer::new(ecx.tcx.reserve_and_set_static_alloc(def_id), Size::ZERO))
556556
}
557557

558558
#[inline(always)]

compiler/rustc_const_eval/src/interpret/memory.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
176176
M::adjust_alloc_base_pointer(self, ptr)
177177
}
178178

179-
pub fn create_fn_alloc_ptr(
180-
&mut self,
181-
fn_val: FnVal<'tcx, M::ExtraFnVal>,
182-
) -> Pointer<M::Provenance> {
179+
pub fn fn_ptr(&mut self, fn_val: FnVal<'tcx, M::ExtraFnVal>) -> Pointer<M::Provenance> {
183180
let id = match fn_val {
184-
FnVal::Instance(instance) => self.tcx.create_fn_alloc(instance),
181+
FnVal::Instance(instance) => self.tcx.reserve_and_set_fn_alloc(instance),
185182
FnVal::Other(extra) => {
186183
// FIXME(RalfJung): Should we have a cache here?
187184
let id = self.tcx.reserve_alloc_id();

compiler/rustc_const_eval/src/interpret/traits.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
2727
ensure_monomorphic_enough(*self.tcx, ty)?;
2828
ensure_monomorphic_enough(*self.tcx, poly_trait_ref)?;
2929

30-
let vtable_symbolic_allocation = self.tcx.create_vtable_alloc(ty, poly_trait_ref);
30+
let vtable_symbolic_allocation = self.tcx.reserve_and_set_vtable_alloc(ty, poly_trait_ref);
3131
let vtable_ptr = self.global_base_pointer(Pointer::from(vtable_symbolic_allocation))?;
3232
Ok(vtable_ptr.into())
3333
}

compiler/rustc_middle/src/mir/interpret/mod.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ impl<'s> AllocDecodingSession<'s> {
389389
trace!("creating fn alloc ID");
390390
let instance = ty::Instance::decode(decoder);
391391
trace!("decoded fn alloc instance: {:?}", instance);
392-
let alloc_id = decoder.interner().create_fn_alloc(instance);
392+
let alloc_id = decoder.interner().reserve_and_set_fn_alloc(instance);
393393
alloc_id
394394
}
395395
AllocDiscriminant::VTable => {
@@ -399,15 +399,16 @@ impl<'s> AllocDecodingSession<'s> {
399399
let poly_trait_ref =
400400
<Option<ty::PolyExistentialTraitRef<'_>> as Decodable<D>>::decode(decoder);
401401
trace!("decoded vtable alloc instance: {ty:?}, {poly_trait_ref:?}");
402-
let alloc_id = decoder.interner().create_vtable_alloc(ty, poly_trait_ref);
402+
let alloc_id =
403+
decoder.interner().reserve_and_set_vtable_alloc(ty, poly_trait_ref);
403404
alloc_id
404405
}
405406
AllocDiscriminant::Static => {
406407
assert!(alloc_id.is_none());
407408
trace!("creating extern static alloc ID");
408409
let did = <DefId as Decodable<D>>::decode(decoder);
409410
trace!("decoded static def-ID: {:?}", did);
410-
let alloc_id = decoder.interner().create_static_alloc(did);
411+
let alloc_id = decoder.interner().reserve_and_set_static_alloc(did);
411412
alloc_id
412413
}
413414
}
@@ -544,13 +545,13 @@ impl<'tcx> TyCtxt<'tcx> {
544545

545546
/// Generates an `AllocId` for a static or return a cached one in case this function has been
546547
/// called on the same static before.
547-
pub fn create_static_alloc(self, static_id: DefId) -> AllocId {
548+
pub fn reserve_and_set_static_alloc(self, static_id: DefId) -> AllocId {
548549
self.reserve_and_set_dedup(GlobalAlloc::Static(static_id))
549550
}
550551

551552
/// Generates an `AllocId` for a function. Depending on the function type,
552553
/// this might get deduplicated or assigned a new ID each time.
553-
pub fn create_fn_alloc(self, instance: Instance<'tcx>) -> AllocId {
554+
pub fn reserve_and_set_fn_alloc(self, instance: Instance<'tcx>) -> AllocId {
554555
// Functions cannot be identified by pointers, as asm-equal functions can get deduplicated
555556
// by the linker (we set the "unnamed_addr" attribute for LLVM) and functions can be
556557
// duplicated across crates.
@@ -575,7 +576,7 @@ impl<'tcx> TyCtxt<'tcx> {
575576
}
576577

577578
/// Generates an `AllocId` for a (symbolic, not-reified) vtable. Will get deduplicated.
578-
pub fn create_vtable_alloc(
579+
pub fn reserve_and_set_vtable_alloc(
579580
self,
580581
ty: Ty<'tcx>,
581582
poly_trait_ref: Option<ty::PolyExistentialTraitRef<'tcx>>,
@@ -588,7 +589,7 @@ impl<'tcx> TyCtxt<'tcx> {
588589
/// Statics with identical content will still point to the same `Allocation`, i.e.,
589590
/// their data will be deduplicated through `Allocation` interning -- but they
590591
/// are different places in memory and as such need different IDs.
591-
pub fn create_memory_alloc(self, mem: ConstAllocation<'tcx>) -> AllocId {
592+
pub fn reserve_and_set_memory_alloc(self, mem: ConstAllocation<'tcx>) -> AllocId {
592593
let id = self.reserve_alloc_id();
593594
self.set_alloc_id_memory(id, mem);
594595
id

compiler/rustc_middle/src/ty/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ impl<'tcx> TyCtxt<'tcx> {
647647
// Create an allocation that just contains these bytes.
648648
let alloc = interpret::Allocation::from_bytes_byte_aligned_immutable(bytes);
649649
let alloc = self.mk_const_alloc(alloc);
650-
self.create_memory_alloc(alloc)
650+
self.reserve_and_set_memory_alloc(alloc)
651651
}
652652

653653
/// Returns a range of the start/end indices specified with the

compiler/rustc_middle/src/ty/vtable.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ pub(super) fn vtable_allocation_provider<'tcx>(
8484
let scalar = match entry {
8585
VtblEntry::MetadataDropInPlace => {
8686
let instance = ty::Instance::resolve_drop_in_place(tcx, ty);
87-
let fn_alloc_id = tcx.create_fn_alloc(instance);
87+
let fn_alloc_id = tcx.reserve_and_set_fn_alloc(instance);
8888
let fn_ptr = Pointer::from(fn_alloc_id);
8989
Scalar::from_pointer(fn_ptr, &tcx)
9090
}
@@ -94,7 +94,7 @@ pub(super) fn vtable_allocation_provider<'tcx>(
9494
VtblEntry::Method(instance) => {
9595
// Prepare the fn ptr we write into the vtable.
9696
let instance = instance.polymorphize(tcx);
97-
let fn_alloc_id = tcx.create_fn_alloc(instance);
97+
let fn_alloc_id = tcx.reserve_and_set_fn_alloc(instance);
9898
let fn_ptr = Pointer::from(fn_alloc_id);
9999
Scalar::from_pointer(fn_ptr, &tcx)
100100
}
@@ -112,5 +112,5 @@ pub(super) fn vtable_allocation_provider<'tcx>(
112112
}
113113

114114
vtable.mutability = Mutability::Not;
115-
tcx.create_memory_alloc(tcx.mk_const_alloc(vtable))
115+
tcx.reserve_and_set_memory_alloc(tcx.mk_const_alloc(vtable))
116116
}

compiler/rustc_mir_build/src/build/expr/as_constant.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,15 @@ fn lit_to_mir_constant<'tcx>(
133133
let s = s.as_str();
134134
let allocation = Allocation::from_bytes_byte_aligned_immutable(s.as_bytes());
135135
let allocation = tcx.mk_const_alloc(allocation);
136-
let alloc_id = tcx.create_memory_alloc(allocation);
136+
let alloc_id = tcx.reserve_and_set_memory_alloc(allocation);
137137
ConstValue::Slice { alloc_id: Some(alloc_id), start: 0, end: s.len() }
138138
}
139139
(ast::LitKind::ByteStr(data, _), ty::Ref(_, inner_ty, _))
140140
if matches!(inner_ty.kind(), ty::Slice(_)) =>
141141
{
142142
let allocation = Allocation::from_bytes_byte_aligned_immutable(data as &[u8]);
143143
let allocation = tcx.mk_const_alloc(allocation);
144-
let alloc_id = tcx.create_memory_alloc(allocation);
144+
let alloc_id = tcx.reserve_and_set_memory_alloc(allocation);
145145
ConstValue::Slice { alloc_id: Some(alloc_id), start: 0, end: data.len() }
146146
}
147147
(ast::LitKind::ByteStr(data, _), ty::Ref(_, inner_ty, _)) if inner_ty.is_array() => {
@@ -152,7 +152,7 @@ fn lit_to_mir_constant<'tcx>(
152152
{
153153
let allocation = Allocation::from_bytes_byte_aligned_immutable(data as &[u8]);
154154
let allocation = tcx.mk_const_alloc(allocation);
155-
let alloc_id = tcx.create_memory_alloc(allocation);
155+
let alloc_id = tcx.reserve_and_set_memory_alloc(allocation);
156156
ConstValue::Slice { alloc_id: Some(alloc_id), start: 0, end: data.len() }
157157
}
158158
(ast::LitKind::Byte(n), ty::Uint(ty::UintTy::U8)) => {

0 commit comments

Comments
 (0)