rename get_global_alloc to try_get_global_alloc
This commit is contained in:
parent
da5e4d73f1
commit
a10d8e4581
10 changed files with 32 additions and 22 deletions
|
@ -369,7 +369,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
|
|||
// we don't deallocate it.
|
||||
let (alloc_id, _, _) = ecx.ptr_get_alloc_id(ptr)?;
|
||||
let is_allocated_in_another_const = matches!(
|
||||
ecx.tcx.get_global_alloc(alloc_id),
|
||||
ecx.tcx.try_get_global_alloc(alloc_id),
|
||||
Some(interpret::GlobalAlloc::Memory(_))
|
||||
);
|
||||
|
||||
|
|
|
@ -138,7 +138,7 @@ pub(crate) fn deref_mir_constant<'tcx>(
|
|||
let mplace = ecx.deref_operand(&op).unwrap();
|
||||
if let Some(alloc_id) = mplace.ptr.provenance {
|
||||
assert_eq!(
|
||||
tcx.get_global_alloc(alloc_id).unwrap().unwrap_memory().0.0.mutability,
|
||||
tcx.global_alloc(alloc_id).unwrap_memory().0.0.mutability,
|
||||
Mutability::Not,
|
||||
"deref_mir_constant cannot be used with mutable allocations as \
|
||||
that could allow pattern matching to observe mutable statics",
|
||||
|
|
|
@ -94,7 +94,7 @@ fn intern_shallow<'rt, 'mir, 'tcx, M: CompileTimeMachine<'mir, 'tcx, const_eval:
|
|||
// to validation to error -- it has the much better error messages, pointing out where
|
||||
// in the value the dangling reference lies.
|
||||
// The `delay_span_bug` ensures that we don't forget such a check in validation.
|
||||
if tcx.get_global_alloc(alloc_id).is_none() {
|
||||
if tcx.try_get_global_alloc(alloc_id).is_none() {
|
||||
tcx.sess.delay_span_bug(ecx.tcx.span, "tried to intern dangling pointer");
|
||||
}
|
||||
// treat dangling pointers like other statics
|
||||
|
@ -454,7 +454,7 @@ pub fn intern_const_alloc_recursive<
|
|||
.sess
|
||||
.span_err(ecx.tcx.span, "encountered dangling pointer in final constant");
|
||||
return Err(reported);
|
||||
} else if ecx.tcx.get_global_alloc(alloc_id).is_none() {
|
||||
} else if ecx.tcx.try_get_global_alloc(alloc_id).is_none() {
|
||||
// We have hit an `AllocId` that is neither in local or global memory and isn't
|
||||
// marked as dangling by local memory. That should be impossible.
|
||||
span_bug!(ecx.tcx.span, "encountered unknown alloc id {:?}", alloc_id);
|
||||
|
|
|
@ -161,7 +161,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
) -> InterpResult<'tcx, Pointer<M::Provenance>> {
|
||||
let alloc_id = ptr.provenance;
|
||||
// We need to handle `extern static`.
|
||||
match self.tcx.get_global_alloc(alloc_id) {
|
||||
match self.tcx.try_get_global_alloc(alloc_id) {
|
||||
Some(GlobalAlloc::Static(def_id)) if self.tcx.is_thread_local_static(def_id) => {
|
||||
bug!("global memory cannot point to thread-local static")
|
||||
}
|
||||
|
@ -289,7 +289,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
|
||||
let Some((alloc_kind, mut alloc)) = self.memory.alloc_map.remove(&alloc_id) else {
|
||||
// Deallocating global memory -- always an error
|
||||
return Err(match self.tcx.get_global_alloc(alloc_id) {
|
||||
return Err(match self.tcx.try_get_global_alloc(alloc_id) {
|
||||
Some(GlobalAlloc::Function(..)) => {
|
||||
err_ub_format!("deallocating {alloc_id:?}, which is a function")
|
||||
}
|
||||
|
@ -478,7 +478,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
id: AllocId,
|
||||
is_write: bool,
|
||||
) -> InterpResult<'tcx, Cow<'tcx, Allocation<M::Provenance, M::AllocExtra>>> {
|
||||
let (alloc, def_id) = match self.tcx.get_global_alloc(id) {
|
||||
let (alloc, def_id) = match self.tcx.try_get_global_alloc(id) {
|
||||
Some(GlobalAlloc::Memory(mem)) => {
|
||||
// Memory of a constant or promoted or anonymous memory referenced by a static.
|
||||
(mem, None)
|
||||
|
@ -669,7 +669,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
// # Statics
|
||||
// Can't do this in the match argument, we may get cycle errors since the lock would
|
||||
// be held throughout the match.
|
||||
match self.tcx.get_global_alloc(id) {
|
||||
match self.tcx.try_get_global_alloc(id) {
|
||||
Some(GlobalAlloc::Static(did)) => {
|
||||
assert!(!self.tcx.is_thread_local_static(did));
|
||||
// Use size and align of the type.
|
||||
|
@ -715,7 +715,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
if let Some(extra) = self.memory.extra_fn_ptr_map.get(&id) {
|
||||
Some(FnVal::Other(*extra))
|
||||
} else {
|
||||
match self.tcx.get_global_alloc(id) {
|
||||
match self.tcx.try_get_global_alloc(id) {
|
||||
Some(GlobalAlloc::Function(instance)) => Some(FnVal::Instance(instance)),
|
||||
_ => None,
|
||||
}
|
||||
|
@ -839,7 +839,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> std::fmt::Debug for DumpAllocs<'a,
|
|||
}
|
||||
None => {
|
||||
// global alloc
|
||||
match self.ecx.tcx.get_global_alloc(id) {
|
||||
match self.ecx.tcx.try_get_global_alloc(id) {
|
||||
Some(GlobalAlloc::Memory(alloc)) => {
|
||||
write!(fmt, " (unchanged global, ")?;
|
||||
write_allocation_track_relocs(
|
||||
|
|
|
@ -447,7 +447,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
|
|||
// `!` is a ZST and we want to validate it.
|
||||
if let Ok((alloc_id, _offset, _prov)) = self.ecx.ptr_try_get_alloc_id(place.ptr) {
|
||||
// Special handling for pointers to statics (irrespective of their type).
|
||||
let alloc_kind = self.ecx.tcx.get_global_alloc(alloc_id);
|
||||
let alloc_kind = self.ecx.tcx.try_get_global_alloc(alloc_id);
|
||||
if let Some(GlobalAlloc::Static(did)) = alloc_kind {
|
||||
assert!(!self.ecx.tcx.is_thread_local_static(did));
|
||||
assert!(self.ecx.tcx.is_static(did));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue