Skip to content

Commit 1ea4466

Browse files
committed
Elaborate on the details in some comments
1 parent 658c27b commit 1ea4466

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

src/librustc_mir/interpret/intern.rs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,9 @@ pub fn intern_const_alloc_recursive<M: CompileTimeMachine<'mir, 'tcx>>(
361361
// everything as immutable. Creating a promoted with interior mutability is UB, but
362362
// there's no way we can check whether the user is using raw pointers correctly.
363363
// So all we can do is mark this as immutable here.
364+
// It is UB to mutate through a raw pointer obtained via an immutable reference.
365+
// Since all references and pointers inside a promoted must by their very definition
366+
// be created from an immutable reference, mutating though them would be UB.
364367
InternKind::Promoted => {
365368
alloc.mutability = Mutability::Not;
366369
}
@@ -388,19 +391,27 @@ pub fn intern_const_alloc_recursive<M: CompileTimeMachine<'mir, 'tcx>>(
388391
// dangling pointer
389392
throw_unsup!(ValidationFailure("encountered dangling pointer in final constant".into()))
390393
} else if let Some(_) = ecx.tcx.alloc_map.lock().get(alloc_id) {
391-
// If we encounter an `AllocId` that points to a mutable `Allocation`,
392-
// (directly or via relocations in its `Allocation`), we should panic,
393-
// the static rules should prevent this.
394-
// We may hit an `AllocId` that belongs to an already interned static,
394+
// We have hit an `AllocId` that belongs to an already interned static,
395395
// and are thus not interning any further.
396-
// But since we are also checking things during interning,
397-
// we should probably continue doing those checks no matter what we encounter.
398396

399397
// E.g. this should be unreachable for `InternKind::Promoted` except for allocations
400-
// created for string and byte string literals.
398+
// created for string and byte string literals, since these are interned immediately
399+
// at creation time.
401400

402-
// FIXME: check if the allocation is ok as per the interning rules as if we interned
403-
// it right here.
401+
// FIXME(oli-obk): Since we are also checking things during interning,
402+
// we should probably continue doing those checks no matter what we encounter.
403+
// So we basically have to check if the allocation is ok as per the interning rules as
404+
// if we interned it right here.
405+
// This should be as simple as
406+
/*
407+
for &(_, ((), reloc)) in alloc.relocations().iter() {
408+
if leftover_allocations.insert(reloc) {
409+
todo.push(reloc);
410+
}
411+
}
412+
*/
413+
// But I (oli-obk) haven't thought about the ramnificatons yet. This also would cause
414+
// compile-time regressions, so we should think about caching these.
404415
} else {
405416
span_bug!(ecx.tcx.span, "encountered unknown alloc id {:?}", alloc_id);
406417
}

0 commit comments

Comments
 (0)