Skip to content

Commit 518368c

Browse files
committed
rename get_global_alloc to try_get_global_alloc
1 parent e6f70a5 commit 518368c

File tree

10 files changed

+18
-18
lines changed

10 files changed

+18
-18
lines changed

compiler/rustc_codegen_cranelift/src/constant.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant
362362
let (data_id, alloc, section_name) = match todo_item {
363363
TodoItem::Alloc(alloc_id) => {
364364
//println!("alloc_id {}", alloc_id);
365-
let alloc = match tcx.get_global_alloc(alloc_id).unwrap() {
365+
let alloc = match tcx.global_alloc(alloc_id) {
366366
GlobalAlloc::Memory(alloc) => alloc,
367367
GlobalAlloc::Function(_) | GlobalAlloc::Static(_) | GlobalAlloc::Vtable(..) => {
368368
unreachable!()

compiler/rustc_const_eval/src/const_eval/machine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
369369
// we don't deallocate it.
370370
let (alloc_id, _, _) = ecx.ptr_get_alloc_id(ptr)?;
371371
let is_allocated_in_another_const = matches!(
372-
ecx.tcx.get_global_alloc(alloc_id),
372+
ecx.tcx.try_get_global_alloc(alloc_id),
373373
Some(interpret::GlobalAlloc::Memory(_))
374374
);
375375

compiler/rustc_const_eval/src/const_eval/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ pub(crate) fn deref_mir_constant<'tcx>(
138138
let mplace = ecx.deref_operand(&op).unwrap();
139139
if let Some(alloc_id) = mplace.ptr.provenance {
140140
assert_eq!(
141-
tcx.get_global_alloc(alloc_id).unwrap().unwrap_memory().0.0.mutability,
141+
tcx.global_alloc(alloc_id).unwrap_memory().0.0.mutability,
142142
Mutability::Not,
143143
"deref_mir_constant cannot be used with mutable allocations as \
144144
that could allow pattern matching to observe mutable statics",

compiler/rustc_const_eval/src/interpret/intern.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ fn intern_shallow<'rt, 'mir, 'tcx, M: CompileTimeMachine<'mir, 'tcx, const_eval:
9494
// to validation to error -- it has the much better error messages, pointing out where
9595
// in the value the dangling reference lies.
9696
// The `delay_span_bug` ensures that we don't forget such a check in validation.
97-
if tcx.get_global_alloc(alloc_id).is_none() {
97+
if tcx.try_get_global_alloc(alloc_id).is_none() {
9898
tcx.sess.delay_span_bug(ecx.tcx.span, "tried to intern dangling pointer");
9999
}
100100
// treat dangling pointers like other statics
@@ -454,7 +454,7 @@ pub fn intern_const_alloc_recursive<
454454
.sess
455455
.span_err(ecx.tcx.span, "encountered dangling pointer in final constant");
456456
return Err(reported);
457-
} else if ecx.tcx.get_global_alloc(alloc_id).is_none() {
457+
} else if ecx.tcx.try_get_global_alloc(alloc_id).is_none() {
458458
// We have hit an `AllocId` that is neither in local or global memory and isn't
459459
// marked as dangling by local memory. That should be impossible.
460460
span_bug!(ecx.tcx.span, "encountered unknown alloc id {:?}", alloc_id);

compiler/rustc_const_eval/src/interpret/memory.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
161161
) -> InterpResult<'tcx, Pointer<M::PointerTag>> {
162162
let alloc_id = ptr.provenance;
163163
// We need to handle `extern static`.
164-
match self.tcx.get_global_alloc(alloc_id) {
164+
match self.tcx.try_get_global_alloc(alloc_id) {
165165
Some(GlobalAlloc::Static(def_id)) if self.tcx.is_thread_local_static(def_id) => {
166166
bug!("global memory cannot point to thread-local static")
167167
}
@@ -289,7 +289,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
289289

290290
let Some((alloc_kind, mut alloc)) = self.memory.alloc_map.remove(&alloc_id) else {
291291
// Deallocating global memory -- always an error
292-
return Err(match self.tcx.get_global_alloc(alloc_id) {
292+
return Err(match self.tcx.try_get_global_alloc(alloc_id) {
293293
Some(GlobalAlloc::Function(..)) => {
294294
err_ub_format!("deallocating {alloc_id:?}, which is a function")
295295
}
@@ -474,7 +474,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
474474
id: AllocId,
475475
is_write: bool,
476476
) -> InterpResult<'tcx, Cow<'tcx, Allocation<M::PointerTag, M::AllocExtra>>> {
477-
let (alloc, def_id) = match self.tcx.get_global_alloc(id) {
477+
let (alloc, def_id) = match self.tcx.try_get_global_alloc(id) {
478478
Some(GlobalAlloc::Memory(mem)) => {
479479
// Memory of a constant or promoted or anonymous memory referenced by a static.
480480
(mem, None)
@@ -665,7 +665,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
665665
// # Statics
666666
// Can't do this in the match argument, we may get cycle errors since the lock would
667667
// be held throughout the match.
668-
match self.tcx.get_global_alloc(id) {
668+
match self.tcx.try_get_global_alloc(id) {
669669
Some(GlobalAlloc::Static(did)) => {
670670
assert!(!self.tcx.is_thread_local_static(did));
671671
// Use size and align of the type.
@@ -711,7 +711,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
711711
if let Some(extra) = self.memory.extra_fn_ptr_map.get(&id) {
712712
Some(FnVal::Other(*extra))
713713
} else {
714-
match self.tcx.get_global_alloc(id) {
714+
match self.tcx.try_get_global_alloc(id) {
715715
Some(GlobalAlloc::Function(instance)) => Some(FnVal::Instance(instance)),
716716
_ => None,
717717
}
@@ -835,7 +835,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> std::fmt::Debug for DumpAllocs<'a,
835835
}
836836
None => {
837837
// global alloc
838-
match self.ecx.tcx.get_global_alloc(id) {
838+
match self.ecx.tcx.try_get_global_alloc(id) {
839839
Some(GlobalAlloc::Memory(alloc)) => {
840840
write!(fmt, " (unchanged global, ")?;
841841
write_allocation_track_relocs(

compiler/rustc_const_eval/src/interpret/validity.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
447447
// `!` is a ZST and we want to validate it.
448448
if let Ok((alloc_id, _offset, _tag)) = self.ecx.ptr_try_get_alloc_id(place.ptr) {
449449
// Special handling for pointers to statics (irrespective of their type).
450-
let alloc_kind = self.ecx.tcx.get_global_alloc(alloc_id);
450+
let alloc_kind = self.ecx.tcx.try_get_global_alloc(alloc_id);
451451
if let Some(GlobalAlloc::Static(did)) = alloc_kind {
452452
assert!(!self.ecx.tcx.is_thread_local_static(did));
453453
assert!(self.ecx.tcx.is_static(did));

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ impl<'tcx> TyCtxt<'tcx> {
554554
/// This function exists to allow const eval to detect the difference between evaluation-
555555
/// local dangling pointers and allocations in constants/statics.
556556
#[inline]
557-
pub fn get_global_alloc(self, id: AllocId) -> Option<GlobalAlloc<'tcx>> {
557+
pub fn try_get_global_alloc(self, id: AllocId) -> Option<GlobalAlloc<'tcx>> {
558558
self.alloc_map.lock().alloc_map.get(&id).cloned()
559559
}
560560

@@ -565,7 +565,7 @@ impl<'tcx> TyCtxt<'tcx> {
565565
/// ids), this function is frequently used throughout rustc, but should not be used within
566566
/// the miri engine.
567567
pub fn global_alloc(self, id: AllocId) -> GlobalAlloc<'tcx> {
568-
match self.get_global_alloc(id) {
568+
match self.try_get_global_alloc(id) {
569569
Some(alloc) => alloc,
570570
None => bug!("could not find allocation for {id:?}"),
571571
}

compiler/rustc_middle/src/mir/pretty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ pub fn write_allocations<'tcx>(
720720
write!(w, "{}", display_allocation(tcx, alloc.inner()))
721721
};
722722
write!(w, "\n{id:?}")?;
723-
match tcx.get_global_alloc(id) {
723+
match tcx.try_get_global_alloc(id) {
724724
// This can't really happen unless there are bugs, but it doesn't cost us anything to
725725
// gracefully handle it and allow buggy rustc to be debugged via allocation printing.
726726
None => write!(w, " (deallocated)")?,

compiler/rustc_middle/src/ty/impls_ty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for mir::interpret::AllocId {
147147
ty::tls::with_opt(|tcx| {
148148
trace!("hashing {:?}", *self);
149149
let tcx = tcx.expect("can't hash AllocIds during hir lowering");
150-
tcx.get_global_alloc(*self).hash_stable(hcx, hasher);
150+
tcx.try_get_global_alloc(*self).hash_stable(hcx, hasher);
151151
});
152152
}
153153
}

compiler/rustc_middle/src/ty/print/pretty.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,7 +1269,7 @@ pub trait PrettyPrinter<'tcx>:
12691269
if let ty::Array(elem, len) = inner.kind() {
12701270
if let ty::Uint(ty::UintTy::U8) = elem.kind() {
12711271
if let ty::ConstKind::Value(ty::ValTree::Leaf(int)) = len.kind() {
1272-
match self.tcx().get_global_alloc(alloc_id) {
1272+
match self.tcx().try_get_global_alloc(alloc_id) {
12731273
Some(GlobalAlloc::Memory(alloc)) => {
12741274
let len = int.assert_bits(self.tcx().data_layout.pointer_size);
12751275
let range =
@@ -1298,7 +1298,7 @@ pub trait PrettyPrinter<'tcx>:
12981298
ty::FnPtr(_) => {
12991299
// FIXME: We should probably have a helper method to share code with the "Byte strings"
13001300
// printing above (which also has to handle pointers to all sorts of things).
1301-
if let Some(GlobalAlloc::Function(instance)) = self.tcx().get_global_alloc(alloc_id)
1301+
if let Some(GlobalAlloc::Function(instance)) = self.tcx().try_get_global_alloc(alloc_id)
13021302
{
13031303
self = self.typed_value(
13041304
|this| this.print_value_path(instance.def_id(), instance.substs),

0 commit comments

Comments
 (0)