Skip to content

Commit 0947a94

Browse files
committed
Update comments with reasoning in ptr_guaranteed_cmp.
`GlobalAlloc::TypeId` exists mostly to prevent consteval from comparing `TypeId`s, so always return 2 for those (whether the pointers are to the same allocation or not). In the different-allocation case, document that `GlobalAlloc::Memory`, `Function`, and `Vtable` can be deduplicated, at least with other allocations of the same kind, so those should return 2.
1 parent c5727d9 commit 0947a94

File tree

1 file changed

+11
-4
lines changed
  • compiler/rustc_const_eval/src/const_eval

1 file changed

+11
-4
lines changed

compiler/rustc_const_eval/src/const_eval/machine.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,11 @@ impl<'tcx> CompileTimeInterpCx<'tcx> {
322322
// cannot be sure of runtime equality of pointers to the same one, (or the
323323
// runtime inequality of pointers to different ones) (see e.g. #73722).
324324
Some(GlobalAlloc::Function { .. } | GlobalAlloc::VTable(..)) => 2,
325-
// FIXME: Can these be duplicated (or deduplicated)?
326-
Some(GlobalAlloc::Memory(..) | GlobalAlloc::TypeId { .. }) => 2,
325+
// FIXME: Can these can be duplicated?
326+
Some(GlobalAlloc::Memory(..)) => 2,
327+
// `GlobalAlloc::TypeId` exists mostly to prevent consteval from comparing
328+
// `TypeId`s, always return 2
329+
Some(GlobalAlloc::TypeId { .. }) => 2,
327330
}
328331
} else {
329332
if let (Some(GlobalAlloc::Static(a_did)), Some(GlobalAlloc::Static(b_did))) = (
@@ -367,8 +370,12 @@ impl<'tcx> CompileTimeInterpCx<'tcx> {
367370
} else {
368371
// Even if one of them is a static, as per https://doc.rust-lang.org/nightly/reference/items/static-items.html#r-items.static.storage-disjointness
369372
// immutable statics can overlap with other kinds of allocations somtimes.
370-
// FIXME: We could be more decisive for mutable statics, which cannot
371-
// overlap with other kinds of allocations.
373+
// FIXME: We could be more decisive for (non-zero-sized) mutable statics,
374+
// which cannot overlap with other kinds of allocations.
375+
// `GlobalAlloc::{Memory, Function, Vtable}` can at least be deduplicated with
376+
// the same kind, so comparing two of the same kind of those should return 2.
377+
// `GlobalAlloc::TypeId` exists mostly to prevent consteval from comparing
378+
// `TypeId`s, so comparing two of those should always return 2.
372379
// FIXME: Can we determine any other cases?
373380
2
374381
}

0 commit comments

Comments
 (0)